[Commits] 98fdd2b: MDEV-6219: Server crashes in Bitmap<64u>::merge (this=0x180, map2=...) on 2nd execution of PS with INSERT .. SELECT, derived_merge

sanja at mariadb.com sanja at mariadb.com
Wed Feb 25 17:20:35 EET 2015


revision-id: 98fdd2b31e4f29f7be1b55d4cc60364b8a8e58ea
parent(s): 22dae70015bd9666a0278e908d023aa23fc3215b
committer: Oleksandr Byelkin
branch nick: server
timestamp: 2015-02-25 16:20:31 +0100
message:

MDEV-6219: Server crashes in Bitmap<64u>::merge (this=0x180, map2=...) on 2nd execution of PS with INSERT .. SELECT, derived_merge

Problem: Not all permanent Item_direct_view_ref was in permanent list of used items of the view.

Solution: Detect creating permenent view/derived table reference and put them in the permanent list at once.

---
 mysql-test/r/derived.result | 25 +++++++++++++++++++++++++
 mysql-test/t/derived.test   | 33 +++++++++++++++++++++++++++++++++
 sql/sql_base.cc             | 13 -------------
 sql/table.cc                |  7 +++++++
 4 files changed, 65 insertions(+), 13 deletions(-)

diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result
index d0f42c3..7924fe6 100644
--- a/mysql-test/r/derived.result
+++ b/mysql-test/r/derived.result
@@ -567,4 +567,29 @@ insert into t1 (accountId,balance) values
 update t1 set balance=(select sum(balance) from (SELECT balance FROM t1 where accountId like 'dealer%') AS copied) where accountId = 'OPERATOR';
 set optimizer_switch=@save_derived_optimizer_switch_bug;
 drop table t1;
+#
+# MDEV-6219:Server crashes in Bitmap<64u>::merge
+# (this=0x180, map2=...) on 2nd execution of PS with INSERT .. SELECT,
+# derived_merge
+#
+CREATE TABLE t1 (a VARCHAR(8)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('foo'),('bar');
+create procedure p1()
+INSERT INTO t1 SELECT * FROM ( 
+SELECT * FROM t1
+) AS sq
+WHERE sq.a IN ( SELECT 'baz' FROM DUAL );
+call p1();
+call p1();
+drop procedure p1;
+PREPARE stmt FROM "
+  INSERT INTO t1 SELECT * FROM ( 
+    SELECT * FROM t1
+  ) AS sq
+  WHERE sq.a IN ( SELECT 'baz' FROM DUAL ) 
+";
+EXECUTE stmt;
+EXECUTE stmt;
+deallocate prepare stmt;
+drop table t1;
 set optimizer_switch=@save_derived_optimizer_switch;
diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test
index 61ae369..6bea29b 100644
--- a/mysql-test/t/derived.test
+++ b/mysql-test/t/derived.test
@@ -493,4 +493,37 @@ set optimizer_switch=@save_derived_optimizer_switch_bug;
 drop table t1;
 
 
+--echo #
+--echo # MDEV-6219:Server crashes in Bitmap<64u>::merge
+--echo # (this=0x180, map2=...) on 2nd execution of PS with INSERT .. SELECT,
+--echo # derived_merge
+--echo #
+
+CREATE TABLE t1 (a VARCHAR(8)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('foo'),('bar');
+
+create procedure p1()
+  INSERT INTO t1 SELECT * FROM ( 
+    SELECT * FROM t1
+  ) AS sq
+  WHERE sq.a IN ( SELECT 'baz' FROM DUAL );
+
+call p1();
+call p1();
+drop procedure p1;
+
+PREPARE stmt FROM "
+  INSERT INTO t1 SELECT * FROM ( 
+    SELECT * FROM t1
+  ) AS sq
+  WHERE sq.a IN ( SELECT 'baz' FROM DUAL ) 
+";
+
+EXECUTE stmt;
+EXECUTE stmt;
+
+deallocate prepare stmt;
+
+drop table t1;
+
 set optimizer_switch=@save_derived_optimizer_switch;
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 424f572..95cae9c 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -7254,14 +7254,6 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
   */
   result= FALSE;
 
-  /*
-    Save the lists made during natural join matching (because
-    the matching done only once but we need the list in case
-    of prepared statements).
-  */
-  table_ref_1->persistent_used_items= table_ref_1->used_items;
-  table_ref_2->persistent_used_items= table_ref_2->used_items;
-
 err:
   if (arena)
     thd->restore_active_arena(arena, &backup);
@@ -8307,11 +8299,6 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
         }
       }
 #endif
-      /*
-         field_iterator.create_item() builds used_items which we
-         have to save because changes made once and they are persistent
-      */
-      tables->persistent_used_items= tables->used_items;
 
       if ((field= field_iterator.field()))
       {
diff --git a/sql/table.cc b/sql/table.cc
index e48d8e2..8ae2640 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -5335,6 +5335,12 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
     item->maybe_null= TRUE;
   /* Save item in case we will need to fall back to materialization. */
   view->used_items.push_front(item);
+  /*
+    If we create this reference on persistent memory then it should be
+    present in persistent list
+  */
+  if (thd->mem_root == thd->stmt_arena->mem_root)
+    view->persistent_used_items.push_front(item);
   DBUG_RETURN(item);
 }
 
@@ -6902,6 +6908,7 @@ bool TABLE_LIST::handle_derived(LEX *lex, uint phases)
 {
   SELECT_LEX_UNIT *unit;
   DBUG_ENTER("handle_derived");
+  DBUG_PRINT("enter", ("phases: 0x%x", phases));
   if ((unit= get_unit()))
   {
     for (SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select())


More information about the commits mailing list