Repository navigation
Register prepared sets before expanding ALIAS columns of Merge child tables - #113757
PedroTadim merged 1 commit into
Conversation
…tables Reading through a `Merge` table aborted the server with `Logical error: No set is registered for key __set_...` when a child table declared an `ALIAS` column whose expression contains `IN`, and the children disagreed about that column's default. `StorageMerge::getColumnsDescriptionFromSourceTablesImpl` clears the default on such a disagreement, so the Merge-level column looks physical and is requested from every child. The child still declares it as `ALIAS`, so `ReadFromMerge::getModifiedQueryInfo` expands it and builds actions for the expression with a `PlannerActionsVisitor`. That visitor resolves `IN` through `PlannerContext::getPreparedSets`, but the context it is given was derived a few lines earlier and its constructor copies only `query_context`, `global_planner_context` and `is_ast_level_optimization_allowed`. `prepared_sets` is a member of the derived context, so the registry is empty and the lookup misses. In a debug or sanitizer build `Exception::handleErrorCode` aborts at throw time, so the call has to be avoided rather than guarded. `collectSets` is what registers those sets, and two existing call sites do exactly this before visiting: `Planner/Utils.cpp` for row policies and additional table filters, and `CollectTableExpressionData.cpp` for the same ALIAS expansion pattern, whose header comment states the rule. Call it before both visitor sites in `StorageMerge.cpp`. It is idempotent, so registering a set that is already present is a no-op. The second site, `convertAndFilterSourceStream`, is reached when a child table hits the query info cache: that path skips `getModifiedQueryInfo` entirely, restores the aliases from the cache and builds another empty planner context. Reverting only that call makes the new test's `query info cache` case abort in `convertAndFilterSourceStream`, while the other cases stay green. Two right-hand sides are reachable through a `Merge` table here and both are covered: a constant tuple, and a `Set` table whose registry key carries no element types, which is why a constant-tuple-only fix would be incomplete. A subquery cannot occur, because an `ALIAS` expression containing one is rejected at DDL time with `Code: 116`. A bare table identifier registers a set that nothing outside a SELECT pipeline fills, and it already aborts the same way without any `Merge` table, so it is left alone. Closes ClickHouse#113712
Internal second-model reviewTwo independent review passes over this change: a cold read of the resulting code, and a separate
Test liveness was checked rather than assumed. Reverting either of the two calls reddens only the |
Pre-PR validation (a-i)Every
Mutation matrix, each arm built and run with its Build ID asserted:
The second mutant is what shows the second site is real rather than defensive. After the matrix the restored tree rebuilt to the shipping Build ID byte for byte. |
|
cc @azat @vdimir, could you review this? Reading through a |
|
Workflow [PR], commit [4e4dd39] Summary: ✅
AI ReviewSummaryThis PR fixes the analyzer-only Final Verdict✅ No blocking or major findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 11/11 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units12 translation units recompiled, 76 s compile time in total, 12 of them have a recent master baseline. |
Backport #113757 to 26.7: Register prepared sets before expanding ALIAS columns of Merge child tables
Backport #113757 to 26.5: Register prepared sets before expanding ALIAS columns of Merge child tables
Backport #113757 to 26.6: Register prepared sets before expanding ALIAS columns of Merge child tables
…anding ALIAS columns of Merge child tables
…anding ALIAS columns of Merge child tables
Closes: #113712
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
Logical error: No set is registered for key ...when reading through aMergetable whose child declares anALIAScolumn containingIN, and the children disagree about that column's default.Description
Reproducer, which aborts the server on master:
getColumnsDescriptionFromSourceTablesImplclears a column's default when children disagree about it, so the Merge-levelxlooks physical and is requested from every child.t2still declares it asALIAS, soReadFromMerge::getModifiedQueryInfoexpands it and builds actions with aPlannerActionsVisitor. That visitor resolvesINthroughPlannerContext::getPreparedSets, but its context was derived a few lines earlier and the deriving constructor does not copyprepared_sets, so the registry is empty and the lookup misses. SinceLOGICAL_ERRORaborts at throw time under a sanitizer, the call has to be avoided rather than guarded.The fix calls
collectSetsbefore building the actions, as two existing sites already do here:Planner/Utils.cppfor row policies, andCollectTableExpressionData.cppfor the same ALIAS expansion pattern. It is idempotent. The reachable right-hand sides here are a constant tuple and aSettable, and both now resolve; theSettable reaches the same lookup through a different branch. A subquery is rejected at DDL time, and a plain table already fails identically without aMergetable, so it is untouched.convertAndFilterSourceStreamneeds the same call, being reached when a child hits the query info cache, which skipsgetModifiedQueryInfoand builds another empty context. The issue'sLIMIT -326, 33 FORMAT ORCis incidental; a plainSELECT *aborts.Validation: the new test fails on master and passes with the fix, through
clickhouse-test, 100/100 runs (50 randomized, 50 with randomization off). Reverting either call reddens only the cases reaching that site. A 437-test slice overmerge()andALIAScolumns has an identical failure set on both arms.Version info
26.8.1.951(included in26.8and later)26.7.5.7,26.6.4.6,26.5.8.8