Fix flaky test 02354_vector_search_rescoring_and_prewhere#101573
Conversation
Pin query_plan_merge_expressions=1 because the vector search query plan optimizer (tryUseVectorSearch) requires a specific plan structure: LimitStep → SortingStep → ExpressionStep → [FilterStep] → ReadFromMergeTree. When query_plan_merge_expressions is randomized to 0, extra unmerged ExpressionSteps appear between SortingStep and ReadFromMergeTree, causing the optimizer to fail pattern matching and silently fall back to brute-force scan. This produces different (brute-force) results instead of index-based results. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
cc @rschu1ze — could you review this? It pins query_plan_merge_expressions=1 in the vector search rescoring test because tryUseVectorSearch() needs merged expression steps to recognize the LimitStep→SortingStep→ExpressionStep→ReadFromMergeTree plan pattern. When expressions aren't merged, the optimizer silently falls back to brute-force scan, producing wrong results. |
|
Workflow [PR], commit [3107817] Summary: ❌
AI ReviewSummaryThis PR stabilizes ClickHouse RulesFinal Verdict
|
a185cdc
The vector search optimizer (tryUseVectorSearch in useVectorSearch.cpp) requires a specific merged expression step sequence in the query plan: LimitStep→SortingStep→ExpressionStep→ReadFromMergeTree. When query_plan_merge_expressions is randomized to 0, expressions are not merged and the optimizer fails to detect the pattern, causing fallback to brute-force scan with different results. Pin query_plan_merge_expressions=1 in 14 vector search tests that depend on index usage. This follows the same fix pattern as PR ClickHouse#101573 which addressed the identical issue in rescoring_and_prewhere. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
What this PR does
Pin
query_plan_merge_expressions = 1to fix a chronic flaky test.Root cause: The vector search query plan optimizer (
tryUseVectorSearchinuseVectorSearch.cpp) requires a specific plan structure:LimitStep → SortingStep → ExpressionStep → [FilterStep] → ReadFromMergeTree. Whenquery_plan_merge_expressionsis randomized to0, extra unmergedExpressionSteps appear betweenSortingStepandReadFromMergeTree, breaking the optimizer's pattern matching. It silently falls back to brute-force scan, producing different (L2Distance-sorted full scan) results instead of HNSW index-based results.Reproduction:
SET query_plan_merge_expressions = 0deterministically triggers the failure — all queries in the test return brute-force results (e.g.,16, 19, 12, 11instead of index-filtered16, 19).CIDB evidence: 34 failures in 30 days — 30 from PR #100874 flaky check (which adds
query_plan_merge_expressionsto the SettingsRandomizer), plus historical hits in PRs #96130, #99181, and 1 master failure.Verification: 50/50 passes with full randomization after the fix.
Version info
26.4.1.520