Skip to content

Fix vector search with arrayJoin below the sort and with a row policy - #114074

Merged
alexey-milovidov merged 41 commits into
masterfrom
vector-search-array-join-row-policy
Oct 2, 2026
Merged

alexey-milovidov merged 41 commits into
masterfrom
vector-search-array-join-row-policy

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 9, 2026 •

Copy link
Copy Markdown
Member

Fixes for the vector search ORDER BY <distance> LIMIT optimization.

arrayJoin below the sort. arrayJoin changes the number of rows - an empty array drops its base row - so the rewrite must not shortlist base rows before it runs. optimizeTopK rejects arrayJoin for this reason (#82279), but the vector search optimization did not, so the rows that a later base row would have contributed were never produced:

CREATE TABLE t (id UInt32, tags Array(UInt32), vec Array(Float32),
    INDEX idx vec TYPE vector_similarity('hnsw', 'cosineDistance', 2))
ENGINE = MergeTree ORDER BY id SETTINGS index_granularity = 4;

INSERT INTO t SELECT number, if(number < 16, [], [number]), [toFloat32(number), toFloat32(number + 1)]
FROM numbers(64);

SELECT arrayJoin(tags) FROM t ORDER BY cosineDistance(vec, [0., 1.]) LIMIT 1;
-- returned nothing; with `use_skip_indexes = 0` it returns 16

A row policy is an additional filter. A row policy restricts rows inside the reader just like a WHERE or a PREWHERE, but it did not participate in additional_filters_present, so a query filtered only by a policy was treated as unfiltered: the vector_search_filter_strategy = 'prefilter' bailout was skipped, so an explicit request for exact search was ignored, and the index fetched only LIMIT neighbours without the vector_search_index_fetch_multiplier compensation, which the policy can then discard.

Filters that read the vector column broke the non-rescoring rewrite (found during review). The rewrite drops the physical vector column from the read list and replaces it with the virtual _distance column, so any filter that still needs the column was left without its input and the query failed with NOT_FOUND_COLUMN_IN_BLOCK (an exception, pre-existing on master). The rewrite is now skipped - the same treatment as the vector column in SELECT - when the column is read by:

  • a row policy (including a policy carried in the deferred filter under FINAL with apply_row_policy_after_final),
  • a plain WHERE filter below the sort, e.g. WHERE length(vec) > 0 (reachable with default settings, because the implicit PREWHERE optimization is disabled for vector-search candidates).

The quantized-codes rewrite (useVectorSearchWithQuantizedCodes) is not affected by these problems: it splices the shortlist above the whole Expression/Filter chain, so the expansion and the filters run below it, and its reader-side filters prefilter the approximate ranking. This was checked with the same queries.

Dotted vector column names. The search column name taken from ORDER BY is unqualified whenever the distance function reads the INPUT node directly, while the plan's DAG nodes carry the table qualifier (__table1.vec), so the bailouts above had to recognize both forms. Matching by suffix was too broad - an unrelated dotted column n.vec was conflated with a search column named vec and needlessly disabled the rewrite - so the exact DAG input name is now recovered from the distance function's argument and compared exactly. The index lookup had the mirror-image problem, pre-existing on master: it stripped everything before the first dot, so a genuinely dotted storage column n.vec collapsed to vec and could bind to the index of an unrelated column. It now peels the leading component only when it is a proven table qualifier: the full name is not a storage column, but the remainder is. useVectorSearchWithQuantizedCodes.cpp had the same problem: a dotted n.values.id without the Quantized codec was shortlisted on values.id.quantized. It now resolves the name with the same rule.

FINAL with an explicit PREWHERE is covered by a separate regression test. FINAL can defer a PREWHERE until after the merge, but the deferral copies the filter and clears query_info.prewhere_info only when the pipeline is built, i.e. past every query plan optimization, so the existing getPrewhereInfo bailout still fires and the physical vector column survives for the deferred filter.

Related: #82279
Related: #110188

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed vector search returning too few rows for a query with arrayJoin below ORDER BY <distance> LIMIT. A row policy now counts as an additional filter for vector search, so vector_search_filter_strategy = 'prefilter' is honored and the index fetch multiplier is applied for a query filtered by a row policy. Fixed NOT_FOUND_COLUMN_IN_BLOCK for a non-rescoring vector search query when a WHERE filter or a row policy reads the vector column.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Workflow [PR]
Sync PR [sync-upstream/pr/114074]

Version info

  • Merged into: 26.10.1.1249-master (included in 26.10 and later)

`arrayJoin` changes the number of rows: an empty array drops its base
row. Vector search shortlists a few base rows through the index and
feeds only those to the expression below the sort, so the rows a later
base row would have contributed were never produced and the query
returned fewer rows than the `LIMIT`. `optimizeTopK` already rejects
`arrayJoin` for the same reason.

A row policy restricts rows inside the reader just like a `WHERE` or a
`PREWHERE`, so it must count as an additional filter. It did not, so a
query filtered only by a policy was treated as unfiltered: the
`vector_search_filter_strategy = 'prefilter'` bailout was skipped, and
the index fetched only `LIMIT` neighbours without the
`vector_search_index_fetch_multiplier` compensation.
@clickhouse-gh

clickhouse-gh Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [825ff84]

Summary: ✅


AI Review

Summary

This PR hardens the vector-search ORDER BY <distance> LIMIT optimizations against row-expanding arrayJoin, reader-side row policies, and dotted vector-column names on both the vector-similarity-index and quantized-codes paths. I reviewed the current head, the full PR diff, and every existing review thread; the remaining code paths match the stated contract, and the new stateless regressions cover the bug families that were found during review. I did not find a remaining correctness, compatibility, or test-coverage issue that warrants a new inline comment.

Final Verdict

✅ Approved. No new inline findings.

LLVM Coverage Report

Measured on commit 825ff84.

Metric Baseline Current Δ
Lines 88.20% 88.10% -0.10%
Functions 91.70% 91.70% +0.00%
Branches 79.40% 79.50% +0.10%

Changed lines: Changed C/C++ lines covered: 115/120 (95.83%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 825ff84bc with master 96757f50c (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 8a0adcace; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 23 s compile time in total, 8 of them have a recent master baseline.

Job report

@shankar-iyer shankar-iyer self-assigned this Aug 10, 2026
alexey-milovidov and others added 3 commits August 11, 2026 00:59
The policy filter runs inside the reader on the read columns, and
`replaceVectorColumnWithDistanceColumn` removed the physical vector
column from the read list, leaving the policy without its input:
a query such as `SELECT id FROM t ORDER BY cosineDistance(vec, ...)
LIMIT 1` with a policy `USING length(vec) > 0` failed with
`NOT_FOUND_COLUMN_IN_BLOCK` on the default
`vector_search_with_rescoring = 0` path. Give it the same treatment
as a `SELECT` clause containing the vector column: skip the rewrite.

Addresses the AI review finding on #114074.

Co-Authored-By: Claude Fable 5 <[email protected]>
With `FINAL` and the default `apply_row_policy_after_final = 1`, a row policy
that is not part of the sorting key is moved into `deferred_row_level_filter`
by `deferFiltersAfterFinalIfNeeded` before the vector-search second pass runs,
so checking only `getRowLevelFilter` missed it and
`replaceVectorColumnWithDistanceColumn` still erased the vector column that
the deferred policy needs, leading to a `NOT_FOUND_COLUMN_IN_BLOCK` exception.
The second pass now inspects `getDeferredRowLevelFilter` as well.

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov and others added 2 commits August 12, 2026 00:36
…ector column

An explicit `PREWHERE` turns the non-rescoring vector-search rewrite off, because
that rewrite drops the physical vector column from the read list in favour of the
virtual `_distance` column. Under `FINAL` the `PREWHERE` can additionally be
deferred until after the final merge, either through `apply_prewhere_after_final`
or behind a row policy over a non-sorting-key column.

Deferring copies the filter into `deferred_prewhere_info` and keeps
`query_info.prewhere_info` in place until the pipeline is built, i.e. past every
query plan optimization, so the `getPrewhereInfo` bailout still fires and the
vector column survives for the deferred filter. Pin that: the queries return the
nearest row and the plan keeps reading `vec`, with a control query without
`PREWHERE` proving the plan check is not vacuous.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`deferFiltersAfterFinalIfNeeded` copies `query_info.row_level_filter` into
`deferred_row_level_filter`; it does not move it. `query_info.row_level_filter`
is cleared in `ReadFromMergeTree::initializePipeline`, i.e. after every query
plan optimization has run, so at the time of the vector-search second pass both
carriers hold the policy and either one alone would trigger the guard. Both are
still checked so that the guard does not depend on that ordering, but the
comment should not claim the policy has already moved.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
alexey-milovidov and others added 3 commits August 12, 2026 08:34
… column

A plain `WHERE` filter below the sort that reads the search column (e.g.
`WHERE length(vec) > 0`) reached the non-rescoring rewrite:
`replaceVectorColumnWithDistanceColumn` dropped the vector column from the
read list, and the `FilterStep` was rebuilt on top of the new reader header
while its predicate still needed the column, failing with
`NOT_FOUND_COLUMN_IN_BLOCK`. Reachable with default settings, because the
implicit `PREWHERE` optimization is disabled for vector-search candidates.

The bailout now prunes a copy of the filter step's DAG the same way the
rebuild does and skips the optimized-plan rewrite if the search column
survives among the required inputs - the same treatment as the vector column
in `SELECT` and in a row policy. The pruned DAG is reused in the rebuild.

Co-Authored-By: Claude Fable 5 <[email protected]>
…arch test

The control query of `04839_vector_search_final_prewhere` relies on the
non-rescoring rewrite actually happening under `FINAL`, which requires the
vector index to be used. The randomized setting `use_skip_indexes_if_final = 0`
disables the index under `FINAL`, so the rewrite never fires and the control
returned 0. Pin `use_skip_indexes_if_final = 1` (and
`use_skip_indexes_if_final_exact_mode = 0`) against randomization.

CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114074&sha=4cb158477ac3df1c9c8a556cb00fccb02166effa&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29

Co-Authored-By: Claude Fable 5 <[email protected]>
A row policy on a non-key attribute hides the `LIMIT` nearest neighbours, so the
non-rescoring shortlist returns nothing with `vector_search_index_fetch_multiplier = 1`
and the next visible rows once the multiplier is raised. Without the fix (the row
policy not counted in `additional_filters_present`), the multiplier is not applied
and the query returns nothing even with `vector_search_index_fetch_multiplier = 3`
(verified against a pre-fix master binary). The policy must not filter on the primary
key column: such a policy feeds the primary key analysis and is carried in
`PrewhereInfo`, which makes the rewrite fall back to an exact scan that is correct
regardless of the multiplier.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114074&sha=6996e85e7450afd7be2c987661928e4c5eb9abeb&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%201%2F4%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. All 57 failures in the shard are test_storage_rabbitmq tests failing with RuntimeError: Cannot wait RabbitMQ container at cluster.start() — the RabbitMQ container failed to start in the test environment, unrelated to this vector-search PR. I found no open tracking issue for this container-startup failure.

@groeneai

Copy link
Copy Markdown
Collaborator

Your analysis is right, and the fix is already merged: it is your own #114415, which landed 3 hours after this run.

The run is one fixture event, not 57 failures: all 57 rows carry the byte-identical test.py:86 module-setup traceback (uniqExact of the context = 1). In the job log the broker made 83 rabbitmqctl await_startup attempts over 119.7 s, every one exiting 69 with epmd reports: node 'rabbit' not running at all. The decisive detail is in the same shard: test_system_stop.py passed 21/21 against the same image and the same host, so the Erlang node hung in that one container rather than anything being wrong with the image, the host, or your vector-search change.

That is exactly the hang #114415 recovers from. Neither its merge commit 1bdd9e7910c7 nor #114434's fc4699673fdf is in this run's master_commits, so the run predates both. The current head's tested tree carries both (retries=2, the recreate branch, and the RABBITMQ_LOGS bind mount), so a re-run now force-removes the hung container, brings up a fresh one and waits again instead of aborting the module.

On the tracking issue: you are correct that there is no open GitHub issue. I track this signature internally; over 120 days it is 16 whole-module events, and since 2026-07-10 all 9 are on arm_binary, distributed plan, 1/4 against 18,245 OK rabbitmq rows in that lane since your merge. The other half is #114434, which you merged last night: it restores the broker's own rabbit.log to the artifact bundle, which was going to a tmpfs and being discarded on every run, so the one file that would show why epmd never saw the node was never collected. That is diagnostics only, not a fix for the hang. With both in place, the next occurrence should either self-recover or leave the broker log behind, and root-causing the boot failure itself is still open.

No new PR from me here: the recovery is yours and already merged, and this red is unrelated to #114074.

The AI review asked to mirror the `arrayJoin` bailout of the
vector-similarity-index path in `optimizeVectorSearchWithQuantizedCodes`.
It is not needed there: that rewrite splices its shortlist `LimitStep`
*above* the whole Expression/Filter chain, so an `arrayJoin` in a lower
`FilterStep` runs before anything is truncated and the result always
reaches the `LIMIT`. Only an `arrayJoin` in the rescore expression above
the shortlist would be a problem, and that is already rejected by the
`hasArrayJoin` check there.

Verified against a build without any additional guard: with
`vector_search_index_fetch_multiplier = 1` and the four nearest rows
dropped by `arrayJoin`, the query still returns the full `LIMIT`, and the
top-k deviation at multiplier 1 is plain quantization error - a plain
`WHERE id >= 16` on the same data returns the identical set.

Add `04893_vector_search_quantized_codes_array_join` to pin the
invariant: the shortlist limit sits above the filter, the row count
reaches the `LIMIT` at multiplier 1, and a large multiplier reproduces
the exact top-k.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Fixed the deterministic CI failure in 04893_vector_search_quantized_codes_array_join in 38f7e58. The test asserted that approximate quantized-code ranking must equal exact top-k; that is not guaranteed and is unrelated to the arrayJoin safety invariant. The regression now checks the required plan placement and that the result reaches the requested LIMIT at multiplier 1. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114074&sha=f475391df0c1c115c92f97b28df37a03ebd6ff62&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29

@clickhouse-gh

clickhouse-gh Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 39 queries analysed

Release-transition baseline: compared against the most recent available 26.9 masters at or before the trusted base-commit anchor because no 26.10 master baseline exists there.

I downgraded all six flagged ClickBench improvements (Q18, Q23, Q31, Q32, Q33, Q34) to not_sure. This PR only changes the vector-search query plan rewrites (arrayJoin and row-policy guards, and how dotted search-column names are resolved) and adds tests, and none of these queries uses a vector similarity index or a distance ORDER BY. Q32's CPU drop of about 30% shows real work reduction, but it most likely comes from master changes between the v26.9 baseline and the v26.10 PR build. Q33 and Q34 sped up in wall time while CPU time rose slightly. No regressions were flagged, and nothing in tpch_adapted_1_official stood out.

clickbench

⚠️ 6 inconclusive

Flagged queries (6 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 18 not_sure 1101 988 -10.2% <0.0001 aggregation: This GROUP BY query has no vector index or distance ORDER BY, so the vector-search rewrite returns before any changed code runs. The -10.2% cannot come from this PR.
⚠️ 23 not_sure 86 50 -41.9% <0.0001 The query is noisy on master and does not use a vector similarity index, so this PR's changes never run for it. The -41.9% is not attributable to this PR.
⚠️ 31 not_sure 309 277 -10.4% <0.0001 aggregation: This is a GROUP BY/ORDER BY count query with no distance function, so it never reaches the changed vector-search code. The -10.4% did not come from this PR.
⚠️ 32 not_sure 1376 916 -33.5% <0.0001 aggregation: CPU time also dropped about 30%, but this GROUP BY query never runs the changed vector-search code. The work reduction must come from a code difference outside this PR.
⚠️ 33 not_sure 1256 1187 -5.5% <0.0001 aggregation: CPU time rose slightly while wall time fell, so the -5.5% is not backed by less work. The query also never touches the vector-search rewrite.
⚠️ 34 not_sure 1259 1186 -5.8% <0.0001 aggregation: Like Q33, CPU time went up slightly while wall time fell by -5.8%. The query does not reach any vector-search code this PR changes.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 06a3537b-0082-4cb4-9dd8-56bd96817f62
  • MIRAI run: f0328a88-ccb5-4ef4-aed1-f78e15b131b9
  • PR check IDs:
    • clickbench_2645694_1790828333
    • clickbench_2645998_1790828363
    • clickbench_2646111_1790828390
    • tpch_adapted_1_official_2646229_1790828403
    • tpch_adapted_1_official_2646258_1790828404
    • tpch_adapted_1_official_2646428_1790828408

Add `05043_vector_search_dotted_search_column`: a table carrying both `vec`
and a dotted `n.vec`, each with its own vector similarity index. The nearest
neighbour differs between the two columns, so binding the query to the index
of `vec` would be visible in the result. Checked with both analyzers, because
the name extracted from `ORDER BY` is unqualified with the old one.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

@rschu1ze — tagging you on this one as JOIN-related, as requested. Review request sent too.

The dotted-name fallback in `useVectorSearch.cpp` stripped everything
before the first dot whenever the exact vector-index lookup missed. On
the old-analyzer path the extracted name can already be a real storage
column such as `n.values.id`, so `ORDER BY L2Distance(n.values.id, ...)`
could bind the optimization to an indexed `values.id` column and rank
candidates by the wrong vector while the query still sorts by the column
that was written.

Peel the leading component only when it is a proven table qualifier: the
full name is not a column of the table while the remainder is. Otherwise
the optimization bails out and the query falls back to an exact scan.

Regression test `05063_vector_search_multi_dot_column_name`.
`SETTINGS enable_analyzer` cannot be changed inside the `EXPLAIN`
subquery, so the two analyzer variants are selected with a session-level
`SET`. Reference recorded from the fixed binary; with the previous
first-dot truncation the same test returns the neighbours of the
unrelated indexed `values.id` column (ids `0, 1, 2`) instead of the
neighbours of `n.values.id` (ids `63, 62, 61`), on both the analyzer and
the old-analyzer path.
@clickhouse-gh clickhouse-gh Bot added the comp-vector-index Vector similarity index in MergeTree: ANN/HNSW index build/query, usearch integration, vector ind... label Sep 4, 2026
@shankar-iyer

Copy link
Copy Markdown
Member
  • Code changes in useVectorSearch.cpp cover more than arrayJoin and Row policy related. I think the dotted name thing and issue with predicate like length(vec) > 0 can be cut into separate PRs?
  • Rename all new tests to have prefix 02354_vector_search
  • Set enable_quantized_codec in the failing test and rerun CI after refresh to master

alexey-milovidov and others added 2 commits September 11, 2026 10:19
…ily and enable the `Quantized` codec

`shankar-iyer` asked for all new tests of this pull request to carry the
`02354_vector_search` prefix used by the rest of the vector-search tests, so all
nine are renamed accordingly.

`02354_vector_search_quantized_codes_array_join` also failed in `Fast test`
with `Codec Quantized is experimental and not meant to be used in production`:
`allow_experimental_codecs` became obsolete and the codec is now gated behind
`enable_quantized_codec`, which the test now sets.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @shankar-iyer, thanks — points 2 and 3 are done in 703cf683bf9a, and I merged master (4854 commits behind, clean).

  • Test names. All nine new tests now carry the 02354_vector_search prefix: 02354_vector_search_array_join, _row_policy, _final_prewhere, _where_on_vector_column, _quantized_codes_array_join, _select_on_vector_column, _unrelated_dotted_column, _dotted_search_column, _multi_dot_column_name.

  • The failing test. 02354_vector_search_quantized_codes_array_join failed in Fast test with Codec Quantized is experimental and not meant to be used in production: it used allow_experimental_codecs, which has since become obsolete, and the codec is now gated behind enable_quantized_codec. The test sets that instead. On the merged head all nine tests of this pull request pass locally, as do 02354_vector_search_queries, _rescoring, _rescoring_and_prewhere, _lazy_materialization, 04490_vector_search_rescoring_prewhere_eligibility, 05059_vector_search_bug117723 and 05099_vector_search_limit_multiplier_overflow.

  • Splitting the pull request. I looked at whether the dotted-name and length(vec) > 0 parts can be cut out, and they cannot be cut cleanly:

    • The dotted-name handling is not a separate feature — it is a correctness prerequisite of the bailout checks this very pull request introduces. The arrayJoin and row-policy fixes work by scanning the inputs of the filter, prewhere and row-policy DAGs for the search column. Name matching there is exactly what the dotted-name commits fix: the first version broke the pre-existing 04490_vector_search_rescoring_prewhere_eligibility on 16 shards (NOT_FOUND_COLUMN_IN_BLOCK: Not found column __table1.vec), because the name from ORDER BY may arrive qualified (__table1.vec) or plain; the later commits removed the over-broad suffix match that conflated an unrelated n.vec with vec, and the truncation that bound `n.values.id` to an unrelated indexed values.id. Splitting them out would mean landing the arrayJoin/row-policy guards with known wrong-result and NOT_FOUND_COLUMN_IN_BLOCK bugs of their own.
    • The WHERE length(vec) > 0 case is literally the same defect as the row-policy one — the non-rescoring rewrite erases the vector column from the read list while a predicate below the sort still needs it — and it is fixed by the same guard (prune a clone of the filter/prewhere DAG the same way the rebuild does, and bail if the search column survives among the required inputs). Separating it would duplicate that guard across two pull requests touching the same lines.

    So the whole diff is one bug family in the second pass of useVectorSearch.cpp: the non-rescoring rewrite must bail out whenever something below the sort still reads the vector column, and it must identify that column by name correctly. The one part that is genuinely independent is the first-pass arrayJoin rejection, which is ~10 lines. If you would still prefer that split, say so and I will carve the arrayJoin rejection into its own pull request — but I do not think the remaining parts can be separated without shipping the intermediate states as regressions.

alexey-milovidov and others added 3 commits September 24, 2026 15:14
The analyzer is mandatory on `master` now: `SET enable_analyzer = 0` throws
`SETTING_CONSTRAINT_VIOLATION`, so these sections can no longer run.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…odes rewrite

`useVectorSearchWithQuantizedCodes.cpp` stripped the first dotted component of
the search column whenever the codec lookup on the full name failed, so
`ORDER BY L2Distance(`n.values.id`, ...)` on a column without the codec was
shortlisted on `values.id.quantized` when `values.id` carried `Quantized`,
and the exact rescore only saw that wrong shortlist. Resolve the name with the
same rule as `useVectorSearch.cpp`: peel the leading component only when the
full name is not a storage column while the remainder is.

Regression `02354_vector_search_quantized_codes_multi_dot_column_name`: the
pre-fix binary uses the shortlist and returns ids 2, 1, 0 instead of 63, 62, 61.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 1, 2026
Merged via the queue into master with commit 31d9e00 Oct 2, 2026
342 of 343 checks passed
@alexey-milovidov
alexey-milovidov deleted the vector-search-array-join-row-policy branch October 2, 2026 03:41
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-vector-index Vector similarity index in MergeTree: ANN/HNSW index build/query, usearch integration, vector ind... pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants