summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <igor@olga.mysql.com>2007-05-14 16:41:09 -0700
committerunknown <igor@olga.mysql.com>2007-05-14 16:41:09 -0700
commitfca58c95566c5a7bf8abf7386aa2b03890d85e05 (patch)
treec69d06d257c43de7983d59c91eb31625c3043087
parent47430268e53ae1ed379e0594349eb8dbca0f89c2 (diff)
downloadmariadb-git-fca58c95566c5a7bf8abf7386aa2b03890d85e05.tar.gz
Fixed bug #27937: crash for the the second execution of a prepared
statement from a UNION query with ORDER BY an expression containing RAND(). The crash happened because the global order by list in the union query was not re-initialized for execution. (Local order by lists were re-initialized though). mysql-test/r/ps.result: Added a test case for bug #27937. mysql-test/t/ps.test: Added a test case for bug #27937. sql/sql_union.cc: Fixed bug #27937: crash for the the second execution of a prepared statement from a UNION query with ORDER BY an expression containing RAND(). The crash happened because the global order by list in the union query was not re-initialized for execution. (Local order by lists were re-initialized though). Added re-initialization of the global order by list in the function st_select_lex_unit::init_prepare_fake_select_lex.
-rw-r--r--mysql-test/r/ps.result22
-rw-r--r--mysql-test/t/ps.test18
-rw-r--r--sql/sql_union.cc5
3 files changed, 45 insertions, 0 deletions
diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result
index d8a75737efc..49e4bf2f318 100644
--- a/mysql-test/r/ps.result
+++ b/mysql-test/r/ps.result
@@ -1087,4 +1087,26 @@ t2 CREATE TABLE `t2` (
drop database mysqltest;
deallocate prepare stmt1;
deallocate prepare stmt2;
+CREATE TABLE t1(a int);
+INSERT INTO t1 VALUES (2), (3), (1);
+PREPARE st1 FROM
+'(SELECT a FROM t1) UNION (SELECT a+10 FROM t1) ORDER BY RAND()*0+a';
+EXECUTE st1;
+a
+1
+2
+3
+11
+12
+13
+EXECUTE st1;
+a
+1
+2
+3
+11
+12
+13
+DEALLOCATE PREPARE st1;
+DROP TABLE t1;
End of 4.1 tests.
diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test
index a0133897f50..5e5dcc36b19 100644
--- a/mysql-test/t/ps.test
+++ b/mysql-test/t/ps.test
@@ -1128,4 +1128,22 @@ drop database mysqltest;
deallocate prepare stmt1;
deallocate prepare stmt2;
#
+
+#
+# Bug #27937: crash on the second execution for prepared statement
+# from UNION with ORDER BY an expression containing RAND()
+#
+
+CREATE TABLE t1(a int);
+INSERT INTO t1 VALUES (2), (3), (1);
+
+PREPARE st1 FROM
+ '(SELECT a FROM t1) UNION (SELECT a+10 FROM t1) ORDER BY RAND()*0+a';
+
+EXECUTE st1;
+EXECUTE st1;
+
+DEALLOCATE PREPARE st1;
+DROP TABLE t1;
+
--echo End of 4.1 tests.
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index f3f814831f5..615d060a5a8 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -135,6 +135,11 @@ st_select_lex_unit::init_prepare_fake_select_lex(THD *thd)
fake_select_lex->table_list.link_in_list((byte *)&result_table_list,
(byte **)
&result_table_list.next);
+ for (ORDER *order= (ORDER *) global_parameters->order_list.first;
+ order;
+ order= order->next)
+ order->item= &order->item_ptr;
+
return options_tmp;
}