Commit 90650edf authored by Magne Mahre's avatar Magne Mahre

Bug#58970 Problem Subquery (without referencing a table)

          and Order By
      
When having a UNION statement in a subquery, with no
referenced tables (or only a reference to the virtual
table 'dual'), the UNION did not allow an ORDER BY clause.
      
      i.e:
          SELECT(SELECT 1 AS a UNION 
                 SELECT 0 AS a 
                 ORDER BY a) AS b  or
          SELECT(SELECT 1 AS a FROM dual UNION 
                 SELECT 0 as a 
                 ORDER BY a) AS b
      
      
In addition, an ORDER BY / LIMIT clause was not accepted
in subqueries even for single SELECT statements with no 
referenced tables (or with 'dual' as table reference)
      
   i.e: 
      SELECT(SELECT 1 AS a ORDER BY a) AS b  or
      SELECT(SELECT 1 AS a FROM dual ORDER BY a) AS b
      
The fix was to allow an optional ORDER BY/LIMIT clause to
the grammar for these cases.
      
See also: Bug#57986
parent 1b645167
......@@ -1744,3 +1744,28 @@ ORDER BY c2 DESC, c1 ASC LIMIT 1
c1 c2
t1a 3
DROP TABLE t1, t2;
#
# Bug #58970 Problem Subquery (without referencing a table)
# and Order By
#
SELECT(SELECT 0 AS a UNION SELECT 1 AS a ORDER BY a ASC LIMIT 1) AS dev;
dev
0
SELECT(SELECT 0 AS a UNION SELECT 1 AS a ORDER BY a DESC LIMIT 1) AS dev;
dev
1
SELECT(SELECT 0 AS a FROM dual UNION SELECT 1 AS a FROM dual ORDER BY a ASC LIMIT 1) AS dev;
dev
0
SELECT(SELECT 0 AS a FROM dual UNION SELECT 1 AS a FROM dual ORDER BY a DESC LIMIT 1) AS dev;
dev
1
SELECT(SELECT 1 AS a ORDER BY a) AS dev;
dev
1
SELECT(SELECT 1 AS a LIMIT 1) AS dev;
dev
1
SELECT(SELECT 1 AS a FROM dual ORDER BY a DESC LIMIT 1) AS dev;
dev
1
......@@ -1171,3 +1171,16 @@ SELECT c1, c2 FROM (
) AS res;
DROP TABLE t1, t2;
--echo #
--echo # Bug #58970 Problem Subquery (without referencing a table)
--echo # and Order By
--echo #
SELECT(SELECT 0 AS a UNION SELECT 1 AS a ORDER BY a ASC LIMIT 1) AS dev;
SELECT(SELECT 0 AS a UNION SELECT 1 AS a ORDER BY a DESC LIMIT 1) AS dev;
SELECT(SELECT 0 AS a FROM dual UNION SELECT 1 AS a FROM dual ORDER BY a ASC LIMIT 1) AS dev;
SELECT(SELECT 0 AS a FROM dual UNION SELECT 1 AS a FROM dual ORDER BY a DESC LIMIT 1) AS dev;
SELECT(SELECT 1 AS a ORDER BY a) AS dev;
SELECT(SELECT 1 AS a LIMIT 1) AS dev;
SELECT(SELECT 1 AS a FROM dual ORDER BY a DESC LIMIT 1) AS dev;
......@@ -13914,7 +13914,7 @@ query_specification:
;
query_expression_body:
query_specification
query_specification opt_union_order_or_limit
| query_expression_body
UNION_SYM union_option
{
......@@ -13922,6 +13922,7 @@ query_expression_body:
MYSQL_YYABORT;
}
query_specification
opt_union_order_or_limit
{
Lex->pop_context();
$$= $1;
......
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