Commit d83c2643 authored by unknown's avatar unknown

Manual merge of patch for 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" into 5.0 tree.


mysql-test/r/ps.result:
  Manual merge.
mysql-test/t/ps.test:
  Manual merge.
sql/sql_insert.cc:
  Manual merge.
parents c8c0140e 79444fa5
...@@ -675,3 +675,9 @@ a ...@@ -675,3 +675,9 @@ a
10 10
drop table t1; drop table t1;
deallocate prepare stmt; deallocate prepare stmt;
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;
...@@ -693,3 +693,15 @@ execute stmt using @offset, @limit, @offset, @limit, @limit; ...@@ -693,3 +693,15 @@ execute stmt using @offset, @limit, @offset, @limit, @limit;
drop table t1; drop table t1;
deallocate prepare stmt; deallocate prepare stmt;
#
# 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;
...@@ -1988,10 +1988,22 @@ select_insert::select_insert(TABLE_LIST *table_list_par, TABLE *table_par, ...@@ -1988,10 +1988,22 @@ select_insert::select_insert(TABLE_LIST *table_list_par, TABLE *table_par,
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_list, *fields, values, !insert_into_view)) /*
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_list, *fields, values,
!insert_into_view);
lex->current_select= lex_current_select_save;
if (res)
DBUG_RETURN(1); DBUG_RETURN(1);
/* /*
if it is INSERT into join view then check_insert_fields already found if it is INSERT into join view then check_insert_fields already found
...@@ -2003,12 +2015,12 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u) ...@@ -2003,12 +2015,12 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
Is table which we are changing used somewhere in other parts of Is table which we are changing used somewhere in other parts of
query query
*/ */
if (!(thd->lex->current_select->options & OPTION_BUFFER_RESULT) && if (!(lex->current_select->options & OPTION_BUFFER_RESULT) &&
unique_table(table_list, table_list->next_global)) unique_table(table_list, table_list->next_global))
{ {
/* Using same table for INSERT and SELECT */ /* Using same table for INSERT and SELECT */
thd->lex->current_select->options|= OPTION_BUFFER_RESULT; lex->current_select->options|= OPTION_BUFFER_RESULT;
thd->lex->current_select->join->select_options|= OPTION_BUFFER_RESULT; lex->current_select->join->select_options|= OPTION_BUFFER_RESULT;
} }
else else
{ {
......
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