diff options
-rw-r--r-- | mysql-test/r/derived.result | 27 | ||||
-rw-r--r-- | mysql-test/t/derived.test | 35 | ||||
-rw-r--r-- | sql/sql_base.cc | 13 | ||||
-rw-r--r-- | sql/table.cc | 7 |
4 files changed, 67 insertions, 15 deletions
diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result index 7c44466ae92..2b0b1041936 100644 --- a/mysql-test/r/derived.result +++ b/mysql-test/r/derived.result @@ -567,7 +567,31 @@ 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; -set optimizer_switch=@save_derived_optimizer_switch; +# +# 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; # # MDEV-6892: WHERE does not apply # @@ -580,3 +604,4 @@ select x.id, message from (select id from t1) x left join where coalesce(message,0) <> 0; id message drop table t1,t2; +set optimizer_switch=@save_derived_optimizer_switch; diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test index ddce7f55292..d98e7b56905 100644 --- a/mysql-test/t/derived.test +++ b/mysql-test/t/derived.test @@ -492,7 +492,38 @@ update t1 set balance=(select sum(balance) from (SELECT balance FROM t1 where ac set optimizer_switch=@save_derived_optimizer_switch_bug; drop table t1; -set optimizer_switch=@save_derived_optimizer_switch; +--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; --echo # --echo # MDEV-6892: WHERE does not apply @@ -506,3 +537,5 @@ select x.id, message from (select id from t1) x left join (select id, 1 as message from t2) y on x.id=y.id where coalesce(message,0) <> 0; drop table t1,t2; + +set optimizer_switch=@save_derived_optimizer_switch; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 12cd999d130..7e2fe7b1b63 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -7380,14 +7380,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); @@ -8434,11 +8426,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 cdc7b4381cd..da6c4ccf42f 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); } @@ -6912,6 +6918,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()) |