Repository navigation
Treat a bare table identifier on the right of IN as a deferred set for mutation pruning - #117272
Conversation
…for mutation pruning Mutation partition pruning leaves a predicate with a deferred `IN` set unpruned, because the pruning pass and the asynchronous mutation execution evaluate the set independently: rows in a partition that matches only the execution-time set have no block number and escape the mutation, while it is still reported `is_done = 1`. The guard only recognised an `ASTTableIdentifier` on the right-hand side, but a parsed `IN some_table` carries a plain `ASTIdentifier`; only an already-resolved one is an `ASTTableIdentifier`. That is also the worst form to miss: an explicit subquery in a mutation predicate is rejected up front by the `allow_nondeterministic_mutations` validation, while a bare table identifier passes it - so the deferred-set form users can actually run at default settings was exactly the one the guard let through. Nothing else can stand there: the right-hand side of `IN` is a set, a tuple, a subquery, a table or a table function, so any identifier names a table. Closes: #117113
|
Workflow [PR], commit [20ad298] Summary: ✅
AI ReviewSummaryThe PR prevents mutation partition pruning from narrowing the scope of table-backed Final VerdictStatus: ✅ Approve |
|
The one-line fix looks correct and safely conservative for the spelling it targets, and since One same-function sibling stays open after this merges: |
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, 31 s compile time in total, 7 of them have a recent master baseline. |
…red set Address review: the pruning guard only inspected the raw predicate AST, while the analysis below expands `ALIAS` columns against the storage (`collectSourceColumns` with `keep_alias_columns = false`). A column default such as `is_hit UInt8 ALIAS p IN keys` therefore carried a deferred set past the guard, and `ALTER TABLE ... DELETE WHERE is_hit` was still pruned to the submission-time contents of `keys`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…`ALIAS` carrier `IAST::as` is an exact-type cast, not a `dynamic_cast`, so `as<ASTIdentifier>` does not match an `ASTTableIdentifier` - and `MarkTableIdentifiersVisitor` rewrites the node in place, including inside a column default expression the storage metadata keeps. Spell out both forms. Extend test 05075 with the `ALIAS` carrier the review asked for: a column `is_hit UInt8 ALIAS p IN keys` must leave the mutation unpruned, while `is_one UInt8 ALIAS p IN (1)` is a stable constant set and is still pruned. The test also waits for the mutation entries with `SYSTEM SYNC REPLICA ... PULL` before reading `system.mutations`: an entry becomes visible only after this replica pulls it from ZooKeeper, which made the test flaky in CI (the second mutation row was sometimes missing). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 @zlareb1 thank you - the column-default escape you verified on master is now fixed in this PR rather than left for #117273: Your note that the definition survives the no-subqueries-in-defaults validation also explains a second defect: Also fixed the CI flake in the new test: a mutation entry is visible in |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…the deferred-set check The deferred-set check in `getPartitionIdsPrunedByPredicate` looked up column defaults by the raw identifier spelling, so `DELETE WHERE t.is_hit` missed the `is_hit` `ALIAS` (which hides `p IN some_table`) while the analysis resolved the qualified name all the same and pruned the mutation to the submission-time set. Strip a `table.` / `database.table.` qualifier naming this table and also try every name prefix, so that a subcolumn of such a column is followed as well. Also document why an identifier on the right of `IN` is always a table here: `AddDefaultDatabaseVisitor` qualifies it with the database, so a column there (`x IN arr`) is rejected in mutation predicates and in column defaults alike. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ed-set check A stored `DEFAULT`/`MATERIALIZED` column is read as it was written, so a deferred set in its definition is not evaluated by either the pruning pass or the mutation execution. Following it only lost pruning for a safe predicate. Mirror `contains_nondeterministic_function` and add a regression for a `MATERIALIZED` carrier. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A `MATERIALIZED` column with `IN some_table` cannot be inserted into at all (#117276), so cover the stored carrier with a `DEFAULT` column written explicitly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117272&sha=88c4f5982fb5955ffe937976930c449b9a424b4f&name_0=PR&name_1=AST%20fuzzer%20(amd_debug%2C%20targeted%2C%20old_compatibility) ( |
|
The fix is already in progress: #119664 (it closes #117276, which is this abort). The aborting mutation comes from this PR's own test, unfuzzed: This PR does not cause it. The same thing aborts on master ( CREATE TABLE keys (p UInt8) ENGINE = MergeTree ORDER BY p;
CREATE TABLE t (p UInt8, x UInt64, is_hit UInt8 ALIAS p IN keys) ENGINE = MergeTree PARTITION BY p ORDER BY x;
INSERT INTO keys VALUES (1);
INSERT INTO t VALUES (1, 1), (2, 2);
ALTER TABLE t DELETE WHERE is_hit;With the |
…ns in the deferred-set check The deferred-set walk in `getPartitionIdsPrunedByPredicate` treated every identifier as a storage column, including lambda parameters, so `arrayExists(x -> x = 1, arr)` with a column `x ALIAS p IN keys` lost partition pruning. Mirror the lambda handling of the non-determinism check: skip the parameter list, track bound names while visiting the body, and do not carry them into a followed column definition. Cover both the shadowing case and a free name inside a lambda body in `05075`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
In the `DBReplicated` stateless run, `SYSTEM STOP REPLICATION QUEUES` stops only the local replica, so another replica executed `ALTER TABLE t_prune_in_table_alias DELETE WHERE is_hit` and hit the `Not-ready Set is passed as the second argument for function 'in'` exception of #117276, aborting that server. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117272&sha=58900020280f2b4987a013dc1355d569ef7f21dc&name_0=PR&name_1=Stateless%20tests%20(amd_llvm_coverage%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%203%2F3) PR: #117272 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Thanks @groeneai. The |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117272&sha=43f81d75e08cf8518c9466936c9fa7f293fffa95&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20s3%20storage%2C%20DBReplicated%2C%20sequential%29 ( |
|
Already fixed by #126345 (merged 2026-10-19 10:34Z), so no new PR is needed. The stack is the expected The 43f81d7 run (2026-10-18) was built before the fix; the new head 09b45db already contains it. Since the merge: 667 master runs with 3 failures, all on commits without the fix, and the 2 PR failures were re-runs of workflows created before the merge. |
|
🕵 Status of the CI failures on da1dd1d:
|
|
🕵 Status of the CI failures on d95721b:
|
|
🕵 Status on e085e92: public CI is green. The only red check is |
…deferred set Now that a mutation through `flag ALIAS p IN keys` executes instead of throwing, the partition pruning of `getPartitionIdsPrunedByPredicate` must not narrow it to the partitions matching the submission-time contents of `keys`: the set is built again when the mutation executes, so rows in a partition matching only then would escape the mutation while it reports `is_done = 1`. Follow an identifier of the predicate into its `ALIAS`/`EPHEMERAL` column definition when looking for a deferred set, and treat a plain `ASTIdentifier` on the right of `IN` (the parsed form of `IN table`) as one. This is the guard of #117272, included here so this change does not depend on it landing first. The new test changes the right-hand side between the submission and the execution of a mutation on a partitioned `ReplicatedMergeTree` and checks that the rows of the newly matching partition are deleted. Related: #117272 Related: #117113 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Status of the CI failures on b882000:
I merged master (20ad298) to refresh the branch. There are no unresolved review threads. |
|
📊 Cloud Performance Report ✅ AI verdict: No performance changes are attributed to this PR. It only changes how mutation partition pruning detects deferred IN sets (MergeTreeData::getPartitionIdsPrunedByPredicate) and adds a test, and none of the benchmark SELECT queries run that code. The one flagged row, clickbench Q10 (+17.9%, 95 ms to 112 ms), was correctly kept at not_sure: it sits inside master's current 83–115 ms range and has a noisy history. Nothing in the diff points to this delta, so the PR shows no regressions or improvements. clickbenchFlagged queries (1 of 43)
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
|
Closes: #117113
Related: #110968
Related: #117115
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
ALTER DELETE/ALTER UPDATEsilently skipping rows when the predicate containsIN <table>.The default-enabled
optimize_mutations_with_partition_pruningevaluated that set at submission timeand narrowed the mutation's
block_numbers, so a partition matching only the execution-time set wasleft out while the mutation still reported
is_done = 1.Description
contains_deferred_setinMergeTreeData::getPartitionIdsPrunedByPredicateintends to leave everydeferred
INform unpruned — its own comment says so — but for the table form it only checkedright_argument->as<ASTTableIdentifier>(). A parsedIN some_tablecarries a plainASTIdentifier;only an already-resolved one is an
ASTTableIdentifier(which derives from it). The analysis thenresolved the identifier to a prepared set and pruned with its submission-time contents.
That is the worst form to miss. An explicit subquery in a mutation predicate is rejected up front by
the pre-existing
allow_nondeterministic_mutationsvalidation ("ALTER UPDATE/ALTER DELETE statementwith subquery may be nondeterministic"), while a bare table identifier passes it — so the deferred-set
form users can actually run at default settings was exactly the one the guard let through.
Checking for
ASTIdentifiercovers both spellings, and nothing else can legitimately stand there: theright-hand side of
INis a set, a tuple, a subquery, a table or a table function.The existing
04909_mutation_partition_pruning_deferred_setscannot catch this because it setsvalidate_mutation_query = 0, andgetPartitionIdsAffectedByCommandsdisables pruning entirely whenvalidation is off — the guard is never reached for the table form. New test
05075_mutation_partition_pruning_table_in_setasserts the resultingblock_numbers.partition_iddirectly, and that a literal enumeration is still pruned.Workflow [PR]
Sync PR [sync-upstream/pr/117272]
Version info
26.12.1.101-master(included in26.12and later)