From ae40c7207760ea6c829a6bdbbabc1e19941f1240 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 13 Nov 2013 14:43:09 -0800 Subject: [PATCH] Fixed bug mdev-5091. The function SELECT_LEX::update_used_tables should process all ORDER BY lists in any subselect of a union. --- mysql-test/r/union.result | 15 +++++++++++++++ mysql-test/t/union.test | 19 +++++++++++++++++++ sql/sql_lex.cc | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index 13941d3f84d..05dab9e2874 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -1724,3 +1724,18 @@ foo 1 deallocate prepare stmt1; End of 5.1 tests +# +# mdev-5091: Asseirtion failure for UNION with ORDER BY +# in one of selects +# +CREATE TABLE t1 (i int, c char(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (6,'b'); +CREATE VIEW v1 AS SELECT * FROM t1; +( SELECT i FROM v1 GROUP BY i ORDER BY CONCAT( c, c ) LIMIT 1 ) +UNION +( SELECT i FROM t1 ); +i +6 +DROP VIEW v1; +DROP TABLE t1; +End of 5.3 tests diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index fefd67fd2f7..bb0e5610a26 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -1210,3 +1210,22 @@ execute stmt1; deallocate prepare stmt1; --echo End of 5.1 tests +--echo # +--echo # mdev-5091: Asseirtion failure for UNION with ORDER BY +--echo # in one of selects +--echo # + + CREATE TABLE t1 (i int, c char(1)) ENGINE=MyISAM; + INSERT INTO t1 VALUES (6,'b'); + + CREATE VIEW v1 AS SELECT * FROM t1; + + ( SELECT i FROM v1 GROUP BY i ORDER BY CONCAT( c, c ) LIMIT 1 ) + UNION + ( SELECT i FROM t1 ); + + DROP VIEW v1; + DROP TABLE t1; + + --echo End of 5.3 tests + diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 6f34dd23f36..e8c795e9c54 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3534,7 +3534,7 @@ void SELECT_LEX::update_used_tables() } for (ORDER *order= group_list.first; order; order= order->next) (*order->item)->update_used_tables(); - if (!master_unit()->is_union()) + if (master_unit()->global_parameters != this) { for (ORDER *order= order_list.first; order; order= order->next) (*order->item)->update_used_tables();