revision-id: 22517dd937d31d3beb03d01f736a43f86b709d48 (mariadb-10.3.6-197-g22517dd)
parent(s): 563efeceece09154f71da6303244b1df36875428
author: Igor Babaev
committer: Igor Babaev
timestamp: 2018-11-06 09:40:07 -0800
message:
MDEV-16357 LIMIT and ORDER BY clause is ignored on a query with UNION
when using brackets
Do not create master unit for select if it has already one.
---
mysql-test/main/brackets.result | 24 ++++++++++++++++++++++++
mysql-test/main/brackets.test | 18 ++++++++++++++++++
sql/sql_lex.cc | 3 +++
3 files changed, 45 insertions(+)
diff --git a/mysql-test/main/brackets.result b/mysql-test/main/brackets.result
index 479b74b..e789cde 100644
--- a/mysql-test/main/brackets.result
+++ b/mysql-test/main/brackets.result
@@ -219,4 +219,28 @@ select 1 union select 1 union select 1;
((select 1) union (select 1) union (select 1));
1
1
+#
+# MDEV-16357: union in brackets with tail
+# union with tail in brackets
+#
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES(1),(2),(3),(4);
+CREATE TABLE t2 (a int);
+INSERT INTO t2 VALUES (4),(5),(6),(7);
+(SELECT a FROM t1 UNION SELECT a FROM t2) LIMIT 1;
+a
+1
+(SELECT a FROM t1 UNION SELECT a FROM t2) ORDER BY a DESC;
+a
+7
+6
+5
+4
+3
+2
+1
+(SELECT a FROM t1 UNION SELECT a FROM t2 LIMIT 1);
+a
+1
+DROP TABLE t1,t2;
# End of 10.4 tests
diff --git a/mysql-test/main/brackets.test b/mysql-test/main/brackets.test
index 699c70a..0eaa3bf 100644
--- a/mysql-test/main/brackets.test
+++ b/mysql-test/main/brackets.test
@@ -88,5 +88,23 @@ select 1 union select 1 union select 1;
(select 1 union select 1 union select 1);
((select 1) union (select 1) union (select 1));
+--echo #
+--echo # MDEV-16357: union in brackets with tail
+--echo # union with tail in brackets
+--echo #
+
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES(1),(2),(3),(4);
+
+CREATE TABLE t2 (a int);
+INSERT INTO t2 VALUES (4),(5),(6),(7);
+
+(SELECT a FROM t1 UNION SELECT a FROM t2) LIMIT 1;
+(SELECT a FROM t1 UNION SELECT a FROM t2) ORDER BY a DESC;
+
+(SELECT a FROM t1 UNION SELECT a FROM t2 LIMIT 1);
+
+DROP TABLE t1,t2;
+
--echo # End of 10.4 tests
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 4a5aedc..9fdebd6 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -5250,6 +5250,9 @@ LEX::create_unit(SELECT_LEX *first_sel)
SELECT_LEX_UNIT *unit;
DBUG_ENTER("LEX::create_unit");
+ if (first_sel->master_unit())
+ DBUG_RETURN(first_sel->master_unit());
+
if (!(unit= alloc_unit()))
DBUG_RETURN(NULL);
_______________________________________________
commits mailing list
commits@mariadb.org
https://lists.askmonty.org/cgi-bin/mailman/listinfo/commits