Repository navigation
Fix deferred filters with partition pruning on non-sorting key - #98242
Conversation
…replacing-mt Fix deferred filters with partition pruning on non-sorting key
|
Hi @yariks5s @alexey-milovidov — while reviewing this PR I found the following:
Could you review the test PR and add the |
|
Hi — this PR may need backporting to release branches Why: This fixes silent wrong results (P0) in a core query path (FINAL with partition pruning) that has existed since deferred filters were introduced. The affected code in ReadFromMergeTree is present in all active release branches. If this should be backported, consider adding |
Cherry pick #98242 to 26.2: Fix deferred filters with partition pruning on non-sorting key
Backport #98242 to 26.2: Fix deferred filters with partition pruning on non-sorting key
PR ClickHouse#98242 (commit `ebc5cb49baa594b87f4631850ae9902424414113`, landed in 26.3) disabled partition pruning unconditionally for any `FINAL` query whose partition-key columns are not part of the sorting key. The intent was correctness: a `FINAL` merge may need to deduplicate same-primary-key rows that live in different partitions, so partition pruning would silently drop input rows. In practice this hits event-log workloads hard. Their tables are partitioned by the event timestamp, which is set once at insert time and never changes — same-PK rows cannot span partitions. Reported wall-clock and memory regressions on real customer queries are around 6× and 4.4× respectively (see ClickHouse#104263). This commit makes the deferral opt-out via a new setting `defer_partition_pruning_after_final`: - 1 (default): preserves the 26.3+ correctness behavior. - 0: restores pre-26.3 partition pruning before FINAL. Safe only when the user can assert same-PK rows cannot exist in different partitions. The setting follows the same pattern as `apply_row_policy_after_final` and `apply_prewhere_after_final`. `compatibility = '26.2'` flips it to 0 via `SettingsChangesHistory`. A stateless regression test covers both the issue's reproducer (pruning works under opt-out) and the den-crane pathological case (same PK in two partitions with reversed versions — default deduplicates correctly across partitions, opt-out trusts the user's assertion and prunes first). Issue: ClickHouse#104263
26.3 is the version where the silent behavior change happened (PR ClickHouse#98242). Putting the entry under 26.3 makes `compatibility = '26.2'` correctly revert the setting to 0 (pre-regression behavior); `compatibility = '26.3'+` keeps the post-regression default of 1.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
If the partition key columns are not covered by the sorting key, then partition pruning could incorrectly skip partitions containing rows that should "win" during FINAL deduplication
Documentation entry for user-facing changes
Version info
26.3.1.19426.2.19.21