Repository navigation
Fix exception-safety classification for Tuple comparisons - #125978
Open
Shoryamishra61 wants to merge 2 commits into
Open
Shoryamishra61 wants to merge 2 commits into
Shoryamishra61 wants to merge 2 commits into
Conversation
comparisonCanThrow(left, right) in FunctionsComparison.h checked !which_left.isVariant() && !which_left.isDynamic() && !which_left.isObject() on the outer type. When these types are nested inside a Tuple (such as Tuple(Variant(String, UInt64))), the outer type is Tuple, causing comparisonCanThrow to return false. Because executeTuple decomposes comparisons into element-wise function calls, comparing variant alternatives with incompatible types throws NO_COMMON_TYPE at runtime. Misclassifying the tuple comparison as non-throwing allowed the optimizer (FilterStep::canBeMovedToTheFrontOfAndChain) to move the tuple comparison ahead of guard conditions in WHERE, evaluating it on rows that should have been excluded. Fix this by: 1. Adding an element-wise recursive check in comparisonCanThrow for DataTypeTuple, ensuring a tuple comparison is classified as non-throwing if and only if both sides have the same non-zero element count and every element comparison cannot throw. 2. Excluding DataTypeTuple from the identical-types IColumn::compareAt shortcut to enforce the recursive element-wise check. 3. Adding regression tests to 05259_short_circuit_reorder_arguments. Fixes ClickHouse#125919.
Contributor
|
Workflow [PR], commit [a0b132a] Summary: ❌
AI ReviewSummaryThe PR recursively checks Final VerdictStatus: ✅ Approve |
This was referenced Nov 1, 2026
opensource-fork-sync Bot
pushed a commit
to cla7aye15I4nd/opensource-ClickHouse__ClickHouse
that referenced
this pull request
Nov 6, 2026
…Throw` Same change as ClickHouse#125978 (fixes ClickHouse#125919). Co-authored-by: Shoryamishra61 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
This branch has not been deployed
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.
Closes: #125919
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a bug where comparison of Tuples containing Variant or Dynamic types was incorrectly classified as non-throwing, causing the optimizer to move potentially throwing tuple comparisons ahead of guard conditions in WHERE. Fixes #125919.
Detailed Description
comparisonCanThrow(left, right)insrc/Functions/FunctionsComparison.huses an exact-type equality check (left->equals(*right)) that excludes top-levelVariant,Dynamic, andObject. However, when these types are nested inside aTuple(e.g.Tuple(Variant(String, UInt64))), the outer type isTuple, causingcomparisonCanThrowto returnfalse.Because
FunctionComparison::executeTupledecomposes comparisons into element-wise function evaluations, comparing variant alternatives with incompatible types (e.g.UInt64vsString) throwsNO_COMMON_TYPEat runtime. Misclassifying the tuple comparison as non-throwing allowedFilterStep::canBeMovedToTheFrontOfAndChainto reorder the tuple comparison ahead of guard conditions inWHERE, evaluating it on rows that should have been excluded.This change:
comparisonCanThrowwhen comparingDataTypeTupleinstances, ensuring a tuple comparison is classified as non-throwing if and only if both sides have the same non-zero element count and every element comparison cannot throw.DataTypeTuplefrom the identical-typesIColumn::compareAtfast path to enforce the recursive element-wise check.05259_short_circuit_reorder_argumentswith guardedTuple(Variant),Tuple(Dynamic), nested tuple, relational operator, and explain plan verification.Workflow [PR]
Sync PR [sync-upstream/pr/125978]