From 0865e3deab7be2bd49128906fe4f495460ebcbca Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Wed, 24 Jun 2015 14:58:17 +0400 Subject: [PATCH] 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. --- mysql-test/r/parser.result | 7 +++++++ mysql-test/t/parser.test | 7 +++++++ sql/sql_yacc.yy | 1 - 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/parser.result b/mysql-test/r/parser.result index 5b0fbbcbe87..1d29f2c4a0e 100644 --- a/mysql-test/r/parser.result +++ b/mysql-test/r/parser.result @@ -643,3 +643,10 @@ CREATE TRIGGER trigger1 BEFORE INSERT ON t1 FOR EACH ROW SET default_storage_engine = NEW.INNODB; ERROR 42S22: Unknown column 'INNODB' in 'NEW' 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; diff --git a/mysql-test/t/parser.test b/mysql-test/t/parser.test index f59a5d01cf5..31c6ab92ba8 100644 --- a/mysql-test/t/parser.test +++ b/mysql-test/t/parser.test @@ -758,3 +758,10 @@ CREATE TABLE t1 (s VARCHAR(100)); CREATE TRIGGER trigger1 BEFORE INSERT ON t1 FOR EACH ROW SET default_storage_engine = NEW.INNODB; 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; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 373503ad94d..1d31df4d000 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -11336,7 +11336,6 @@ order_clause: */ DBUG_ASSERT(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