Repository navigation
Do not pass a text-index virtual column to the on-fly mutation interpreter - #117277
Conversation
…reter A direct read from a text index rewrites the search predicate into a virtual column produced by the index reader (`__text_index_*`). With `apply_mutations_on_fly` and a pending `ALTER DELETE`, that name was included in the column list handed to `AlterConversions::getMutationSteps`, whose `MutationsInterpreter` resolves names against the storage snapshot - so `StorageSnapshot::getColumn` threw `NO_SUCH_COLUMN_IN_TABLE` and no `hasToken`/`hasAnyTokens`/`hasAllTokens` query could run at all until the mutation materialized. Plain `SELECT`s and `count()` alike failed. The mutation steps read the real columns their own expressions need; the index column is produced on top of their output, so it is simply filtered out of that list. Closes: #116832
|
Workflow [PR], commit [feb2372] Summary: ✅
AI ReviewSummaryThis PR fixes the right boundary: the on-fly mutation interpreter should receive the storage columns that a mutation chain may need to read or rewrite, but not the synthetic Final Verdict✅ Approve. No additional issues found in the current diff. LLVM Coverage ReportMeasured on commit feb2372.
Changed lines: Changed C/C++ lines covered: 14/14 (100.00%) · Uncovered code |
|
The strip is stage-agnostic (it happens before A pending on-fly Suggest (a) rewording the description accordingly and (b) adding that spelling to ALTER TABLE t UPDATE c = c + 1 WHERE 1; -- pending, mutations_sync = 0
SELECT c FROM t WHERE hasToken(s, 'tok1'); -- throws NO_SUCH_COLUMN_IN_TABLE before this fixFor the |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
…s name prefix `isTextIndexVirtualColumn` is a test of the `__text_index_` name prefix, which is not reserved: a table may declare a column of its own with such a name, even with no text index at all. Dropping that column from the list handed to `AlterConversions::getMutationSteps` would hide it from `filterMutationCommands`, which would then discard a pending `ALTER UPDATE` of it while the reader still reads the column - answering from stale on-disk values. Take the names from `index_read_tasks` instead, which is where the index reader's columns were synthesized, so only a column that really is produced by the index reader is dropped. The test covers that shadowing column, and also a pending `ALTER UPDATE` of a column in the read set: `DELETE` is not the only trigger, an `UPDATE` kept by `filterMutationCommands` carries the read columns into its stage just the same and threw the identical `NO_SUCH_COLUMN_IN_TABLE` (verified against a binary without the fix). `query_plan_direct_read_from_text_index` is pinned, because the runner randomizes it off in a fraction of the runs, which would silently degrade every arm into a copy of the `query_plan_direct_read_from_text_index = 0` arm. Test renumbered `05077` -> `05059`.
|
🕵 @zlareb1 you are right, and I reproduced it: with a binary built without the fix, a pending Also, following the review of the prefix heuristic, the filter no longer tests the |
ReproducerSET apply_mutations_on_fly = 1; -- default
CREATE TABLE t (id UInt64, s String, INDEX idx s TYPE text(tokenizer = splitByNonAlpha))
ENGINE = MergeTree ORDER BY id;
INSERT INTO t SELECT number, concat('tok', toString(number % 10), ' word') FROM numbers(1000);
SYSTEM STOP MERGES t;
ALTER TABLE t DELETE WHERE id < 100 SETTINGS mutations_sync = 0;
SELECT count() FROM t WHERE hasToken(s, 'tok1');
-- 26.8.2.7 / 26.7.6.57 / 26.6.4.55 / 26.3.29.7 / 26.2.19.43:
-- Code: 16. DB::Exception: There is no column
-- __text_index_idx_hasToken_3eb56adb17617f51540c807a788a564f in table. (NO_SUCH_COLUMN_IN_TABLE)
-- expected: 90
-- Runs only with query_plan_direct_read_from_text_index = 0, use_skip_indexes = 0,
-- or apply_mutations_on_fly = 0. Same throw for a pending ALTER UPDATE of a read column.Results:
CC component owner: @CurtizJ @ahmadov Analysis metadata
Introducing change: first appears in the `26.2` line
|
|
@alexey-milovidov @tiandiwonder — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Closes: #116832
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
NO_SUCH_COLUMN_IN_TABLEfor every query using a text index while a mutation is pending withapply_mutations_on_fly = 1. Until the mutation materialized,hasToken,hasAnyTokensandhasAllTokenson the indexed column could not be executed at all.Description
query_plan_direct_read_from_text_index(default on) rewrites the search predicate into a columnsynthesized by the index reader, which produces it instead of reading the column data, for example
__text_index_idx_hasToken_<hash>. When a part has on-fly mutations to apply,MergeTreeReadPoolBase::buildReadTaskInfopasses the query's read column list toAlterConversions::getMutationSteps, whoseMutationsInterpreterresolves those names against thestorage snapshot in
prepareMutationStages— andStorageSnapshot::getColumnthrows for a name thatis not a table column.
The trigger is any pending on-fly mutation whose stage has to carry the query's read columns, not
DELETEspecifically: aDELETEadds a filter stage, and anALTER UPDATEthatAlterConversions::filterMutationCommandskeeps — because its assignment target is one of the readcolumns — does the same. Both spellings throw the identical exception without this fix (verified
against a binary built without it).
The mutation steps read the real columns their own expressions need, and the index column is produced
on top of their output, so it is filtered out of the list handed to them. The names to filter out are
taken from
index_read_tasks, which is where the index reader's columns were synthesized, ratherthan from a test of the
__text_index_name prefix: that prefix is not reserved, so a table maydeclare a column of its own with such a name, and dropping a declared column here would hide it from
filterMutationCommands, which would then discard a pendingALTER UPDATEof it while the readerstill reads the column — answering from stale on-disk values.
Test
05059_text_index_direct_read_pending_mutationcovershasToken,hasAnyTokensandhasAllTokensagainst the three settings that used to be the only way to make the query run(
query_plan_direct_read_from_text_index = 0,use_skip_indexes = 0,apply_mutations_on_fly = 0), the same query after the mutation materializes, the pendingALTER UPDATEspelling, and a table declaring a physical__text_index_*column of its own under apending
ALTER UPDATEof it.Workflow [PR]
Sync PR [sync-upstream/pr/117277]
Version info
26.9.1.670(included in26.9and later)