[MDEV-10012] OUTER JOIN of NATURAL JOINs is not supported Created: 2016-04-30  Updated: 2018-05-08

Status: Open
Project: MariaDB Server
Component/s: Parser
Affects Version/s: 5.5, 10.0, 10.1, 10.2
Fix Version/s: 10.2

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: None

Sprint: 10.2.14

 Description   

This query:

SELECT * FROM
t1 NATURAL JOIN t2
    LEFT JOIN
t3 NATURAL JOIN t4
    USING (a);

produces an error:

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 'USING (a)' at line 4

This is a wrong behavior. It's a valid query according to the standard.
Oracle and PostgreSQL support this.

The problem here is that the USING clause is related to the LEFT JOIN operation, while MariaDB tries to apply it to the second NATURAL JOIN.

According to the Standard, NATURAL and CROSS joins have higher precedence over OUTER and INNER joins.

So the above query should mean exactly the same with:

SELECT * FROM
(t1 NATURAL JOIN t2)
    LEFT JOIN
(t3 NATURAL JOIN t4)
    USING (a);

which works fine and does not produce syntax errors.


Generated at Thu Feb 08 07:39:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.