Repository navigation
Conversation
The eight IgnoreSet variants of IN (in.cpp registers inIgnoreSet, globalInIgnoreSet, notInIgnoreSet, globalNotInIgnoreSet, nullInIgnoreSet, globalNullInIgnoreSet, notNullInIgnoreSet, globalNotNullInIgnoreSet) return 0 for every row without ever looking at their right operand. They exist so that types can be resolved without building a set, and FunctionIn is variadic precisely so the left operand can be passed alone: isVariadic() == ignore_set, getNumberOfArguments() == ignore_set ? 0 : 2, and getReturnTypeImpl accepts 1 or 2 arguments and returns UInt8 either way (src/Functions/in.cpp:51-72). The old analyzer already builds the node that way, and its comment at src/Interpreters/ActionsVisitor.cpp:1322-1341 explains why a stand-in column is not an acceptable substitute. Commit c0596ea stopped preparing the right operand for these functions, which is correct, but kept adding a set column to the ActionsDAG. It gated the tuple lookup, the subquery/storage lookup and the guarding `if (!set) throw` on !ignore_set, so `set` stays default-constructed and ColumnSet::create(1, nullptr) enters the plan. That unconditional throw was what enforced the invariant "a planner-built ColumnSet always holds a non-null FutureSetPtr", so removing it turned an enforced property into an assumed one, and every consumer that dereferences ColumnSet::getData() without a null check became reachable with null. Six of the getData() call sites in the tree are in that shape (ActionsDAG.cpp:4744, VirtualColumnUtils.cpp:83 and :140, ReadFromRemote.cpp:324, KVStorageUtils.cpp:189 and :381); the rest null-check the pointer before using it. Two were observed crashing within fifteen minutes of each other on 2026-09-24, both first-ever in ninety days: - serializeConstant at src/Interpreters/ActionsDAG.cpp:4744, reached from the aggregation hash-table cache-key path (calculateHashTableCacheKeys.cpp:161 -> optimizeTreeSecondPass), master STID 2060-5018; - buildSetsForDagImpl at src/Storages/VirtualColumnUtils.cpp:84, reached from SourceStepWithFilterBase::applyFilters for virtual-column and PREWHERE filter analysis, STID 4168-5979. Both are plain segmentation faults on a debug or release build, and UndefinedBehaviorSanitizer reports them as a member call on a null pointer of type DB::FutureSet. Note that this is a null shared_ptr, not the not-ready-set state, which is future_set->get() == nullptr with future_set itself non-null. Fix the producer rather than the consumers. visitFunction no longer calls makeSetForInFunction for an IgnoreSet call and builds the DAG node from the left operand alone, so no set column is created and there is nothing for a consumer to dereference. Because makeSetForInFunction is no longer reached for these functions, its ignore_set gates are removed and the unconditional `if (!set) throw` is restored, which makes the invariant enforced again instead of merely documented. Guarding the consumers was rejected: it is a symptom guard at the dereference rather than a fix at the source, it does not scale, because each consumer needs its own decision about what a null set means, and serializeConstant has no good local answer because it must emit a FutureSet::Hash, so a sentinel would silently collide distinct plans in the hash-table statistics cache. Attaching a non-null empty placeholder set was also rejected: notInIgnoreSet executes to 0, but an empty set makes a notIn predicate true, so index analysis at KeyCondition.cpp:1044 and RPNBuilder.cpp:432 would then disagree with execution. Since the DAG node now has one child while the query tree function was resolved over two arguments, the node is built from a FunctionFactory resolver over the children that are actually present, which is the same branch group_by_use_nulls already uses and which keeps the node's argument types in agreement with its children. The access-control behaviour added by c0596ea is unchanged: neither PreparedSets lookup is reinstated, so the right-hand side is still never prepared and never authorized, and tests/integration/test_set_engine_row_policy_serialized_plan passes, including the assertion that inIgnoreSet over a Set table succeeds for a user for whom the plain IN spelling is denied by a row policy. Co-Authored-By: Claude Opus 5 <[email protected]>
…r to a shard tryBuildAdditionalFilterAST (src/Processors/QueryPlan/ReadFromRemote.cpp) rebuilds a pushed-down filter as an AST out of the plan's expression DAG, and it assumes the two-child shape for every IN-family function name. The previous commit leaves an IgnoreSet call with its left operand alone, which breaks that assumption in two independent ways. The four global variants are covered by isNameOfGlobalInFunction (src/Analyzer/Utils.cpp), so the GLOBAL IN block reaches node->children.at(1) on a one-child node. std::out_of_range derives from std::logic_error, so src/Common/Exception.cpp aborts the whole server process on a debug or sanitizer build, and on any build where abort_on_logical_error is set (observed: exit 134, stack through tryBuildAdditionalFilterAST); a release build without that flag reports it as query error Code: 1001 instead. Either way a query whose filter is pushed to a shard fails. Before the previous commit this site was safe only incidentally, because the second child existed, its FutureSetPtr was null, typeid_cast of a null pointer gave null, and the set_from_subquery guard skipped the block. The four local variants reach makeASTFunction with arguments built from node->children, so the predicate is written back as one-argument SQL such as HAVING inIgnoreSet(x). The receiving shard resolves that text and src/Analyzer/Resolve/resolveFunction.cpp throws NUMBER_OF_ARGUMENTS_DOESNT_MATCH for any isNameOfInFunction name, so the distributed query fails. Declare such a node non-convertible to AST instead, which is the mechanism this function already uses for lambdas and for captures three lines above: node_to_ast[node] = nullptr. Its existing handling then applies unchanged. The parent's has_all_args goes false; an enclosing and() whose polarity is known positive drops just that child, which is the invariant the function was hardened for in ClickHouse#113445; and if the whole predicate is the IgnoreSet call the function returns nullptr and addFilters adds no filter. This is sound because the AST is only a pushdown optimization: omitting a conjunct can only widen what the shard returns, the initiator still applies the whole filter, and an IgnoreSet call evaluates to 0 for every row anyway, so no pruning is lost even in principle. The bail sits in the single argument walk that all three addFilters call sites funnel through, so it covers the plain, the external-tables GLOBAL and the parallel-replicas paths at once. It fires only when isNameOfInFunction accepts the name and the name ends with IgnoreSet. isNameOfInFunction accepts sixteen names, of which exactly eight end that way, so the walk is byte-identical in behaviour for every DAG that contains no IgnoreSet call. The regression test gains the remote arms, a plan-shape assertion that is true only when the call has a single operand, a wrapper-type matrix whose output is byte-identical to pristine master, an assertion that a filter mixing a convertible conjunct with an IgnoreSet call still pushes the convertible one to the shard, and a paired serialize_query_plan round trip over wrapped operands. Co-Authored-By: Claude Opus 5 <[email protected]>
Condense the argument_types_match note to a one-line invariant: an IgnoreSet node has one child against two expected types.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 6 findings over 3 rounds, the third
Severity: ❌ blocker / Round 3 was clean from both sides. My own cold re-derivation reached the same conclusions by Noted, not blocking: on master the same null pointer also segfaults Session id: cron:clickhouse-review-slot-10:20260924-234800 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260924-231505 |
|
Workflow [PR], commit [302ee40] AI ReviewSummaryThis PR fixes the null Findings❌ [src/Storages/buildQueryTreeForShard.cpp:419-426, 1000-1023] Final Verdict❌ Changes requested. The planner/DAG fix is correct for the local plan shape, but the distributed |
|
|
||
| /// The `IgnoreSet` variants resolve types without a set: no set is registered for them, and they | ||
| /// take the left operand alone, which `FunctionIn`'s variadic arity accepts. | ||
| const bool ignore_set = is_in_function && function_node.getFunctionName().ends_with("IgnoreSet"); |
There was a problem hiding this comment.
Skipping the set child here does not complete the *IgnoreSet-never-reads-its-right-operand contract for distributed queries. buildQueryTreeForShard still treats global*IgnoreSet like ordinary GLOBAL IN: the distributed_product_mode = global rewrite keeps the IgnoreSet names in play at src/Storages/buildQueryTreeForShard.cpp:419-426, and the later global_in_or_join_nodes loop still unconditionally executes/materializes a QUERY/UNION/TABLE second argument at src/Storages/buildQueryTreeForShard.cpp:1000-1023. That means GLOBAL ... IgnoreSet over a subquery/table can still do real work and still fail on access or transfer-limit errors from an operand the function result ignores.
Can we exclude the IgnoreSet variants from that rewrite/materialization path too, and cover it with a distributed test whose RHS is a subquery or table rather than only a constant tuple?
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 28 s compile time in total, 8 of them have a recent master baseline. |
The eight IgnoreSet variants of IN (in.cpp registers inIgnoreSet, globalInIgnoreSet, notInIgnoreSet, globalNotInIgnoreSet, nullInIgnoreSet, globalNullInIgnoreSet, notNullInIgnoreSet, globalNotNullInIgnoreSet) return 0 for every row without ever looking at their right operand. They exist so that types can be resolved without building a set, and FunctionIn is variadic precisely so the left operand can be passed alone: isVariadic() == ignore_set, getNumberOfArguments() == ignore_set ? 0 : 2, and getReturnTypeImpl accepts 1 or 2 arguments and returns UInt8 either way (src/Functions/in.cpp:51-72). The old analyzer already builds the node that way, and its comment at src/Interpreters/ActionsVisitor.cpp:1322-1341 explains why a stand-in column is not an acceptable substitute. Commit c0596ea stopped preparing the right operand for these functions, which is correct, but kept adding a set column to the ActionsDAG. It gated the tuple lookup, the subquery/storage lookup and the guarding `if (!set) throw` on !ignore_set, so `set` stays default-constructed and ColumnSet::create(1, nullptr) enters the plan. That unconditional throw was what enforced the invariant "a planner-built ColumnSet always holds a non-null FutureSetPtr", so removing it turned an enforced property into an assumed one, and every consumer that dereferences ColumnSet::getData() without a null check became reachable with null. Six of the getData() call sites in the tree are in that shape (ActionsDAG.cpp:4744, VirtualColumnUtils.cpp:83 and :140, ReadFromRemote.cpp:324, KVStorageUtils.cpp:189 and :381); the rest null-check the pointer before using it. Two were observed crashing within fifteen minutes of each other on 2026-09-24, both first-ever in ninety days: - serializeConstant at src/Interpreters/ActionsDAG.cpp:4744, reached from the aggregation hash-table cache-key path (calculateHashTableCacheKeys.cpp:161 -> optimizeTreeSecondPass), master STID 2060-5018; - buildSetsForDagImpl at src/Storages/VirtualColumnUtils.cpp:84, reached from SourceStepWithFilterBase::applyFilters for virtual-column and PREWHERE filter analysis, STID 4168-5979. Both are plain segmentation faults on a debug or release build, and UndefinedBehaviorSanitizer reports them as a member call on a null pointer of type DB::FutureSet. Note that this is a null shared_ptr, not the not-ready-set state, which is future_set->get() == nullptr with future_set itself non-null. Fix the producer rather than the consumers. visitFunction no longer calls makeSetForInFunction for an IgnoreSet call and builds the DAG node from the left operand alone, so no set column is created and there is nothing for a consumer to dereference. Because makeSetForInFunction is no longer reached for these functions, its ignore_set gates are removed and the unconditional `if (!set) throw` is restored, which makes the invariant enforced again instead of merely documented. Guarding the consumers was rejected: it is a symptom guard at the dereference rather than a fix at the source, it does not scale, because each consumer needs its own decision about what a null set means, and serializeConstant has no good local answer because it must emit a FutureSet::Hash, so a sentinel would silently collide distinct plans in the hash-table statistics cache. Attaching a non-null empty placeholder set was also rejected: notInIgnoreSet executes to 0, but an empty set makes a notIn predicate true, so index analysis at KeyCondition.cpp:1044 and RPNBuilder.cpp:432 would then disagree with execution. Since the DAG node now has one child while the query tree function was resolved over two arguments, the node is built from a FunctionFactory resolver over the children that are actually present, which is the same branch group_by_use_nulls already uses and which keeps the node's argument types in agreement with its children. The access-control behaviour added by c0596ea is unchanged: neither PreparedSets lookup is reinstated, so the right-hand side is still never prepared and never authorized, and tests/integration/test_set_engine_row_policy_serialized_plan passes, including the assertion that inIgnoreSet over a Set table succeeds for a user for whom the plain IN spelling is denied by a row policy. Co-Authored-By: Claude Opus 5 <[email protected]> (cherry picked from commit 19d4854 of #122130)
…r to a shard tryBuildAdditionalFilterAST (src/Processors/QueryPlan/ReadFromRemote.cpp) rebuilds a pushed-down filter as an AST out of the plan's expression DAG, and it assumes the two-child shape for every IN-family function name. The previous commit leaves an IgnoreSet call with its left operand alone, which breaks that assumption in two independent ways. The four global variants are covered by isNameOfGlobalInFunction (src/Analyzer/Utils.cpp), so the GLOBAL IN block reaches node->children.at(1) on a one-child node. std::out_of_range derives from std::logic_error, so src/Common/Exception.cpp aborts the whole server process on a debug or sanitizer build, and on any build where abort_on_logical_error is set (observed: exit 134, stack through tryBuildAdditionalFilterAST); a release build without that flag reports it as query error Code: 1001 instead. Either way a query whose filter is pushed to a shard fails. Before the previous commit this site was safe only incidentally, because the second child existed, its FutureSetPtr was null, typeid_cast of a null pointer gave null, and the set_from_subquery guard skipped the block. The four local variants reach makeASTFunction with arguments built from node->children, so the predicate is written back as one-argument SQL such as HAVING inIgnoreSet(x). The receiving shard resolves that text and src/Analyzer/Resolve/resolveFunction.cpp throws NUMBER_OF_ARGUMENTS_DOESNT_MATCH for any isNameOfInFunction name, so the distributed query fails. Declare such a node non-convertible to AST instead, which is the mechanism this function already uses for lambdas and for captures three lines above: node_to_ast[node] = nullptr. Its existing handling then applies unchanged. The parent's has_all_args goes false; an enclosing and() whose polarity is known positive drops just that child, which is the invariant the function was hardened for in #113445; and if the whole predicate is the IgnoreSet call the function returns nullptr and addFilters adds no filter. This is sound because the AST is only a pushdown optimization: omitting a conjunct can only widen what the shard returns, the initiator still applies the whole filter, and an IgnoreSet call evaluates to 0 for every row anyway, so no pruning is lost even in principle. The bail sits in the single argument walk that all three addFilters call sites funnel through, so it covers the plain, the external-tables GLOBAL and the parallel-replicas paths at once. It fires only when isNameOfInFunction accepts the name and the name ends with IgnoreSet. isNameOfInFunction accepts sixteen names, of which exactly eight end that way, so the walk is byte-identical in behaviour for every DAG that contains no IgnoreSet call. The regression test gains the remote arms, a plan-shape assertion that is true only when the call has a single operand, a wrapper-type matrix whose output is byte-identical to pristine master, an assertion that a filter mixing a convertible conjunct with an IgnoreSet call still pushes the convertible one to the shard, and a paired serialize_query_plan round trip over wrapped operands. Co-Authored-By: Claude Opus 5 <[email protected]> (cherry picked from commit 64f2f5b of #122130)
Closes: #122042
Related: #120312
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not required: the crash was introduced on master by #120312 and has never been in a released version.
Description
inIgnoreSetand its seven siblings never read their right operand, returning 0 (NULL for anull-skipping variant over a NULL operand); they exist to resolve types without building a set. Since #120312 the planner no longer registers a
set for them but still materializes a set operand, so that
ActionsDAGcolumn holds a nullpointer, which anything walking the plan then dereferences:
ActionsDAG.cpp:4744(STID 2060-5018);VirtualColumnUtils.cpp:84(STID 4168-5979, Server crashes with SIGSEGV oninIgnoreSetin a WHERE/PREWHERE filter #122042).Both crash on current master, no special settings, no sanitizer:
Fix: do not build that operand, so an
IgnoreSetcall takes its left operand alone, the shape theold analyzer already used (
ActionsVisitor.cpp) and the reasonFunctionInis variadic (in.cpp).The result type is unchanged, because
getReturnTypealready counts aSetargument as constant.One consumer reads that operand, so it is taught the new shape instead of guarded:
tryBuildAdditionalFilterASTrebuilds a shard-pushed filter as SQL text from the DAG'schildren, so an
IgnoreSetcall is now declared non-convertible there, as lambdas already are.Dropping that conjunct only widens what a shard returns.
#120312's access control is unaffected: neither
PreparedSetslookup is reinstated, so the rightside is never prepared or authorized (
test_set_engine_row_policy_serialized_planpasses).The stateless test covers all eight variants, a lambda,
EXPLAIN,PREWHERE, virtual-column andremote-pushdown filters, wrapper types and plain-
INcontrols; red on master, green after.Provenance: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=596f844fb392010d96a8a235a3275a002ee7ca38&name_0=MasterCI
Workflow [PR]
Sync PR [sync-upstream/pr/122130]