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

assertion of (mem_root->flags & 4) == 0 fails in 2nd ps execution with partition pruning

Details

    Description

      With WITH_PROTECT_STATEMENT_MEMROOT:BOOL=ON the following leads to "alloc_root: Assertion `(mem_root->flags & 4) == 0' failed" in both 10.5 b304ec30308a86d87f29e509b988d3120b940f58 and 11.6 72ab8bc990c50d3d3bbd0bb71e536e304b567e40.

      --source include/have_partition.inc
       
      # 2nd ps mem leak; partition pruning
      set @var1=5;
      set @var2=4;
      create table t1 (a int) partition by list(a) (
        partition p0 values in (null,1,2),
        partition p1 values in (3,4)
      );
      create table t2 (a int);
      insert into t1 values (1),(2),(3),(4);
      insert into t2 values (4);
      PREPARE stmt FROM 'UPDATE t1 t1 SET a = (SELECT 1 FROM t2 WHERE a = t1.a) where a = ?';
      /* 1 */ execute stmt using @var1;
      select * from t1;
      /* 2 */ execute stmt using @var2;
      select * from t1;
      deallocate prepare stmt;
      drop table t1, t2;
      

      Attachments

        Issue Links

          Activity

            ycp Yuchen Pei added a comment -

            In 11.6 it seems to be the same problem as the 2nd ps issues in MDEV-25008 in case of a impossible where, that is, early return in Sql_cmd_update::update_single_table() causes skipping something that shouldn't be skipped. In MDEV-25008 it is JOIN::optimize_inner() for the subqueries, called via optimize_unflattened_subqueries(false). The counterpart in the present issue is st_select_lex::save_leaf_tables() for the outer select, and similar to the solution for MDEV-34447, the following patch fixes the testcase in the description:

            modified   sql/sql_update.cc
            @@ -458,6 +458,11 @@ bool Sql_cmd_update::update_single_table(THD *thd)
             #ifdef WITH_PARTITION_STORAGE_ENGINE
               if (prune_partitions(thd, table, conds))
               {
            +    if (!thd->lex->current_select->leaf_tables_saved)
            +    {
            +      thd->lex->current_select->save_leaf_tables(thd);
            +      thd->lex->current_select->leaf_tables_saved= true;
            +    }
                 free_underlaid_joins(thd, select_lex);
             
                 query_plan.set_no_partitions();
            

            CC psergei and shulga

            ycp Yuchen Pei added a comment - In 11.6 it seems to be the same problem as the 2nd ps issues in MDEV-25008 in case of a impossible where, that is, early return in Sql_cmd_update::update_single_table() causes skipping something that shouldn't be skipped. In MDEV-25008 it is JOIN::optimize_inner() for the subqueries, called via optimize_unflattened_subqueries(false) . The counterpart in the present issue is st_select_lex::save_leaf_tables() for the outer select, and similar to the solution for MDEV-34447 , the following patch fixes the testcase in the description: modified sql/sql_update.cc @@ -458,6 +458,11 @@ bool Sql_cmd_update::update_single_table(THD *thd) #ifdef WITH_PARTITION_STORAGE_ENGINE if (prune_partitions(thd, table, conds)) { + if (!thd->lex->current_select->leaf_tables_saved) + { + thd->lex->current_select->save_leaf_tables(thd); + thd->lex->current_select->leaf_tables_saved= true; + } free_underlaid_joins(thd, select_lex); query_plan.set_no_partitions(); CC psergei and shulga
            ycp Yuchen Pei added a comment -

            A draft patch in 11.1:

            55066093c8a upstream/bb-11.1-mdev-34757 MDEV-34757 Check leaf_tables_saved in partition pruning in UPDATE and DELETE

            As for 10.5, the patch requires a backport of MDEV-34447, which also fixes MDEV-33858 for 10.5:

            e265479f97d upstream/bb-10.5-mdev-34757 MDEV-34757 Check leaf_tables_saved in partition pruning in UPDATE and DELETE
            8e57ed0afe8 MDEV-33858 Assertion `(mem_root->flags & 4) == 0' fails on 2nd execution of PS with -DWITH_PROTECT_STATEMENT_MEMROOT=ON
            4eecca43341 MDEV-34447: Memory leakage is detected on running the test main.ps against the server 11.1

            ycp Yuchen Pei added a comment - A draft patch in 11.1: 55066093c8a upstream/bb-11.1-mdev-34757 MDEV-34757 Check leaf_tables_saved in partition pruning in UPDATE and DELETE As for 10.5, the patch requires a backport of MDEV-34447 , which also fixes MDEV-33858 for 10.5: e265479f97d upstream/bb-10.5-mdev-34757 MDEV-34757 Check leaf_tables_saved in partition pruning in UPDATE and DELETE 8e57ed0afe8 MDEV-33858 Assertion `(mem_root->flags & 4) == 0' fails on 2nd execution of PS with -DWITH_PROTECT_STATEMENT_MEMROOT=ON 4eecca43341 MDEV-34447: Memory leakage is detected on running the test main.ps against the server 11.1
            ycp Yuchen Pei added a comment - - edited

            Hi shulga, ptal thanks:

            52bf5e8e211 upstream/bb-10.5-mdev-34757 MDEV-34757 Check leaf_tables_saved in partition pruning in UPDATE and DELETE
            8e57ed0afe8 MDEV-33858 Assertion `(mem_root->flags & 4) == 0' fails on 2nd execution of PS with -DWITH_PROTECT_STATEMENT_MEMROOT=ON
            4eecca43341 MDEV-34447: Memory leakage is detected on running the test main.ps against the server 11.1
            

            The fix (top commit) depends on the backport of MDEV-34447 to 10.5 (bottom commit), which also fixes MDEV-33858 (middle commit).

            ycp Yuchen Pei added a comment - - edited Hi shulga , ptal thanks: 52bf5e8e211 upstream/bb-10.5-mdev-34757 MDEV-34757 Check leaf_tables_saved in partition pruning in UPDATE and DELETE 8e57ed0afe8 MDEV-33858 Assertion `(mem_root->flags & 4) == 0' fails on 2nd execution of PS with -DWITH_PROTECT_STATEMENT_MEMROOT=ON 4eecca43341 MDEV-34447: Memory leakage is detected on running the test main.ps against the server 11.1 The fix (top commit) depends on the backport of MDEV-34447 to 10.5 (bottom commit), which also fixes MDEV-33858 (middle commit).
            shulga Dmitry Shulga added a comment -

            OK to push

            shulga Dmitry Shulga added a comment - OK to push
            ycp Yuchen Pei added a comment -

            Thanks for the review - pushed the following to 10.5:

            e886c2ba02a upstream/10.5 upstream/bb-10.5-mdev-34757 MDEV-34757 Check leaf_tables_saved in partition pruning in UPDATE and DELETE
            00cb3440858 MDEV-33858 Assertion `(mem_root->flags & 4) == 0' fails on 2nd execution of PS with -DWITH_PROTECT_STATEMENT_MEMROOT=ON
            2c3e07df473 MDEV-34447: Memory leakage is detected on running the test main.ps against the server 11.1
            

            ycp Yuchen Pei added a comment - Thanks for the review - pushed the following to 10.5: e886c2ba02a upstream/10.5 upstream/bb-10.5-mdev-34757 MDEV-34757 Check leaf_tables_saved in partition pruning in UPDATE and DELETE 00cb3440858 MDEV-33858 Assertion `(mem_root->flags & 4) == 0' fails on 2nd execution of PS with -DWITH_PROTECT_STATEMENT_MEMROOT=ON 2c3e07df473 MDEV-34447: Memory leakage is detected on running the test main.ps against the server 11.1

            People

              ycp Yuchen Pei
              ycp Yuchen Pei
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.