From ccf5871d7bf8be15fcf9a03842a2f40337a7f72f Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 5 Dec 2013 11:13:20 -0800 Subject: [PATCH] Fixed bug mdev-5382 When marking used columns the function find_field_in_table_ref() erroneously called the walk method for the real item behind a view/derived table field with the second parameter set to TRUE. This erroneous code was introduced in 2006. --- mysql-test/r/union.result | 15 +++++++++++++++ mysql-test/t/union.test | 16 ++++++++++++++++ sql/sql_base.cc | 4 ++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index 05dab9e2874..d4effc8448d 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -1738,4 +1738,19 @@ i 6 DROP VIEW v1; DROP TABLE t1; +# +# mdev-5382: UNION with ORDER BY in subselect +# +CREATE TABLE t1 (a int DEFAULT NULL); +INSERT INTO t1 VALUES (2), (4); +CREATE TABLE t2 (b int DEFAULT NULL); +INSERT INTO t2 VALUES (1), (3); +SELECT c1 FROM (SELECT (SELECT a FROM t1 WHERE t1.a <= t2.b +UNION ALL +SELECT a FROM t1 WHERE t1.a+3<= t2.b +ORDER BY a DESC) AS c1 FROM t2) t3; +c1 +NULL +2 +DROP TABLE t1,t2; End of 5.3 tests diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index bb0e5610a26..bc995aac0a0 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -1227,5 +1227,21 @@ deallocate prepare stmt1; DROP VIEW v1; DROP TABLE t1; +--echo # +--echo # mdev-5382: UNION with ORDER BY in subselect +--echo # + + CREATE TABLE t1 (a int DEFAULT NULL); + INSERT INTO t1 VALUES (2), (4); + CREATE TABLE t2 (b int DEFAULT NULL); + INSERT INTO t2 VALUES (1), (3); + + SELECT c1 FROM (SELECT (SELECT a FROM t1 WHERE t1.a <= t2.b + UNION ALL + SELECT a FROM t1 WHERE t1.a+3<= t2.b + ORDER BY a DESC) AS c1 FROM t2) t3; + + DROP TABLE t1,t2; + --echo End of 5.3 tests diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 130763de76a..3eeb8afef6b 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -6429,9 +6429,9 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list, else { if (thd->mark_used_columns == MARK_COLUMNS_READ) - it->walk(&Item::register_field_in_read_map, 1, (uchar *) 0); + it->walk(&Item::register_field_in_read_map, 0, (uchar *) 0); else - it->walk(&Item::register_field_in_write_map, 1, (uchar *) 0); + it->walk(&Item::register_field_in_write_map, 0, (uchar *) 0); } } else