List:Commits« Previous MessageNext Message »
From:Martin Hansson Date:January 1 1970 12:00am
Subject:bzr push into mysql-6.0 branch (mhansson:2839) Bug#32858
View as plain text  
 2839 Martin Hansson	2008-09-15 [merge]
      Bug#32858: Auto merged.
modified:
  mysql-test/r/union.result
  mysql-test/t/union.test
  sql/sql_yacc.yy

=== modified file 'mysql-test/r/union.result'
--- a/mysql-test/r/union.result	2008-05-13 15:15:40 +0000
+++ b/mysql-test/r/union.result	2008-09-15 13:43:42 +0000
@@ -1521,3 +1521,33 @@ Field	Type	Null	Key	Default	Extra
 NULL	int(11)	YES		NULL	
 DROP TABLE t1, t2, t3, t4, t5, t6;
 End of 5.0 tests
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1);
+SELECT a INTO @v FROM (
+SELECT a FROM t1
+UNION
+SELECT a FROM t1
+) alias;
+SELECT a INTO OUTFILE 'union.out.file' FROM (
+SELECT a FROM t1
+UNION
+SELECT a FROM t1 WHERE 0
+) alias;
+SELECT a INTO DUMPFILE 'union.out.file2' FROM (
+SELECT a FROM t1
+UNION
+SELECT a FROM t1 WHERE 0
+) alias;
+SELECT a FROM t1 UNION SELECT a INTO @v FROM t1;
+SELECT a FROM t1 UNION SELECT a INTO OUTFILE 'union.out.file5' FROM t1;
+SELECT a FROM t1 UNION SELECT a INTO OUTFILE 'union.out.file6' FROM t1;
+SELECT a INTO @v FROM t1 UNION SELECT a FROM t1;
+ERROR HY000: Incorrect usage of UNION and INTO
+SELECT a INTO OUTFILE 'union.out.file7' FROM t1 UNION SELECT a FROM t1;
+ERROR HY000: Incorrect usage of UNION and INTO
+SELECT a INTO DUMPFILE 'union.out.file8' FROM t1 UNION SELECT a FROM t1;
+ERROR HY000: Incorrect usage of UNION and INTO
+SELECT ( SELECT a UNION SELECT a ) INTO @v FROM t1;
+SELECT ( SELECT a UNION SELECT a ) INTO OUTFILE  'union.out.file3' FROM t1;
+SELECT ( SELECT a UNION SELECT a ) INTO DUMPFILE 'union.out.file4' FROM t1;
+DROP TABLE t1;

=== modified file 'mysql-test/t/union.test'
--- a/mysql-test/t/union.test	2008-09-10 12:50:02 +0000
+++ b/mysql-test/t/union.test	2008-09-15 14:06:56 +0000
@@ -990,3 +990,45 @@ DESC t6;
 
 DROP TABLE t1, t2, t3, t4, t5, t6;
 --echo End of 5.0 tests
+#
+# Bug#32858: Error: "Incorrect usage of UNION and INTO" does not take subselects 
+# into account
+#
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1);
+
+# Test fix in parser rule select_derived_union.
+SELECT a INTO @v FROM (
+  SELECT a FROM t1
+  UNION
+  SELECT a FROM t1
+) alias;
+
+SELECT a INTO OUTFILE 'union.out.file' FROM (
+  SELECT a FROM t1
+  UNION
+  SELECT a FROM t1 WHERE 0
+) alias;
+
+SELECT a INTO DUMPFILE 'union.out.file2' FROM (
+  SELECT a FROM t1
+  UNION
+  SELECT a FROM t1 WHERE 0
+) alias;
+
+SELECT a FROM t1 UNION SELECT a INTO @v FROM t1;
+SELECT a FROM t1 UNION SELECT a INTO OUTFILE 'union.out.file5' FROM t1;
+SELECT a FROM t1 UNION SELECT a INTO OUTFILE 'union.out.file6' FROM t1;
+--error ER_WRONG_USAGE
+SELECT a INTO @v FROM t1 UNION SELECT a FROM t1;
+--error ER_WRONG_USAGE
+SELECT a INTO OUTFILE 'union.out.file7' FROM t1 UNION SELECT a FROM t1;
+--error ER_WRONG_USAGE
+SELECT a INTO DUMPFILE 'union.out.file8' FROM t1 UNION SELECT a FROM t1;
+
+# Tests fix in parser rule query_expression_body.
+SELECT ( SELECT a UNION SELECT a ) INTO @v FROM t1;
+SELECT ( SELECT a UNION SELECT a ) INTO OUTFILE  'union.out.file3' FROM t1;
+SELECT ( SELECT a UNION SELECT a ) INTO DUMPFILE 'union.out.file4' FROM t1;
+
+DROP TABLE t1;

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2008-09-10 08:38:07 +0000
+++ b/sql/sql_yacc.yy	2008-09-15 14:06:56 +0000
@@ -461,21 +461,28 @@ Item* handle_sql2003_note184_exception(T
 
    Sets up and initializes a SELECT_LEX structure for a query once the parser
    discovers a UNION token. The current SELECT_LEX is pushed on the stack and
-   the new SELECT_LEX becomes the current one..=
+   the new SELECT_LEX becomes the current one.
 
-   @lex The parser state.
+   @param lex The parser state.
 
-   @is_union_distinct True if the union preceding the new select statement
+   @param is_union_distinct True if the union preceding the new select statement
    uses UNION DISTINCT.
 
+   @param is_top_level This should be @c TRUE if the newly created SELECT_LEX
+   is a non-nested statement.
+
    @return <code>false</code> if successful, <code>true</code> if an error was
    reported. In the latter case parsing should stop.
  */
-bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
+bool add_select_to_union_list(LEX *lex, bool is_union_distinct, 
+                              bool is_top_level)
 {
-  if (lex->result)
+  /* 
+     Only the last SELECT can have INTO. Since the grammar won't allow INTO in
+     a nested SELECT, we make this check only when creating a top-level SELECT.
+  */
+  if (is_top_level && lex->result)
   {
-    /* Only the last SELECT can have  INTO...... */
     my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
     return TRUE;
   }
@@ -8955,7 +8962,7 @@ select_derived_union:
           UNION_SYM
           union_option
           {
-            if (add_select_to_union_list(Lex, (bool)$3))
+            if (add_select_to_union_list(Lex, (bool)$3, FALSE))
               MYSQL_YYABORT;
           }
           query_specification
@@ -13332,7 +13339,7 @@ union_clause:
 union_list:
           UNION_SYM union_option
           {
-            if (add_select_to_union_list(Lex, (bool)$2))
+            if (add_select_to_union_list(Lex, (bool)$2, TRUE))
               MYSQL_YYABORT;
           }
           select_init
@@ -13402,7 +13409,7 @@ query_expression_body:
         | query_expression_body
           UNION_SYM union_option 
           {
-            if (add_select_to_union_list(Lex, (bool)$3))
+            if (add_select_to_union_list(Lex, (bool)$3, FALSE))
               MYSQL_YYABORT;
           }
           query_specification

Thread
bzr push into mysql-6.0 branch (mhansson:2839) Bug#32858Martin Hansson15 Sep