Repository navigation
Cherry pick #108553 to 26.6: Make tryOptimizeAndCompareChain idempotent (fix NOT_FOUND_COLUMN_IN_BLOCK with identifier resolve cache) - #108718
Merged
Conversation
tryOptimizeAndCompareChain appended a derived transitive conjunct to the
AND with push_back and never checked whether an equal conjunct was already
present, so the optimization was not idempotent.
The identifier resolve cache (enable_identifier_resolve_cache, on by
default) can hand the same resolved expression node to several use sites
(projection, HAVING, GROUP BY key). The logical-expression optimizer
visitor does not deduplicate shared nodes, so a shared AND was visited once
per parent and accumulated the same derived conjunct on every visit
(2-arg and -> 4-arg) while a singly-referenced GROUP BY key copy stayed
3-arg. GROUP BY keys are matched against the projection by formatted name,
so the two no longer matched and the query failed with
NOT_FOUND_COLUMN_IN_BLOCK on valid queries using default settings, e.g.
SELECT a FROM numbers(2)
GROUP BY ((number >= materialize(5)) AND (0 >= number)) AS a HAVING a
The sibling rewrites (tryOptimizeAndEqualsNotEqualsChain,
tryReplaceOrEqualsChainWithIn) replace the argument list rather than
appending, so they were already idempotent; this was the only offender.
The fix tracks the conjuncts already present in the AND and appends a
derived one only when an equal conjunct is not there yet. The pass is now
idempotent, so the result is independent of node sharing and the resolve
cache keeps returning shared nodes without copying.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…lve-cache-shared-node-108518 Make tryOptimizeAndCompareChain idempotent (fix NOT_FOUND_COLUMN_IN_BLOCK with identifier resolve cache)
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.
Original pull-request #108553
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job