Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-32569

Failure when executing PS for query using IN subquery

Details

    Description

      The following test case fails if the server is built with -DWITH_PROTECT_STATEMENT_MEMROOT:BOOL=ON

      CREATE TABLE t1 (a varchar(10)) ENGINE=MYISAM;
      CREATE TABLE t2 (b varchar(10) CHARACTER SET utf8) ENGINE=MYISAM;
      INSERT INTO t1 VALUES ('b');
      INSERT INTO t2 VALUES ('b');
      PREPARE stmt FROM 
      "SELECT STRAIGHT_JOIN  t1.a FROM t1 WHERE t1.a IN (SELECT t2.b FROM t2)";
      EXECUTE stmt;
      EXECUTE stmt;
      DEALLOCATE PREPARE stmt;
      DROP TABLE t1,t2;
      

      An assertion failure happens when trying to allocate an Item_direct_ref_to_item at the second execution of the PS.

      Attachments

        Issue Links

          Activity

            See also the test case for MDEV-16128 from ps.test that fails in the same way if the server is built with -DWITH_PROTECT_STATEMENT_MEMROOT:BOOL=ON

            CREATE TABLE t1 (a varchar(10));
            CREATE TABLE t2 (b varchar(10) CHARACTER SET utf8);
            INSERT INTO t1 VALUES ('b');
            INSERT INTO t2 VALUES ('b');
            PREPARE stmt FROM 'SELECT STRAIGHT_JOIN 1 FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.b = t1.a)';
            EXECUTE stmt;
            EXECUTE stmt;
            

            igor Igor Babaev (Inactive) added a comment - See also the test case for MDEV-16128 from ps.test that fails in the same way if the server is built with -DWITH_PROTECT_STATEMENT_MEMROOT:BOOL=ON CREATE TABLE t1 (a varchar (10)); CREATE TABLE t2 (b varchar (10) CHARACTER SET utf8); INSERT INTO t1 VALUES ( 'b' ); INSERT INTO t2 VALUES ( 'b' ); PREPARE stmt FROM 'SELECT STRAIGHT_JOIN 1 FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.b = t1.a)' ; EXECUTE stmt; EXECUTE stmt;

            The following patch fixes this problem.

            --- a/sql/item.cc
            +++ b/sql/item.cc
            @@ -2585,7 +2585,8 @@ bool Type_std_attributes::agg_item_set_converter(const DTCollation &coll,
                 if (conv->fix_fields_if_needed(thd, arg))
                   return TRUE;
             
            -    if (!thd->stmt_arena->is_conventional())
            +    if (!thd->stmt_arena->is_conventional() &&
            +        thd->lex->current_select->first_cond_optimization)
                 {
                   Query_arena *arena, backup;
                   arena= thd->activate_stmt_arena_if_needed(&backup);
            

            It also fixes all assertion failures in the function Type_std_attributes::agg_item_set_converter() for all test cases from the main test suite.

            igor Igor Babaev (Inactive) added a comment - The following patch fixes this problem. --- a/sql/item.cc +++ b/sql/item.cc @@ -2585,7 +2585,8 @@ bool Type_std_attributes::agg_item_set_converter(const DTCollation &coll, if (conv->fix_fields_if_needed(thd, arg)) return TRUE; - if (!thd->stmt_arena->is_conventional()) + if (!thd->stmt_arena->is_conventional() && + thd->lex->current_select->first_cond_optimization) { Query_arena *arena, backup; arena= thd->activate_stmt_arena_if_needed(&backup); It also fixes all assertion failures in the function Type_std_attributes::agg_item_set_converter() for all test cases from the main test suite.

            Please review this patch. You've already checked it.

            igor Igor Babaev (Inactive) added a comment - Please review this patch. You've already checked it.
            Johnston Rex Johnston added a comment -

            Looks good to me. OK to push.

            Johnston Rex Johnston added a comment - Looks good to me. OK to push.

            A fix for this bug was pushed into 10.4. It has to be merged upstream as it is.

            igor Igor Babaev (Inactive) added a comment - A fix for this bug was pushed into 10.4. It has to be merged upstream as it is.

            People

              igor Igor Babaev (Inactive)
              igor Igor Babaev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.