Repository navigation
Conversation
…ueries When a correlated subquery refers to the outer query from two of its relations through columns with the same name, `SubqueryAlias` gives those columns unique aliases (`k`, `k:1`), but `replace_qualified_name` rewrote the pulled-up join filter by column name only, so both columns referred to the first one and the query returned wrong results. This affected EXISTS, NOT EXISTS, IN and scalar subqueries. Map each correlated column to the name it has in the alias's schema, found by its position in the decorrelated subquery's schema. Columns the schema only has under a derived table's alias keep the name-based mapping.
|
Marked as draft after 14 days without activity: merge conflicts. Please address these items and mark Ready for review when ready. |
alamb
requested changes
Oct 28, 2026
alamb
left a comment
Contributor
There was a problem hiding this comment.
Thank you for your contribution; Sorry I don't think this is the right approach
As I mentioned elsewhere (sorry for the repeated content) I don't think we should be trying to patch these subquery cases to make them work; Instead I think we should make the query error otherwise i worry we just open ourselves up to more wrong results bugs. To make it work and have confidence it will be correct, I think we need a more general approach than patches. See here for details
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
See issue #26234.
What changes are included in this PR?
When a correlated subquery refers to the outer query from two of its relations through columns with the same name,
SubqueryAliasgives those columns unique aliases (k,k:1), butreplace_qualified_namerewrote the pulled-up join filter by column name only, so both columns referred to the first one and the query returned wrong results. This affected EXISTS, NOT EXISTS, IN and scalar subqueries.Map each correlated column to the name it has in the alias's schema, found by its position in the decorrelated subquery's schema. Columns the schema only has under a derived table's alias keep the name-based mapping.
What is the testing strategy for this PR?
Introducing new tests for the affected subqueries.
Are there any user-facing changes?
Correcting the behaviour of queries that previously produced the wrong results.