Repository navigation
Minor text index refactoring extracted from the BM25 PR - #124595
Conversation
Extracted from ClickHouse#117519, which builds BM25 scoring on top of it. Mechanical changes: - Rename `MergeTreeIndexTextPostingListCursor.{h,cpp}` to `PostingListCursor.{h,cpp}` and `FlatPostingsPtr` to `PaddedPODArrayPtr`, defined in `IPostingListCodec.h`. - Replace `MergeTreeIndexTextParams::positions` with the bool `enable_positions`. - Replace the `skip_postings` arguments of `deserializeTokenInfo` and `deserializeDictionaryBlock` with `with_postings` without a default, and `MergeTreeIndexDeserializationState::skip_postings_deserialization` with `text_index_read_postings`. - Make `loadHeader` and `matchTokens` free functions, extract `makeIndexIdForCaches`, `skipVarUInts` and `readVarUInts`, and make `serializeTokensAndPostings` a plain function. - Take `std::span<const uint32_t>` in the posting list block codecs. - Capture the index in the condition factory of the vector similarity index instead of a raw pointer to it. - Remove the unused `IndexReadTask::is_final`. Keep the search queries of the virtual columns of a text index in `IndexReadTask` instead of the condition: `MergeTreeIndexConditionText` is no longer modified after construction. `replaceToVirtualColumn` becomes the const `tryGetVirtualColumnName`, `getSearchQueryForVirtualColumn` is removed, and `MergeTreeReaderTextIndex` and `optimizeTrivialCountFromTextIndex` take the queries from the read task, which `createMergeTreeReaderIndex` now receives whole. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A part may hold a substream of a skip index that the current definition does not write, e.g. the `.pos` of a text index created with `support_phrase_search = 1` and redefined without it while the part was detached. `getAllSubstreamsInPart` probed only `getSubstreams`, so a mutation that rebuilds the index did not see the stale `.pos` and hardlinked it into the new part. It now probes `getPotentialSubstreams`, which also covers the legacy minmax `.idx`, so the override of `MergeTreeIndexMinMax` is removed and the function is no longer virtual. Extracted from ClickHouse#117519. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [7828b0d] Summary: ❌
AI ReviewSummaryThis PR extracts text-index refactoring from the Missing context / blind spots
Final Verdict✅ No new inline findings for the current PR revision. |
`IndexReadTask` and `IndexReadColumns` kept the search query of each virtual column in a separate map keyed by column name, so `createReadTasksForTextIndex` and the text index reader had to join them back and throw a `LOGICAL_ERROR` when the lookup failed. Replace both with a single `IndexReadTask::Column` that holds the name, type, search query and default expression. `createReadTasksForTextIndex` now builds the `VirtualColumnDescription` from it, so the read tasks, which are copied for every part, do not carry a `ColumnDescription` that clones its ASTs on copy. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`hasAnyIndexFileOnDisk` and the orphan collector in `updateIndicesToRecalculateAndDrop` walked `getSubstreams`, so a checksum-less `.pos` of a text index redefined without `support_phrase_search` stayed invisible and was hardlinked into the mutated part. Walk `getPotentialSubstreams` instead; it also covers minmax's legacy `.idx`, so the hand-coded `.idx2` -> `.idx` probe is removed. ClickHouse#124595 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
`TextIndexDAGReplacer` carried the same virtual column information through four structs: `SelectedCondition`, `AddedVirtualColumn`, `NodeReplacement` and `ResultReplacement`. `SelectedCondition` now holds an `IndexReadTask::Column` instead of a separate search query and column name, so adding the virtual column only sets its default expression. Added columns go straight into an `IndexReadColumns` member, pruned by `replace` after `removeUnusedActions`, which removes `AddedVirtualColumn`. The rewrite functions return the replacement node and the virtual column input cache is a member, which removes `NodeReplacement`. `replace` returns `std::optional<ResultReplacement>` instead of the `is_dag_rewritten` flag. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`TextIndexDAGReplacer` already knows the analyzed index of every virtual column it adds, so it now collects `IndexReadTasks` instead of the intermediate `IndexReadColumns` map. `createReadTasksForTextIndex` takes the tasks as is and no longer looks the indexes up by name. Also add `IndexReadTask::getNamesAndTypesList` and minor cleanups of comments and formatting. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…er_redefinition` On a case-insensitive filesystem (the macOS fast test runner) `replaceFileNameToHashIfNeeded` stores every stream of a part under the hash of its name, so the `skp_idx_idx.pos.*` glob matched nothing and the test failed on `cp`. Probe the plain name and then the hashed one. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124595&sha=80456c877d038e80ca9a4d1d25f3e9ca285073a1&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29 ClickHouse#124595 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`createReadTasksForTextIndex` added an `IndexReadTask` without columns for every useful text index that is not read directly. The tasks used to keep such indexes out of `MergeTreeSkipIndexReader`, but that exclusion was removed in ClickHouse#102255, and a task without columns never gets a `MergeTreeReaderTextIndex`, because read steps are matched to tasks by column names. The only remaining effect was an empty PREWHERE read step per such index. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
| /// Mapping from virtual column (optimized for direct read from text index) to search query. | ||
| std::unordered_map<String, TextSearchQueryPtr> virtual_column_to_search_query; |
There was a problem hiding this comment.
The main point of refactoring: avoid filling shared fields after creation of MergeTreeIndexConditionText. Currently, it works by accident, but breaks with BM25 scoring.
| struct ResultReplacement | ||
| { | ||
| IndexReadColumns added_columns; | ||
| IndexReadTasks index_read_tasks; |
There was a problem hiding this comment.
Just reducing the number of temporary structs. It makes the code more neat.
| /// index this same mutation drops, so it is absent from the post-drop metadata. | ||
| const String file_name = index_ptr->getFileName(); | ||
| for (const auto & index_substream : index_ptr->getSubstreams()) | ||
| for (const auto & index_substream : index_ptr->getPotentialSubstreams()) |
There was a problem hiding this comment.
A fix for the corner case with chain DETACH PART -> DROP INDEX -> ADD INDEX -> ATTACH PART, when the index holds substreams incompatible with the actual index definition and is not being rebuilt during mutations.
The test copied the positions substream files into a part directory by hand to reproduce a part left by the ClickHouse#109595 bug. Stateless tests should not modify the filesystem of a part. The reachable case is covered by `05343_text_index_stale_positions_after_redefinition`, and `getPotentialSubstreams` by `gtest_index_potential_substreams`. ClickHouse#124595 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…oring-for-bm25 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Storages/MergeTree/PostingListCursor.cpp.o |
new | 258.61 KiB | +258.61 KiB |
src/CMakeFiles/dbms.dir/Processors/QueryPlan/Optimizations/optimizeDirectReadFromTextIndex.cpp.o |
487.05 KiB | 462.11 KiB | -24.94 KiB (-5.12%) |
720 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
297 translation units recompiled, 2948 s compile time in total, 296 of them have a recent master baseline.
Translation units without a recent master baseline:
src/Storages/MergeTree/PostingListCursor.cpp: 7.1 s
|
Unrelated failures:
|
1b9d291
Resolve conflicts with ClickHouse#124595 and adapt the BM25 code to its refactoring: `IndexReadTask` keeps the search query in `IndexReadTask::Column`, `TextIndexDAGReplacer` builds `IndexReadTasks` directly (including the score columns), and `createReadTasksForTextIndex` takes the tasks. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Related: #117519
The changes of #117519 that do not depend on BM25 scoring, so that PR gets smaller.
Changelog category (leave one):
Workflow [PR]
Sync PR [sync-upstream/pr/124595]
Version info
26.10.1.2125-master(included in26.10and later)