[MDEV-19421] Basic 3-way join queries are not parsed Created: 2019-05-08  Updated: 2020-12-19  Resolved: 2019-07-12

Status: Closed
Project: MariaDB Server
Component/s: Parser
Affects Version/s: None
Fix Version/s: 10.2.26, 5.5.65, 10.1.41, 10.3.17

Type: Bug Priority: Major
Reporter: Igor Babaev Assignee: Igor Babaev
Resolution: Fixed Votes: 1
Labels: None

Issue Links:
Problem/Incident
causes MDEV-20330 Combination of "," (comma), cross joi... Closed
causes MDEV-21894 MariaDB 10.3 onward unable to parse s... Closed

 Description   

The following simple join

select * from t1 join t2 join t3 on t2.a=t3.a on t1.a=t2.a;

over tables t1,t2,t3

create table t1 (a int); 
insert into t1 values (7), (2), (9);
create table t2 (a int);
insert into t2 values (5), (1), (7);
create table t3 (a int);
insert into t3 values (2), (7), (3); 

cannot be parsed in MariaDB 10.4:

MariaDB [test]> select * from t1 join t2 join t3 on t2.a=t3.a on t1.a=t2.a;
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 'on t1.a=t2.a' at line 1

MySQL 8.0 handles this query properly:

mysql> select * from t1 join t2 join t3 on t2.a=t3.a on t1.a=t2.a;
+------+------+------+
| a    | a    | a    |
+------+------+------+
|    7 |    7 |    7 |
+------+------+------+

This basic valid query also returns syntax error message:

select * from t1 join t2 left join t3 on t2.a=t3.a on t1.a=t2.a;



 Comments   
Comment by Igor Babaev [ 2019-07-01 ]

The bug is reproducible in all versions starting from 5.5.
A has been prepared for 5.5 and it is supposed to be merged up to 10.3.
Another patch has been prepared for 10.4 because the grammar rules for 10.4 differ significantly from those in 5.5-10.3.

Comment by Oleksandr Byelkin [ 2019-07-11 ]

OK to push.

Comment by Igor Babaev [ 2019-07-12 ]

A fix for this bug was pushed into 5.5. I has to be merged upstream into 10.1-10.3 as it is.
10.4 requires a slightly different patch that has been already prepared.

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