Fix for bug #11060 "Server crashes on re-execution of prepared

INSERT ... SELECT with UNION" (reviewed version).

Altough bug manifest itself only starting from 5.0 it is better to
apply fix to 4.1 to keep some assumptions true and make code more
future-proof.
parent 362a45fd
...@@ -557,3 +557,9 @@ id ...@@ -557,3 +557,9 @@ id
3 3
deallocate prepare stmt; deallocate prepare stmt;
drop table t1, t2; drop table t1, t2;
create table t1 (id int);
prepare stmt from "insert into t1 (id) select id from t1 union select id from t1";
execute stmt;
execute stmt;
deallocate prepare stmt;
drop table t1;
...@@ -569,3 +569,15 @@ select t2.id from t2, t1 where (t1.id=1 and t2.t1_id=t1.id); ...@@ -569,3 +569,15 @@ select t2.id from t2, t1 where (t1.id=1 and t2.t1_id=t1.id);
deallocate prepare stmt; deallocate prepare stmt;
drop table t1, t2; drop table t1, t2;
#
# Bug#11060 "Server crashes on calling stored procedure with INSERT SELECT
# UNION SELECT" aka "Server crashes on re-execution of prepared INSERT ...
# SELECT with UNION".
#
create table t1 (id int);
prepare stmt from "insert into t1 (id) select id from t1 union select id from t1";
execute stmt;
execute stmt;
deallocate prepare stmt;
drop table t1;
...@@ -1578,10 +1578,21 @@ bool delayed_insert::handle_inserts(void) ...@@ -1578,10 +1578,21 @@ bool delayed_insert::handle_inserts(void)
int int
select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u) select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
{ {
int res;
LEX *lex= thd->lex;
SELECT_LEX *lex_current_select_save= lex->current_select;
DBUG_ENTER("select_insert::prepare"); DBUG_ENTER("select_insert::prepare");
unit= u; unit= u;
if (check_insert_fields(thd, table, *fields, values)) /*
Since table in which we are going to insert is added to the first
select, LEX::current_select should point to the first select while
we are fixing fields from insert list.
*/
lex->current_select= &lex->select_lex;
res= check_insert_fields(thd, table, *fields, values);
lex->current_select= lex_current_select_save;
if (res)
DBUG_RETURN(1); DBUG_RETURN(1);
restore_record(table,default_values); // Get empty record restore_record(table,default_values); // Get empty record
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment