[MDEV-19956] Queries with subqueries containing UNION are not parsed Created: 2019-07-05  Updated: 2019-10-04  Resolved: 2019-10-04

Status: Closed
Project: MariaDB Server
Component/s: Parser
Affects Version/s: 10.4
Fix Version/s: 10.4.9, 10.5.0

Type: Bug Priority: Critical
Reporter: Igor Babaev Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
is blocked by MDEV-19996 Bison grammar: turn singe-character o... Closed
is blocked by MDEV-20634 Report disallowed subquery errors as ... Closed

 Description   

The following query

SELECT ((SELECT a FROM t1 LIMIT 2) UNION (SELECT a FROM t2 LIMIT 2) LIMIT 1) AS r FROM t1 AS t;

returns syntax error message in 10.4:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION (SELECT a FROM t2 LIMIT 2) LIMIT 1) AS r FROM t1 AS t' at line 1

Reprodicible in with the following test case

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 ((SELECT a FROM t1 LIMIT 2) UNION (SELECT a FROM t2 LIMIT 2) LIMIT 1) AS r FROM t1 AS t;

10.3 and probably all prior versions return the same error message.
MySQL-8.0 returns a proper result:

mysql> SELECT ((SELECT a FROM t1 LIMIT 2) UNION (SELECT a FROM t2 LIMIT 2) LIMIT 1) AS r FROM t1 AS t;
+------+
| r    |
+------+
|    1 |
|    1 |
|    1 |
|    1 |
+------+

This query with a subquery in the WHERE clause also failed to be parsed:

MariaDB [test]> SELECT * FROM t1 WHERE t1.a IN ((SELECT a FROM t1) UNION (SELECT a FROM t2));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION (SELECT a FROM t2))' at line 1

10.3 returns the same error message.

MySQL-8.0 is ok with the above query:

mysql> SELECT * FROM t1 WHERE t1.a IN ((SELECT a FROM t1) UNION (SELECT a FROM t2));
+------+
| a    |
+------+
|    1 |
|    2 |
|    3 |
|    4 |
+------+



 Comments   
Comment by Igor Babaev [ 2019-09-24 ]

A fix for this bug was pushed into 10.4.

Comment by Marko Mäkelä [ 2019-10-04 ]

igor, please check my follow-up fix and consider whether s2->next_select() could ever hold in LEX::parsed_select_expr_cont().

Generated at Thu Feb 08 08:55:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.