Repository navigation
Fix header column order after the no-rescoring vector search rewrite - #114457
Conversation
The second-pass vector search optimization (`vector_search_with_rescoring = 0`) removed the distance function from the `ExpressionStep` outputs and re-appended the rewritten `_distance` alias at the end, changing the header column order. Steps created above the `Sorting` before the rewrite runs - the local top-N `Limit` and the exchange steps of a distributed plan - kept the original order, and `makeDistributedPlan` failed to rebuild the plan fragments with a logical error: "Cannot add step Limit to QueryPlan because it has incompatible header with root step Sorting". Reinsert the rewritten output at the original position instead. Found by AST fuzzer: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=42701&sha=019244e0d46b4d9029fc261a549e1c5cd79b1bbb&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29 #42701 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [f1447bf] Summary: ✅
AI ReviewSummaryThis PR now covers the original header-order mismatch in the no-rescoring vector-search rewrite plus the follow-up carrier edge cases around filters, row policies, deferred Final Verdict
LLVM Coverage ReportMeasured on commit f1447bf.
Changed lines: Changed C/C++ lines covered: 32/39 (82.05%) · Uncovered code |
The stateless test runner randomizes `max_rows_to_group_by`, and `make_distributed_plan` rejects aggregation with a global GROUP BY limit with a `SUPPORT_IS_DISABLED` exception. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114457&sha=ed4ee925ea364194dfbc190845139c3759a7379f&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29 #114457 Co-Authored-By: Claude Fable 5 <[email protected]>
…sumes the vector column The bailout only checked whether the vector column itself (or an alias of it) is an output of the expression under the `Sorting` step. An output consuming the column indirectly kept its INPUT node alive while `replaceVectorColumnWithDistanceColumn` removed the column from the read header. The reachable case is a filter condition over the vector column, e.g. `WHERE length(vec) = 2 ... ORDER BY L2Distance(vec, ...) LIMIT 3` with `vector_search_with_rescoring = 0` failed with `NOT_FOUND_COLUMN_IN_BLOCK` under both analyzers, because the rewrite removed only the vector column output from the filter DAG. Make the bailout dependency-based: skip the optimization if any output other than the ORDER BY distance expression transitively consumes the vector column INPUT, in both the pre-sort expression DAG and the filter/PREWHERE DAG. Co-Authored-By: Claude Fable 5 <[email protected]>
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, 39 s compile time in total, 8 of them have a recent master baseline. |
|
🕵 Merged The only red on the previous run was |
|
🕵 Fixed the private sync regression in https://github.com/ClickHouse/clickhouse-private/pull/68602: worker reads now serialize the rewritten column list, so |
|
📊 Cloud Performance Report ✅ AI verdict: No query shows a performance change that can be attributed to this PR. Only clickbench Q34 was flagged: its median went from 1256 ms to 1175 ms (-6.4%), which is inside master's current range of 1093-1370 ms, so it was correctly treated as no change. The diff only touches the no-rescoring vector-search rewrite and how row-level filters are handled under it, plus copying deferred row-policy filters when a read step is cloned. None of the ClickBench or TPC-H queries use vector search, row policies or FINAL, so these benchmarks don't run that code. The result fits a correctness fix with no performance cost on these workloads. clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Keep the search column in the read header when a row-level filter DAG consumes it, and cover the no-rescoring path with a row policy regression test.\n\nhttps://github.com//pull/114457
…ctor search column `findSearchColumnInput` accepted any input whose name ends in `.` plus the unqualified search column name. For a table that has an indexed column `vec` next to a `Nested` column `n` with an element `vec` (a physical column literally named `n.vec`), a filter or row policy over `n.vec` was mistaken for a consumer of `vec`, so `vector_search_with_rescoring = 0` silently fell back to rescoring even when only the `ORDER BY` used the real vector column. Resolve the input the same way `optimizeVectorSearchWithQuantizedCodes` does for dotted names: an exact match always wins, and the fallback strips only a single leading table qualifier and skips a candidate that is itself a physical column of the table. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…umn's leaf name `05230_vector_search_no_rescoring_dotted_column_name` covers the case the review pointed at: a table with an indexed `vec` next to a `Nested` column `n`, whose element is the physical column `n.vec`. A filter `has(n.vec, [9.])` must not be taken for a consumer of `vec`, so the no-rescoring rewrite has to stay applied. Proved with a control binary carrying the previous suffix match: the plan-shape assertion counts `0` instead of `1` there, so the test really fails without the fix. `length(n.vec)` is not usable for this - it is rewritten to the `.size0` subcolumn, whose name does not end in `.vec`. The test also keeps a negative case: a filter over `vec` itself must still disable the rewrite. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ger exists Since v26.9 the server rejects `enable_analyzer = 0` with `SETTING_CONSTRAINT_VIOLATION`, so after merging `master` the old-analyzer queries in `04871_vector_search_no_rescoring_vector_column_consumers` and `04907_vector_search_no_rescoring_row_policy` fail. Remove them together with the now-pointless `no-old-analyzer` tag of `04907`; the remaining queries cover the same carriers through the analyzer. Also reword the comment on `findSearchColumnInput`, which referred to the old analyzer as the producer of a table-qualified input name. The fallback that strips a single qualifier is kept, because it is safe in both directions: a missed consumer would turn into `NOT_FOUND_COLUMN_IN_BLOCK` at runtime. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 Merged
Verified against a server built from this branch: |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=114457&sha=1dbd13b5e3beeecface74459274393e84fe17995&name_0=PR&name_1=Stress%20test%20%28amd_msan%29 ( |
|
Investigated. The aborting query is |
…eader-order Conflict in `useVectorSearch.cpp`: master independently added exact-match bailouts for the projection, filter and row-policy consumers of the vector column (`is_search_column`, pruned DAG copies). They cover the same cases as this PR's `findSearchColumnInput` / `anyOutputConsumesInput` guards, so master's version is kept and the PR's duplicate guards and helpers are dropped. The PR's header-order fix, deferred PREWHERE bailout and `ReadFromMergeTree` changes are kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged Conflict resolution in Verified on a local build: |
…passthrough in `05153` Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=114457&sha=8de6dffdae69fbc7088271f9af08e344f2932a5f&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%201%2F2%29 ( |
|
The fix is in progress: #123790 (it includes the change from my #123774, closed in its favor). In its own run on The failure on |
|
🕵 Thanks @groeneai. The |
The second-pass vector search optimization (
vector_search_with_rescoring = 0) removed the distance function from theExpressionStepoutputs and re-appended the rewritten_distancealias at the end, changing the header column order. Steps created above theSortingbefore that rewrite runs — the local top-NLimitand the exchange steps of a distributed plan — kept the original column order, andmakeDistributedPlanfailed to rebuild the plan fragments with a logical error:Cannot add step Limit to QueryPlan because it has incompatible header with root step Sorting. Non-distributed plans never re-validate step headers after optimization, which is why this only surfaced withmake_distributed_plan = 1.The fix reinserts the rewritten output node at the original position of the distance column, so the header column order is preserved and all previously created parent steps stay consistent.
Found by AST fuzzer on #42701 (report); the same signature also hit the unrelated #98789 on 2026-08-08.
The regression test asserts only the row count: the distributed plan currently returns an incorrect top-N for vector search queries regardless of the rescoring mode — a separate, pre-existing bug.
Related: #114456
Related: #42701
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a logical error
Cannot add step Limit to QueryPlan because it has incompatible header with root step Sortingwhen a vector search query withvector_search_with_rescoring = 0was executed with the experimentalmake_distributed_plansetting.Workflow [PR]
Sync PR [sync-upstream/pr/114457]
Version info
26.10.1.1642-master(included in26.10and later)