Skip to content

Cherry pick #108553 to 26.6: Make tryOptimizeAndCompareChain idempotent (fix NOT_FOUND_COLUMN_IN_BLOCK with identifier resolve cache) - #108718

Merged
robot-ch-test-poll merged 4 commits into
backport/26.6/108553from
cherrypick/26.6/108553
Jun 27, 2026
Merged

robot-ch-test-poll merged 4 commits into
backport/26.6/108553from
cherrypick/26.6/108553

Conversation

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 4 commits June 25, 2026 23:14
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)
@robot-ch-test-poll robot-ch-test-poll added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Jun 27, 2026
@robot-ch-test-poll
robot-ch-test-poll merged commit 5f6c5de into backport/26.6/108553 Jun 27, 2026
@robot-ch-test-poll
robot-ch-test-poll deleted the cherrypick/26.6/108553 branch June 27, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants