From: Date: June 15 2005 5:44pm Subject: bk commit into 4.1 tree (dlenev:1.2293) BUG#11060 List-Archive: http://lists.mysql.com/internals/26029 X-Bug: 11060 Message-Id: <20050615154439.AFCFA1379D4@brandersnatch.localdomain> Below is the list of changes that have just been committed into a local 4.1 repository of dlenev. When dlenev does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2293 05/06/15 19:44:33 dlenev@stripped +3 -0 Fix for bug #11060 "Server crashes on re-execution of prepared INSERT ... SELECT with UNION". 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. sql/sql_insert.cc 1.167 05/06/15 19:44:28 dlenev@stripped +12 -0 select_insert::prepare(): Item::fix_fields() methods operate assuming that LEX::current_select points to the select to which current item belongs. Thus during check_insert_fields() routine execution LEX::current_select should point ot the first select in query since this is the select with which items in insert list is associated. But if we have INSERT SELECT UNION SELECT type of query LEX::current_select will point to the fake_select_lex instead since select_insert::prepare() is called during processing of JOIN which corresponds to this select_lex. So we have set LEX::current_select before calling check_insert_fields() and restore it afterwards. mysql-test/t/ps.test 1.34 05/06/15 19:44:28 dlenev@stripped +12 -0 Added test case for bug #11060 "Server crashes on re-execution of prepared INSERT ... SELECT with UNION". mysql-test/r/ps.result 1.35 05/06/15 19:44:28 dlenev@stripped +6 -0 Added test case for bug #11060 "Server crashes on re-execution of prepared INSERT ... SELECT with UNION". # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: dlenev # Host: brandersnatch.localdomain # Root: /home/dlenev/src/mysql-4.1-bg11060 --- 1.166/sql/sql_insert.cc Sat Jun 4 09:23:30 2005 +++ 1.167/sql/sql_insert.cc Wed Jun 15 19:44:28 2005 @@ -1578,11 +1578,23 @@ int select_insert::prepare(List &values, SELECT_LEX_UNIT *u) { + LEX *lex= thd->lex; + SELECT_LEX *lex_select_save= lex->current_select; DBUG_ENTER("select_insert::prepare"); unit= u; + /* + 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; if (check_insert_fields(thd, table, *fields, values)) + { + lex->current_select= lex_select_save; DBUG_RETURN(1); + } + lex->current_select= lex_select_save; restore_record(table,default_values); // Get empty record table->next_number_field=table->found_next_number_field; --- 1.34/mysql-test/r/ps.result Thu May 5 12:55:01 2005 +++ 1.35/mysql-test/r/ps.result Wed Jun 15 19:44:28 2005 @@ -557,3 +557,9 @@ 3 deallocate prepare stmt; 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; --- 1.33/mysql-test/t/ps.test Thu May 5 12:55:01 2005 +++ 1.34/mysql-test/t/ps.test Wed Jun 15 19:44:28 2005 @@ -569,3 +569,15 @@ deallocate prepare stmt; 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;