Repository navigation
Conversation
The text index direct-read path registers virtual columns against the unsubstituted condition at plan time (the virtual column name embeds the unsubstituted search-query hash) and the reader looks them up via generateUnsubstituted(). With use_constant_folding_in_index_analysis and the indexed column also being the partition key, the granule analyzer was instead built from the per-partition constant-folded condition, whose search queries hash differently. The reader then failed to find the query builder and threw LOGICAL_ERROR "Query builder not found for text search query with function". Keep constant folding off for text index condition templates so the granule analyzer and the reader use the same (unsubstituted) set of search queries. Found by the AST fuzzer (STID 3694-54bc). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-2:20260717-004400 |
|
cc @CurtizJ @ahmadov — could you review this? The text index direct-read path registers virtual columns against the unsubstituted condition but the granule analyzer was built from the per-partition constant-folded condition when |
|
Workflow [PR], commit [74a672d] Summary: ❌
AI ReviewSummaryThis PR fixes the Findings
Final VerdictChanges requested. |
Only skip per-partition constant folding for a text index when its condition actually contains a non-None direct-read query, i.e. one that emits a direct-read virtual column looked up by the reader via generateUnsubstituted(). None-mode conditions (match, multiSearchAny*, multiMatchAny, hasAny on non-array tokenizers, LIKE with query_plan_text_index_add_hint = 0) are dropped before the virtual-column rewrite and never looked up, so they keep their per-partition constant-folding specialization. Pin query_plan_direct_read_from_text_index and query_plan_text_index_add_hint in the regression test so CI randomization cannot route the query away from the virtual-column lookup path that this fix targets. Co-Authored-By: Claude Opus 4.8 <[email protected]>
| [](const auto & entry) { return entry.second->getDirectReadMode() != TextIndexDirectReadMode::None; }); | ||
|
|
||
| if (has_direct_read_query) | ||
| condition_template = std::make_shared<ConditionTemplate<MergeTreeIndexConditionPtr>>( |
There was a problem hiding this comment.
getDirectReadMode() != TextIndexDirectReadMode::None is still broader than the path that needs the hash-stable unsubstituted condition here. getDirectReadMode() depends only on the function/index shape; it does not check the global query_plan_direct_read_from_text_index switch, while processAndOptimizeTextIndexFunctions only emits the reader-backed virtual columns when that optimization setting is on. With SET query_plan_direct_read_from_text_index = 0, this branch still rebuilds the template with skip_folding = true, so generateForPartition stops specializing partition-key text-index predicates (LIKE, hasToken, hasPhrase, etc.) even though nothing will ever look them up via generateUnsubstituted().
Can we gate this on the direct-read plan setting as well (or otherwise on whether a virtual column will actually be emitted), and add a regression test for the query_plan_direct_read_from_text_index = 0 case?
CI finish ledger — cdb195fEvery failure below has an owner: a fixing PR. None is PR-caused (this PR only touches the text-index constant-folding guard and its regression test).
Session id: cron:our-pr-ci-monitor:20260717-143000 |
CI finish ledger — cdb195fCI fully finished on this head (Finish Workflow SUCCESS). All failures owned; none PR-caused (all unrelated to the text-index constant-folding fix).
Session id: cron:our-pr-ci-monitor:20260718-033000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 15/15 (100.00%) · Uncovered code |
CI finish ledger — 74a672dEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The Neither family is caused by this PR's diff (a text-index constant-folding fix plus its stateless Session id: cron:our-pr-ci-monitor:20260729-060000 |
|
Introduced by #104582, doesn't reproduce with the default settings. |
|
Right, it needs |
Related: #104582
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a
LOGICAL_ERROR("Query builder not found for text search query with function") when a query filters a column that has atextindex and is also the partition key, with the settinguse_constant_folding_in_index_analysisenabled.Description
Introduced in 26.7 by #104582. It needs
use_constant_folding_in_index_analysis = 1(default 0); with it, the query in the test fails on 26.9.19.9 withQuery builder not found for text search query with function 'like' (LOGICAL_ERROR).The text index direct-read path registers its virtual columns against the unsubstituted condition at plan time (the virtual column name embeds the unsubstituted search-query hash), and the reader looks them up via
generateUnsubstituted(). Whenuse_constant_folding_in_index_analysisis on and the text-indexed column is also the partition key, the granule analyzer was built from the per-partition constant-folded condition instead, whose search queries hash differently. The reader could not find the query builder and threw the logical error (server abort in debug/sanitizer builds).The fix keeps constant folding off for
textindex conditions that contain a direct-read search query, so the granule analyzer and the reader use the same unsubstituted set of search queries. Other index types are unaffected.Found by the AST fuzzer (STID 3694-54bc), report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100173&sha=e196b05a52cdcdcdf80b1f6c6a41071b5deec053&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29