Repository navigation
Introduce Partition Constants Substitution During Index Analysis - #104582
Conversation
|
Workflow [PR], commit [d8e4c29] Summary: ❌
AI ReviewSummaryThis PR adds Findings
Final VerdictChanges requested. |
…kHouse/ClickHouse into skip_indices_part_constants_folding
|
This was fixed by #105146. Let's update the branch. |
…t folding Address review feedback: - `04417_partition_constants_folding_force_settings` documents that `force_primary_key` / `force_index_by_date` still throw `INDEX_NOT_USED` when pruning becomes effective only after per-part constant folding, because the force checks are evaluated against the unsubstituted condition. This locks in the current (data-dependent) behavior. - `04418_partition_constants_folding_minmax_count_projection` covers the implicit MinMax-count projection path in `MergeTreeData::getMinMaxCountProjectionBlock`, where the partition predicate is folded per part before checking the part's MinMax hyperrectangle. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…onstants_folding # Conflicts: # src/Storages/MergeTree/MergeTreeReaderTextIndex.cpp
…ory bucket The setting was recorded under the 26.6 bucket, but 26.6 has been released (baseline for `02995_new_settings_history` is v26.6.1) and the current development version is 26.7. The test requires new settings that are absent from the released baseline to be registered under a version greater than 26.6, so move the entry to the 26.7 bucket. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Merged the latest
The changelog category is already |
The recent master merge brought in `explain_query_plan_default = 'pretty'` (the new default since 26.7, introduced in #105036), which changes the default `EXPLAIN PLAN` output format. The five constant-folding tests that assert on `EXPLAIN indexes = 1` output started failing in Fast test with "result differs with reference": `04218_partition_pk_pruning_constants_folding`, `04219_partition_minmax_skip_index_constants_folding`, `04220_partition_id_constants_folding`, `04221_partition_id_with_minmax_constants_folding`, `04314_partition_constants_folding_derived_key`. Add `SET explain_query_plan_default = 'legacy';` to each of them so their existing (already reviewed) references stay valid. This mirrors how #105036 handled the ~414 existing `EXPLAIN` tests when it changed the default, and keeps the references demonstrating per-part constant folding unchanged. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104582&sha=ebf528aa38a90f8bc69735ead2da02540b2d479b&name_0=PR&name_1=Fast%20test Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Fixed the Fast test failures in I added |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 476/486 (97.94%) · Uncovered code |
|
|
||
| DROP TABLE IF EXISTS t_derived_key; | ||
| CREATE TABLE t_derived_key (d Date, b UInt64) | ||
| ENGINE = MergeTree ORDER BY b PARTITION BY toYYYYMM(d) SETTINGS index_granularity = 1; |
There was a problem hiding this comment.
@Michicosun Is this going to work with a multiple column partitioned table? Maybe add another test for this case
There was a problem hiding this comment.
This should work for any partitioning scheme.
…t_constants_folding Introduce Partition Constants Substitution During Index Analysis
|
Can we enable the setting by default now? |

This PR introduces partition-level constant substitution during index analysis.
When a filter references the partition key together with primary-key or skip-index columns, the partition value is folded into the predicate separately for each part. This lets
MergeTreeprimary-key,MinMax, and skip-index analysis prune more parts and granules without weakening the filter (the original, unsubstituted filter is still applied during execution).The behavior is controlled by the new setting
use_constant_folding_in_index_analysis, which is disabled by default.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added the
use_constant_folding_in_index_analysissetting (disabled by default). When enabled,MergeTreeprimary-key,MinMax, and skip-index analysis fold partition-level constants into the filter predicate separately for each part, improving pruning for filters whose branches depend on partition values, e.g.(a = 1 AND b >= 1) OR (a = 2 AND b > 10)withPARTITION BY a.Version info
26.7.1.598(included in26.7and later)