Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple CTEs with the same name can cause incorrect results #4950

Closed
fulghum opened this issue Dec 8, 2022 · 1 comment
Closed

Multiple CTEs with the same name can cause incorrect results #4950

fulghum opened this issue Dec 8, 2022 · 1 comment
Assignees
Labels
bug Something isn't working good repro Easily reproducible bugs sql Issue with SQL

Comments

@fulghum
Copy link
Contributor

fulghum commented Dec 8, 2022

CTEs with the same name, in different scopes can cause incorrect query results.

Consider the following statement with two CTEs at different scopes, both named cte:

WITH cte(id) AS (
	SELECT 0 from dual
)
SELECT cte.id  
FROM cte
where cte.id in (
	WITH cte(id)
	AS (
		SELECT 42 from dual
	)
	select id from cte
);

MySQL returns:

Empty set (0.01 sec)

Dolt returns:

+----+
| id |
+----+
| 42 |
+----+
1 row in set (0.00 sec)

Dolt doesn't seem to correctly distinguish between the two CTEs with the same name.

Changing the name of the second CTE, as in the statement below, causes Dolt to return the same result as MySQL:

WITH cte(id) AS (
	SELECT 0 from dual
)
SELECT cte.id  
FROM cte
where cte.id in (
	WITH cte2(id)
	AS (
		SELECT 42 from dual
	)
	select id from cte2
);
@fulghum fulghum added bug Something isn't working sql Issue with SQL good repro Easily reproducible bugs labels Dec 8, 2022
@jycor jycor self-assigned this Dec 21, 2022
@jycor
Copy link
Contributor

jycor commented Dec 22, 2022

fix is merged to main

@jycor jycor closed this as completed Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good repro Easily reproducible bugs sql Issue with SQL
Projects
None yet
Development

No branches or pull requests

2 participants