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

leave aliases in projection #1930

Merged
merged 15 commits into from
Aug 18, 2023
Merged

leave aliases in projection #1930

merged 15 commits into from
Aug 18, 2023

Conversation

jycor
Copy link
Contributor

@jycor jycor commented Aug 8, 2023

We convert expression.Alias into expression.GetField with the name replaced in the top-level projection.
When aliasing two different columns with the same name, we fail to properly distinguish them and end up rewriting the GetField indexes for both columns to be the same; this leads to incorrect results.

A simple fix appears to be simply allowing the top-level projection to remain as an expression.Alias.
This fix does not work for prepared statements in the old name resolution path.

fix for: dolthub/dolt#6455

@@ -1124,7 +1124,22 @@ Select * from (
{
Query: `select y, (select 1 from uv where y = 1 and u = x) is_one from xy join uv on x = v order by y;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [xy.y:1, is_one:4]\n" +
" ├─ columns: [xy.y:1, Subquery\n" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm kind of surprised this doesn't break sometimes. i intentionally separate subquery expressions from their inputs so that correlated subqueries get their inputs. i guess if we stack them deep enough the subqueries still get their inputs. either way this isn't ideal, we need lateral joins to avoid the duplicate exec and naming trade-offs

Copy link
Contributor

@max-hoffman max-hoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of skeptical of this one, but if it works it works. The duplication is kind of painful, but using lateral joins to fix subquery duplication/naming is within arms length now.

@jycor jycor merged commit ca2b258 into main Aug 18, 2023
6 checks passed
@Hydrocharged Hydrocharged deleted the james/aliasing branch August 24, 2023 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants