Repository navigation
Conversation
…tible type at analysis `FunctionComparison` admitted a `String`/`FixedString` operand against any type when resolving, but at execution only a constant string is converted to the other operand's type, so `s != 1` with a non-constant `s` failed with `NO_COMMON_TYPE` only when executed. Optimizations that remove or merge the comparison first (the chain rewrite to `IN`/`NOT IN` at `optimize_min_*_chain_length`, a constant-false filter) made the same predicate accepted or rejected depending on chain length. Check this pair in `getReturnTypeImpl` when the other operand is a constant, so the error is raised during analysis regardless of later optimizations. Related: ClickHouse#121006 Related: ClickHouse#121146
Contributor
|
Workflow [PR], commit [25a9746] Summary: ❌
|
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.
Related: #121006
Related: #121146
Related: #111924
FunctionComparison::getReturnTypeImpladmits aString/FixedStringoperand against any other type ("Everything can be compared with string by conversion"), but at execution only a constant string is converted to the other operand's type (executeWithConstString). A non-constant string against a constant without a common supertype (s != 1,toString(uuid_col) != toUUID(...),s = toDate(...)) always throwsNO_COMMON_TYPE, but only when the comparison is executed. So whether the query fails depends on whether an optimization removes the comparison first:This PR checks that pair when the comparison is resolved, if the other operand is a constant, so the error is raised during analysis, before any optimizer pass, for every chain length and with both analyzers. This replaces #121146, which tried to make
LogicalExpressionOptimizerPasspredict which comparisons would throw by re-implementing the execution rules ofFunctionComparisonin the optimizer.Not affected: a constant string against anything (
number = '1','1' = 1),Enumconstants (common typeString),FixedString(16)againstIPv6, tuples (a string is parsed as a tuple),Dynamic/Variant/JSONconstants, and pairs where neither side is a constant, which keep the existing execution-time behaviour.One more case becomes an error: a string column that is constant only at execution, e.g.
SELECT count() FROM (SELECT 'a' AS s) WHERE s = 1, because the analyzer does not see its constness. This relied on the execution-time coercion by accident and fails as soon as the column is materialized.The query in #121006 keeps failing, now consistently: in 26.6 it succeeded only because the
NOT INrewrite built a set from theUUIDconstants that could never match aString(#117240), silently dropping the filter.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Comparing a non-constant
StringorFixedStringexpression with a constant of a type that has no common type with it (for examples != 1ortoString(uuid) = toUUID('...')) now throwsNO_COMMON_TYPEduring query analysis. Previously the error was raised only when the comparison was executed, so the same condition was accepted when an optimization removed it, e.g. a chain of three or more such comparisons rewritten toNOT IN, or a filter that was never executed. Use a constant of the string type, e.g.s != '1', or convert one side explicitly.Workflow [PR]
Sync PR [sync-upstream/pr/121719]