Commit 0865e3de authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-7792 - SQL Parsing Error - UNION AND ORDER BY WITH JOIN

ORDER BY against union may confuse name resolution context, causing valid
SQL statements to fail.

The purpose of context change was presumably intended for the duration of
gathering field list for ORDER BY. However it isn't actually required (name
resolution context is never accessed by the latter).

See also alternative solution (in MySQL 5.7): 92145b95.
parent ad9b3263
...@@ -643,3 +643,10 @@ CREATE TRIGGER trigger1 BEFORE INSERT ON t1 FOR EACH ROW ...@@ -643,3 +643,10 @@ CREATE TRIGGER trigger1 BEFORE INSERT ON t1 FOR EACH ROW
SET default_storage_engine = NEW.INNODB; SET default_storage_engine = NEW.INNODB;
ERROR 42S22: Unknown column 'INNODB' in 'NEW' ERROR 42S22: Unknown column 'INNODB' in 'NEW'
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-7792 - SQL Parsing Error - UNION AND ORDER BY WITH JOIN
#
CREATE TABLE t1(a INT);
SELECT * FROM t1 JOIN ((SELECT 1 AS b) UNION ALL (SELECT 2 AS b) ORDER BY b DESC) s1 WHERE a=1;
a b
DROP TABLE t1;
...@@ -758,3 +758,10 @@ CREATE TABLE t1 (s VARCHAR(100)); ...@@ -758,3 +758,10 @@ CREATE TABLE t1 (s VARCHAR(100));
CREATE TRIGGER trigger1 BEFORE INSERT ON t1 FOR EACH ROW CREATE TRIGGER trigger1 BEFORE INSERT ON t1 FOR EACH ROW
SET default_storage_engine = NEW.INNODB; SET default_storage_engine = NEW.INNODB;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-7792 - SQL Parsing Error - UNION AND ORDER BY WITH JOIN
--echo #
CREATE TABLE t1(a INT);
SELECT * FROM t1 JOIN ((SELECT 1 AS b) UNION ALL (SELECT 2 AS b) ORDER BY b DESC) s1 WHERE a=1;
DROP TABLE t1;
...@@ -11336,7 +11336,6 @@ order_clause: ...@@ -11336,7 +11336,6 @@ order_clause:
*/ */
DBUG_ASSERT(sel->master_unit()->fake_select_lex); DBUG_ASSERT(sel->master_unit()->fake_select_lex);
lex->current_select= sel->master_unit()->fake_select_lex; lex->current_select= sel->master_unit()->fake_select_lex;
lex->push_context(&lex->current_select->context, thd->mem_root);
} }
} }
order_list order_list
......
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