[MDEV-16359] wrong result (extra rows) on the query with UNION and brackets Created: 2018-05-31  Updated: 2018-08-04  Resolved: 2018-08-04

Status: Closed
Project: MariaDB Server
Component/s: Parser
Affects Version/s: 10.4
Fix Version/s: 10.4.0

Type: Bug Priority: Major
Reporter: Alice Sherepa Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-16317 Testing for brackets (parentheses) in... Stalled

 Description   

MariaDB [test]> (select 1) union (select 1) union (select 1);
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.000 sec)
 
MariaDB [test]> ((select 1) union (select 1) union (select 1));
+---+
| 1 |
+---+
| 1 |
| 1 |
+---+
2 rows in set (0.000 sec)



 Comments   
Comment by Alice Sherepa [ 2018-07-05 ]

 10.4 9183f66f056e27490
MariaDB [test]> CREATE OR REPLACE FUNCTION func() RETURNS int RETURN   ( (SELECT 1 a) UNION (SELECT 2)  limit 1 );
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 2)  limit 1 )' at line 1
MariaDB [test]> (SELECT 1 a) UNION (SELECT 2)  limit 1;
+---+
| a |
+---+
| 1 |
+---+
1 row in set (0.001 sec)
 
MariaDB [test]> ((SELECT 1 a) UNION (SELECT 2)  limit 1);
+---+
| a |
+---+
| 1 |
| 2 |
+---+
2 rows in set (0.001 sec)
 
MariaDB [test]> ((SELECT 1 a) UNION (SELECT 2)  limit 1) limit 1;
+---+
| a |
+---+
| 1 |
+---+
1 row in set (0.002 sec)
 
MariaDB [test]> CREATE OR REPLACE FUNCTION func() RETURNS int RETURN   (( (SELECT 1 a) UNION (SELECT 2)  limit 1 )limit 1);
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 2)  limit 1 )limit 1)' at line 1

Comment by Igor Babaev [ 2018-08-04 ]

The following is also wrong:

MariaDB [test]> (select 1 union select 1 union select 1);      
+---+
| 1 |
+---+
| 1 |
| 1 |
+---+
MariaDB [test]> explain extended (select 1 union select 1 union select 1);
+------+--------------+--------------+------+---------------+------+---------+------+------+----------+----------------+
| id   | select_type  | table        | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra          |
+------+--------------+--------------+------+---------------+------+---------+------+------+----------+----------------+
|    1 | PRIMARY      | NULL         | NULL | NULL          | NULL | NULL    | NULL | NULL |     NULL | No tables used |
|    2 | UNION        | NULL         | NULL | NULL          | NULL | NULL    | NULL | NULL |     NULL | No tables used |
|    3 | UNION        | NULL         | NULL | NULL          | NULL | NULL    | NULL | NULL |     NULL | No tables used |
| NULL | UNION RESULT | <union1,2,3> | ALL  | NULL          | NULL | NULL    | NULL | NULL |     NULL |                |
+------+--------------+--------------+------+---------------+------+---------+------+------+----------+----------------+
 
MariaDB [test]> show warnings;
+-------+------+--------------------------------------------------------------------------------------------------------------+
| Level | Code | Message                                                                                                      |
+-------+------+--------------------------------------------------------------------------------------------------------------+
| Note  | 1003 | /* select#1 */ select 1 AS `1` union /* select#2 */ select 1 AS `1` union all /* select#3 */ select 1 AS `1` |
+-------+------+--------------------------------------------------------------------------------------------------------------+

Comment by Igor Babaev [ 2018-08-04 ]

A fix for this bug was pushed into 10.4

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