Bug #17 Incorrect parsing of UNION in IN subselect
Submitted: 30 Dec 2002 0:38 Modified: 21 Jul 2003 8:03
Reporter: Oleksandr Byelkin Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1 OS:Any (any)
Assigned to: CPU Architecture:Any

[30 Dec 2002 0:38] Oleksandr Byelkin
Description:
UNION subselects with braces inside is incorrectly parsed. 

How to repeat:
mysql> (select 1) union (select 2) limit 2; 
+---+ 
| 1 | 
+---+ 
| 1 | 
| 2 | 
+---+ 
2 rows in set (0.00 sec) 
it is OK 
 
mysql> select 1 in (select 1 union select 2); 
+--------------------------------+ 
| 1 in (select 1 union select 2) | 
+--------------------------------+ 
|                              1 | 
+--------------------------------+ 
1 row in set (0.00 sec) 
 
it is OK, too 
 
 
mysql> select 1 in ((select 1) union (select 2) limit 2); 
ERROR 1064: You have an error in your SQL syntax.  Check the manual that 
corresponds to your MySQL server version for the right syntax to use near 'union (select 
2) limit 2)' at line 1 
 
it should not be syntax error, but "This version of MySQL doesn't yet support 'LIMIT & 
IN/ALL/ANY/SOME subquery'" 
 
ysql> select 1 in ((select 1) union (select 2)); 
ERROR 1064: You have an error in your SQL syntax.  Check the manual that 
corresponds to your MySQL server version for the right syntax to use near 'union (select 
2))' at line 1 
 
it should be performed 
 

Suggested fix:
Sorry, If I whold have suggestion about fix I had fixed it already.
[3 Mar 2003 7:29] MySQL Verification Team
This bug happens to due to error in parsing.

A problem is caused by parenthesis parsing in 4.1.

Simply, with:
select 1 in ((select 1) union (select 2));

first select in UNION drops in select_init2 instead in
select_init1 parser label !!!
[21 Jul 2003 8:03] Sergei Golubchik
the problem is that "SELECT 1" is a correct expression.
E.g. this query works:

SELECT 1 IN ((SELECT 1),(SELECT 2));

I cannot see how to fix parser to distinguish

SELECT 1 IN ((SELECT 1) UNION (SELECT 2))

from the above with only one look-ahead. At least not without very ugly workarounds and really lousy grammar.

This bug will go away automatically, when we'll get new parser (not bison-based)
[25 Sep 2015 0:34] No Name
A very old post, but it was helpful to me. 

http://bestmanspeechstructure.net/