Repository navigation
Do not let use_skip_indexes = 0 disable part min-max pruning - #123403
Conversation
ClickHouse#103952 added `|| !use_skip_indexes` to `skip_analysis` of the per-part min-max condition, both in `ReadFromMergeTree::buildPartitionPruningIndexes` and in `MergeTreeData::getMinMaxCountProjectionBlock`. Since 26.5, queries with `use_skip_indexes = 0` no longer prune parts by the partition-key min-max index and read every part whose partition is not removed by the partition pruner. `use_skip_indexes` controls data-skipping indexes only. Gate the part min-max index on `use_partition_pruning` again, as before ClickHouse#103952 and as the partition pruner next to it already is. Fixes ClickHouse#123363.
The `partition_key_prunes_something` cell relied on `use_skip_indexes = 0` leaving the Min-Max stage inert, so that only the Partition stage pruned. Min-Max now prunes there too, so compare the granules left after Partition with the granules Min-Max started from instead.
|
Workflow [PR], commit [e3a8470] Summary: ✅
AI ReviewSummaryThis PR restores part-level partition-key Findings❌ Blockers
Final Verdict
|
With `part_minmax_index_columns = 'with_block_number_offset'` the part min-max index also covers `_block_number` and `_block_offset`. A condition on them alone made the min-max condition useful, so `force_index_by_date` did not throw `INDEX_NOT_USED` although there is no condition on the partition key. This already happened with the default `use_skip_indexes = 1`; after the previous commit it also happens with `use_skip_indexes = 0`. Require the min-max condition to use at least one partition-key column. The block number columns come after the partition-key columns in the min-max index, so it is enough to compare the used column positions.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 64 s compile time in total, 8 of them have a recent master baseline. |
- 04328: `use_skip_indexes = 0` no longer disables part-level min-max pruning, so it is not an unindexed oracle anymore. Use `use_partition_pruning = 0, use_statistics_for_part_pruning = 0` instead, which really reads every part. - 05317: disable the query condition cache, which ignores `use_skip_indexes`, and statistics on the ClickHouse#115271 table, so the `Statistics` step can not remove the part before the partition pruner runs.
|
@samay-sharma CI is green here. Could you take a look, or point it to whoever reviews |
|
@Michicosun I see you are the assignee of the issue, can you please review this PR? |
| /// `force_index_by_date` requires a condition on the partition key. The min-max index may also cover | ||
| /// `_block_number` and `_block_offset` (see `part_minmax_index_columns`), which come after the | ||
| /// partition-key columns, so a condition on them alone does not count. | ||
| auto minmax_idx_uses_partition_key = [&] | ||
| { | ||
| if (!minmax_idx_condition) | ||
| return false; | ||
| const auto & condition = minmax_idx_condition->generateUnsubstituted(); | ||
| if (condition.alwaysUnknownOrTrue()) | ||
| return false; | ||
| const size_t num_partition_key_columns = MergeTreeData::getMinMaxColumns( | ||
| metadata_snapshot->getPartitionKey(), data.getSettings(), MergeTreePartMinMaxIndexColumns::PARTITION_KEY_ONLY).size(); | ||
| for (size_t column : condition.getUsedColumns()) | ||
| if (column < num_partition_key_columns) | ||
| return true; | ||
| return false; | ||
| }; |
There was a problem hiding this comment.
Why is this change needed to fix an issue?
There was a problem hiding this comment.
Without the use_skip_indexes gate, the part min-max index is also built with _block_number / _block_offset when part_minmax_index_columns = 'with_block_number_offset'. A condition on them alone then made force_index_by_date pass, which it did not with use_skip_indexes = 0 before this PR. This change counts only the partition-key columns for force_index_by_date. Covered by 05318_force_index_by_date_minmax_block_number.
There was a problem hiding this comment.
That is okay, let's not change this in the current pr.
There was a problem hiding this comment.
Reverted the force_index_by_date change in MergeTreeDataSelectExecutor.cpp and removed 05318_force_index_by_date_minmax_block_number. The description now notes that a condition on _block_number or _block_offset alone satisfies force_index_by_date with use_skip_indexes = 0 too, as it already does with use_skip_indexes = 1.
There was a problem hiding this comment.
Let's create a simple test from the issue repro.
There was a problem hiding this comment.
Added 05326_minmax_pruning_use_skip_indexes_repro, the repro from the issue with use_skip_indexes = 0. It expects Min-Max to select 1/30 parts, and 30/30 without the fix.
There was a problem hiding this comment.
There are too many tests for a simple problem, let's leave only tests/queries/0_stateless/05326_minmax_pruning_use_skip_indexes_repro.sql
There was a problem hiding this comment.
Removed 05317 and 05318; 05326_minmax_pruning_use_skip_indexes_repro is the only new test.
The PR still adjusts 04328, 04652 and 04947, because they used use_skip_indexes = 0 to turn off part Min-Max pruning.
…ue repro Related: ClickHouse#123363 Co-authored-by: Copilot <[email protected]>
…_alter_partition` `use_skip_indexes = 0` no longer disables the part-level `Min-Max` analysis, so the `pruned plan` check failed. Use parts whose `c1` range covers the searched value, so only the partition pruner can exclude one. Related: ClickHouse#123403 Co-authored-by: Copilot <[email protected]>
Revert the `force_index_by_date` change in `MergeTreeDataSelectExecutor` and remove `05317_minmax_pruning_with_use_skip_indexes_disabled` and `05318_force_index_by_date_minmax_block_number`, so the only new test is `05326_minmax_pruning_use_skip_indexes_repro`. Co-authored-by: Copilot <[email protected]>
|
Merged master to pick up the |
| SELECT count() FROM t_106533_partlevel WHERE NOT ((val >= 0.) AND (val <= 3.)); | ||
| SELECT count() FROM t_106533_partlevel WHERE NOT ((val >= 0.) AND (val <= 3.)) SETTINGS use_skip_indexes = 0; | ||
| SELECT count() FROM t_106533_partlevel WHERE NOT ((val >= 0.) AND (val <= 3.)) SETTINGS use_partition_pruning = 0, use_statistics_for_part_pruning = 0; | ||
|
|
||
| -- A positive range is decided by intersection alone, which a hidden NaN cannot make true, so the mixed | ||
| -- part is pruned for val > 500 as an all-finite one would be. | ||
| SELECT count() FROM t_106533_partlevel WHERE val > 500; | ||
| SELECT count() FROM t_106533_partlevel WHERE val > 500 SETTINGS use_skip_indexes = 0; | ||
| SELECT count() FROM t_106533_partlevel WHERE val > 500 SETTINGS use_partition_pruning = 0, use_statistics_for_part_pruning = 0; |
There was a problem hiding this comment.
Changing the oracle from use_skip_indexes = 0 to use_partition_pruning = 0 makes these two "unindexed" arms share the same query-condition-cache key as the pruned arm.
ReadFromMergeTree writes whole-part exclusions from index analysis into the QCC, and that key is salted by the skip-index profile / use_skip_indexes, not by use_partition_pruning. So if the first query wrongly prunes the mixed part, the second query can reuse that cached 0/1 verdict even though it disabled partition pruning, and the regression turns into a false negative.
Please pin use_query_condition_cache = 0 for this oracle (at least these two pairs), like the later t_106533_pk_minmax case already does.
There was a problem hiding this comment.
The query condition cache can't carry a wrong min-max prune into the second query. Parts are pruned by the min-max index in filterParts, before index analysis, and only ranges that the primary key or skip indexes exclude from the remaining parts are written to the cache. A part dropped by min-max pruning is never recorded. Here the primary key is on id and the table has no skip index, so nothing about val > 500 is cached, and the second query reads the part.
|
@Michicosun can you add the to merge queue ? |
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes when the part-level min-max and partition pruning analysis is skipped: setting use_skip_indexes=0 no longer turns it off. With default settings nothing changes, and the ClickBench table has no partition key, so the measured queries never run the changed code. ClickBench Q30 (+29.6%) and Q31 (+30.1%) are correctly marked not_sure because both PR medians fall inside master's recent range. CPU time fell slightly for both, and the PR runs were much noisier, consistent with the two benchmarks sharing one host, so no performance effect can be attributed to this PR. clickbenchFlagged queries (2 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
|
Cherry pick #123403 to 26.7: Do not let use_skip_indexes = 0 disable part min-max pruning
Cherry pick #123403 to 26.8: Do not let use_skip_indexes = 0 disable part min-max pruning
Cherry pick #123403 to 26.9: Do not let use_skip_indexes = 0 disable part min-max pruning
Backport #123403 to 26.8: Do not let use_skip_indexes = 0 disable part min-max pruning
Backport #123403 to 26.7: Do not let use_skip_indexes = 0 disable part min-max pruning
Backport #123403 to 26.9: Do not let use_skip_indexes = 0 disable part min-max pruning
…f the Min-Max step `(c0 IS NULL) >= true` and `(c0 IS NOT NULL) < true` reach the same single-point chain over a NULL partition value, so the partitioned table answered 0 instead of 2 for them. Since ClickHouse#123403, `use_skip_indexes = 0` no longer disables the part Min-Max condition, so the two `assumeNotNull` EXPLAIN blocks printed a pruning Min-Max step on current master. Use `isNull` / `isZeroOrNull` predicates there instead: they report no monotonicity, so only the Partition step can use them on any base. Closes ClickHouse#126369 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lace-build-mutex Conflicts resolved: - ReadFromMergeTree.cpp, MergeTreeData.cpp: keep master's `skip_analysis_` (no longer tied to `use_skip_indexes`, ClickHouse#123403), the PK factory without `relaxRangeAtomsOverNaNHidingTupleColumns`, and the vector similarity factory capturing `index_helper`; add the factories' `require_ready_sets` argument on top. - MergeTreeIndexText.cpp: master's `params.enable_positions` plus `require_ready_sets`. - ManifestFilesPruning.cpp: take master's version (ClickHouse#123085 made `require_ready_sets` a constructor parameter); pass `true` at the decode thread caller `ManifestFileIterator::getOrCreatePruner`, as this branch did inside the pruner before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #123363
Related: #103952, #115271, #117355
Since 26.5,
use_skip_indexes = 0also turns off the per-part min-max index on the partition-key columns. Queries that set it (for example to bypass abloom_filterindex) stop pruning parts by the partition key and read every part the partition pruner does not remove. The issue reports a production query going from about 55 to about 2,400 selected parts, with p99 latency going from ~4 s to ~48 s.#103952 added
|| !use_skip_indexestoskip_analysisof the min-maxKeyConditioninReadFromMergeTree::buildPartitionPruningIndexes, and the same check toMergeTreeData::getMinMaxCountProjectionBlock. The partition pruner next to both is still gated only onuse_partition_pruning.use_skip_indexesis documented as "Use data skipping indexes during query execution." The part min-max index is not a data-skipping index: it covers the partition-key columns, plus_block_number/_block_offsetwithpart_minmax_index_columns = with_block_number_offset.The fix removes the
use_skip_indexescheck from both places, so the min-max index is gated onuse_partition_pruningagain, as before #103952.use_partition_pruning = 0still disables it, which03988_setting_use_partition_pruningand04062_use_partition_pruning_disable_minmax_count_projectioncover.One existing test relied on the old behavior. The
partition_key_prunes_somethingcell of04652_enum_constant_vs_string_columnsetuse_skip_indexes = 0so that Min-Max would stay at 5/5 and only the Partition stage would prune. Min-Max now prunes 1/5 there with the samev in ['7', '7']condition, so the cell compares the granules left after Partition with the granules Min-Max started from. It still fails if neither stage prunes, and it passes on both the old and the new build. Thepartition_key_condition_uses_namecell, which reads the Partition section's condition text, is unchanged.04328_106533_partition_pruning_nan_inversionuseduse_skip_indexes = 0as its unindexed oracle for the part-level min-max checks ont_106533_partlevel. With the fix that arm prunes too (Parts: 0/1forval > 500), so the oracle now usesuse_partition_pruning = 0, use_statistics_for_part_pruning = 0, which reads every part.In
getMinMaxCountProjectionBlockthe gate only cost pruning: the partition pruner still ran, so results were correct. It is removed there too, for consistency.04947_modulo_partition_key_alter_partitionuseduse_skip_indexes = 0so that only the partition pruner would exclude a partition. Min-Max now excludes it first, so the table is partitioned byc1 % 2, which Min-Max cannot prune byc1 = 2but the partition pruner can.With
part_minmax_index_columns = 'with_block_number_offset', a condition on_block_numberor_block_offsetalone already satisfiesforce_index_by_datewith the defaultuse_skip_indexes = 1. With the gate removed this now also holds foruse_skip_indexes = 0.force_index_by_dateis not changed in this PR.This also fixes the reproducer in #115271. With
use_skip_indexes = 0, min-max pruning did not remove thep = 1part, so the partition pruner evaluatedintDiv(1, p - 1)on it and threwDivision by zero. With the fix the query returns0, as on 26.4. This does not fix the underlying problem: the partition pruner can still throw on a part that min-max pruning does not remove. The general fix for that is #117355, so this PR does not close #115271.Test
05326_minmax_pruning_use_skip_indexes_reprois the issue's repro: 30 daily parts, each containing everyk, withauto_statistics_types = ''so theStatisticsstep cannot hide the bug. Withuse_skip_indexes = 0it expectsMin-Maxto select 1/30 parts. Without the fix it selects 30/30.Benchmark
Official Docker images,
clickhouse local. The table has 51.8M rows in 226 parts (180 daily partitions),ORDER BY kwith everykin every part, and no statistics. The query isSELECT count() FROM t WHERE k = 3 AND ts::Date IN (SELECT toDate('2026-03-05')). Latency is the median of 10 warm runs on local NVMe:use_skip_indexeshead)head)On master,
use_skip_indexes = 0reads 226× the parts and 225× the rows. Locally that is about 4× the latency. On object storage each extra part means more GET requests, which is where the issue's 60× S3 GETs and 12× p99 come from. With the fix,use_skip_indexes = 0reads the same single part asuse_skip_indexes = 1. The "this PR" rows come from a local release build of this branch (clang 21.1.8), run natively rather than in Docker.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
use_skip_indexes = 0also disabling part pruning by the partition-key min-max index (since 26.5), which made such queries read every part of the table.Workflow [PR]
Sync PR [sync-upstream/pr/123403]
Version info
26.10.1.2200-master(included in26.10and later)26.9.18.11,26.8.26.5,26.7.29.12