Skip to content

Proper partition pruning with dates - #118606

Merged
scanhex12 merged 13 commits into
masterfrom
iceberg_partition_pruning_todate
Sep 10, 2026
Merged

scanhex12 merged 13 commits into
masterfrom
iceberg_partition_pruning_todate

Conversation

@scanhex12

@scanhex12 scanhex12 commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Proper partition pruning with dates. Closes #103433


Workflow [PR]
Sync PR [sync-upstream/pr/118606]

Version info

  • Backported to: 26.8.3.89, 26.7.7.70

scanhex12 and others added 3 commits September 7, 2026 15:16
…nversion

`ToDateMonotonicity` and `ToDateTimeMonotonicity` ask `WhichDataType` about the
argument type as it comes. For `Nullable(DateTime64(6))` none of the branches
match, so `toDate`, `toDate32`, `toDateTime` and `toDateTime64` are reported as
non-monotonic and key analysis drops the atom: a `WHERE toDate(x) = ...` over a
nullable key reads every granule. `IFunctionDateOrDateTime` already unwraps the
wrapper, which is why `toYYYYMMDD(x)` uses the index in the same query while
`toDate(x)` does not.

Monotonicity of a value-wise conversion does not depend on the wrapper: `NULL`
maps to `NULL` and keeps its place in the ordering. Unwrap `LowCardinality` and
`Nullable` before the type dispatch, so the decision is made about the value
type. For an argument that is neither, this changes nothing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ed column

Partition pruning builds a `KeyCondition` whose key is the partition expression,
for example `day(ts)`, and the source column is offered as the key's argument.
That covers a predicate on the column itself, because
`canConstantBeWrappedByMonotonicFunctions` finds `ts` among the key
subexpressions and pushes the constant through `day`. It does not cover
`toDate(ts) = ...`: that expression is not a subexpression of the key, and
composing the two directions (invert `toDate` on the constant, then apply `day`)
is something `KeyCondition` does not do. So any filter that wrapped the
partition source column in a function was ignored, and a table partitioned by
`days(created_at)` was read in full.

The partition value of a monotonic transform is a bound on the source column:
every row of the file shares the partition value, so `day = 19722` says the
column is within `[2023-12-31 00:00:00, 2023-12-31 23:59:59.999999]`. Derive
that range and hand it to the per-column conditions that pruning already builds
from the manifest bounds. Those have the source column as their key, so
`KeyCondition` handles a monotonic function chain over it, and no new condition
analysis is needed. The derived range does not come from the manifest bounds, so
this also prunes files that carry no column statistics at all.

The month and year boundaries are the calendar arithmetic of `DateLUT` around
`ExtendedDayNum(0)`, which is the epoch the transforms count from; a partition
value no date can represent saturates there and is rejected by a round trip
through the forward transform.

`day`, `hour`, `month` and `year` are inverted. `bucket` and `void` cannot be,
and `truncate` is left for later; an `identity` partition already works, because
there the source column is the key itself. A non-null partition value implies
the source column has no nulls in that file, because a transform returns null
for a null input, so the range needs no separate null check.

Closes: #103433

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5273be8]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug, targeted, old_compatibility) FAIL
Logical error: 'exact_ranges[i].begin >= range.begin' (STID: 2508-4c75) FAIL cidb
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) FAIL
05054_nullable_key_todate_monotonicity FAIL cidb
02156_storage_merge_prewhere NOT_FAILED cidb
02402_merge_engine_with_view NOT_FAILED cidb
02918_optimize_count_for_merge_tables NOT_FAILED cidb

AI Review

Summary

This PR fixes two real pruning gaps: toDate/toDateTime monotonicity over Nullable keys, and Iceberg partition pruning when the filter wraps the partition source column in a monotonic date function. The Nullable key fix is only partial because the sibling preimage rewrite still sees wrapped DateTime types, and the Iceberg pruning path is still incorrect for non-UTC DateTime / DateTime64 partition columns, where it can prune away files that do contain matching rows.

Findings

❌ Blockers

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFilesPruning.cpp:302-333] The partition-value inversion for day / month / year on DateTime and DateTime64 reconstructs ranges in UTC and then refines day numbers with a fixed 86400 seconds-per-day step. That does not match the forward transforms ClickHouse writes into Iceberg metadata: toRelativeDayNum, toMonthNumSinceEpoch, and toYearNumSinceEpoch run in the source column's DateLUT, and civil days in non-UTC zones are not always 86400 seconds wide. A ClickHouse-written table partitioned by a non-UTC DateTime can therefore have a file pruned even though WHERE toDate(ts) = ... or toStartOfMonth(ts) = ... matches rows inside it.
    Suggested fix: derive the inverse interval with the same DateLUT and the same boundary construction the forward transform uses (fromDayNum / addMonths / addYears in that zone), or decline this pruning path unless the partition semantics are known to be UTC.
  • [src/Functions/FunctionsConversion.h:4363-4377] ToDateMonotonicity::get now ignores LowCardinality / Nullable, but getPreimage still passes the wrapped type through unchanged. OptimizeDateOrDateTimeConverterWithPreimageVisitor calls getPreimage on the raw column type, so toDate(nullable_datetime) = const is still not rewritten to a plain range for Nullable(DateTime) even after this patch. That leaves the same wrapper-invariant broken in a sibling optimization path and keeps those filters on the slower full-scan path.
    Suggested fix: unwrap wrappers before getPreimageForDateRounding, or move the unwrapping into the helper itself.
Tests
  • ⚠️ There is still no regression that exercises a ClickHouse-written Iceberg table with a non-UTC DateTime / DateTime64 partition column (for example DateTime('America/New_York') partitioned by days or months). That is the smallest focused test that would prove the inverse range uses the same semantics as the writer.
Final Verdict

Changes requested.

LLVM Coverage Report

Measured on commit 5273be8.

Metric Baseline Current Δ
Lines 88.90% 88.90% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 96/105 (91.43%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 7, 2026
scanhex12 and others added 2 commits September 7, 2026 15:58
#103447 rewrote the filter itself,
substituting `toDate` with `toRelativeDayNum` and recomputing the constant, and
the review named two ways that loses rows: a constant that is not aligned to the
transform's granularity (`toStartOfHour(ts) < '... 10:30:00'` must keep the
10:00 hour, the rewrite dropped it) and a value before 1970, where the unsigned
relative transforms invert the ordering (`toRelativeDayNum('1969-12-31')` is
`65535` while `1970-01-01` is `0`).

Deriving the source range from the partition value leaves the predicate alone,
so both are decided by `KeyCondition` over an exact range instead of by an
equivalence that has to be proven. Test them: a non-aligned constant on the
hour, day and month transforms, and a table whose `days` and `years` partition
values are negative.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Refining a closed interval into a finer unit is the same arithmetic three times
over: an hour into seconds, a day into seconds, and a second into the ticks of
the column's scale. `[a, b]` becomes `[a * factor, (b + 1) * factor - 1]`, so
say that once and drop the `multiplyChecked`/`addChecked` pair whose only job
was to thread the overflow checks through those expressions.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 7, 2026
A partition value comes straight from manifest metadata, so the arithmetic that
turns it into a range must not assume it is in range. Carry the interval
half-open, where each step is one `addOverflow` or `mulOverflow` away from the
previous one, and close it at the end with a checked subtraction: a value no
date can represent now fails a check and leaves the file unpruned instead of
wrapping around through signed overflow.

The interval is closed rather than handed to `KeyCondition` half-open on
purpose. Key analysis applies the filter's functions to the two ends of the
range, so the excluded upper end of a January partition maps to February and
`toStartOfMonth(ts) = '2024-02-01'` keeps the January file; the last value
inside the interval maps to January and prunes it.

`canBePruned` reads the partition value once instead of naming it in two
scopes, which `clang-tidy` reports as shadowing when the outer one is hoisted.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@scanhex12
scanhex12 force-pushed the iceberg_partition_pruning_todate branch from 6ecb9de to 884a8ef Compare September 7, 2026 21:34
scanhex12 and others added 2 commits September 7, 2026 22:07
`rangeOfPartitionValue` repeated the same three steps in each branch: build the
interval, take the last value inside it, wrap the two ends into a `Range`, with
the emptiness of every step threaded by hand. What the branches actually differ
in is the unit the column stores its values in, so let the emptiness propagate
through the helpers and leave one line per type.

Both ends of a month or year interval are now checked by the round trip through
the forward transform. The calendar saturates at the top of its range, where one
month past the last one is 9999-12-31 rather than the first excluded day, and
taking that for the excluded end would drop 9999-12-31 out of the interval and
let `toDate32(ts) = '9999-12-31'` prune the file that holds it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@scanhex12
scanhex12 force-pushed the iceberg_partition_pruning_todate branch from aeee61d to f8ae61d Compare September 7, 2026 22:18
scanhex12 and others added 2 commits September 8, 2026 00:18
`DataTypes/DataTypeLowCardinality.h` was included twice, which fails the
clang-tidy check with `readability-duplicate-include`. The second include came
with the merge of `master`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
if (!own_unit)
return {};

const auto & utc = DateLUT::instance("UTC");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

day/hour/month/year partitions are not always UTC on tables written by ClickHouse itself. getPartitionField serializes toRelativeDayNum, toRelativeHourNum, toMonthNumSinceEpoch, and toYearNumSinceEpoch into Iceberg day/hour/month/year, and those transforms run in the source column's DateLUT for DateTime/DateTime64, not in UTC. Reconstructing the source range with DateLUT::instance("UTC") therefore shifts every local boundary on a non-UTC table.

Concrete case: a ClickHouse-written DateTime('America/New_York') value 2023-12-31 20:30:00 belongs to the local day=2023-12-31 partition, but this code maps that partition to [2023-12-31 00:00:00 UTC, 2024-01-01 00:00:00 UTC), which excludes the row. A predicate such as WHERE toDate(dt) = '2023-12-31' can then prune the file away even though it contains a matching row.

Please derive the inverted interval in the same time zone the forward partition transform uses, or decline this pruning path unless the partition semantics are known to be UTC.

@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5273be862 with master b666e5df6 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

76 translation units recompiled, 297 s compile time in total, 74 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.09 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +23.9 s (+9%) in total before that adjustment.

Job report

@antonio2368 antonio2368 self-assigned this Sep 8, 2026
Comment thread src/Functions/FunctionsConversion.h Outdated

/// Monotonicity of a value-wise conversion does not depend on the `Nullable` or `LowCardinality`
/// wrapper: `NULL` maps to `NULL` and keeps its place in the ordering.
inline const IDataType & unwrapTypeForMonotonicity(const IDataType & type)

@antonio2368 antonio2368 Sep 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this removeLowCardinalityAndNullable?

scanhex12 and others added 2 commits September 9, 2026 15:01
`unwrapTypeForMonotonicity` was `removeLowCardinalityAndNullable` written again, as
pointed out in review. That function takes a `DataTypePtr`, while a monotonicity
implementation only gets a `const IDataType &`, so it now has an overload for a
reference and the local copy in `FunctionsConversion.h` is gone.

A reference overload rather than `type.getPtr()`: `getPtr` is `shared_from_this`,
which throws for a type that no `shared_ptr` owns, and monotonicity is called that
way, e.g. `gtest_conversion_monotonic.cpp` passes stack-allocated types.

PR: #118606

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Reverts the `removeLowCardinalityAndNullable` overload for `const IDataType &`:
the two monotonicity implementations that need the unwrapping do it themselves.

PR: #118606

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
static IFunction::Monotonicity get(const IDataType & type, const Field & left, const Field & right)
static IFunction::Monotonicity get(const IDataType & type_with_wrappers, const Field & left, const Field & right)
{
const IDataType * type_without_wrappers = &type_with_wrappers;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToDateMonotonicity::get now peels LowCardinality/Nullable, but getPreimage still forwards the wrapped type unchanged to getPreimageForDateRounding at src/Functions/FunctionsConversion.h. OptimizeDateOrDateTimeConverterWithPreimageVisitor calls converter_base->getPreimage(*column_type, point) on the raw column type, so toDate(nullable_dt) = ... still gets no preimage and the AST rewrite remains disabled for Nullable(DateTime) / LowCardinality(Nullable(DateTime)). The same wrapper-invariant this patch fixes for key analysis is therefore still broken in the sibling preimage optimization path.

Please unwrap before calling getPreimageForDateRounding, or teach that helper to accept wrapped DateTime.

@scanhex12
scanhex12 enabled auto-merge September 10, 2026 12:41
@scanhex12
scanhex12 added this pull request to the merge queue Sep 10, 2026
@scanhex12 scanhex12 added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 10, 2026
PedroTadim added a commit that referenced this pull request Sep 11, 2026
Backport #118606 to 26.8: Proper partition pruning with dates
Algunenano added a commit that referenced this pull request Sep 11, 2026
…8/118606

Revert "Backport #118606 to 26.8: Proper partition pruning with dates"
Algunenano added a commit that referenced this pull request Sep 11, 2026
…7/118606

Revert "Backport #118606 to 26.7: Proper partition pruning with dates"
scanhex12 added a commit that referenced this pull request Sep 11, 2026
…it is

An Iceberg partition field summary keeps its bounds in the single-value
serialization of the partition field's own type, and for the `day`, `month`,
`year` and `hour` transforms that type is a signed `int` counting units from
1970. ClickHouse models those transforms in the partition key with
`toRelativeDayNum`, `toMonthNumSinceEpoch`, `toYearNumSinceEpoch` and
`toRelativeHourNum`, whose result types are unsigned, so
`ManifestListPruner::canBePruned` read a bound from before 1970 as a huge
unsigned number. For a manifest that spans 1969 and 2024 the lower bound then
came out above the upper bound, and `KeyCondition::checkInRange` hit
`chassert(key_order.compareTuples(left_keys, right_keys, used_key_size) <= 0)`,
which aborts a build with assertions.

That is why
`test_storage_iceberg_with_spark/test_partition_pruning_with_functions.py::test_partition_pruning_with_functions_before_epoch`
started failing on master in `Integration tests (amd_tsan, 3/6)` and
`Integration tests (amd_msan, 8/8)`: the `toDate32` monotonicity that
#118606 gave a `Nullable` column
made the filter of that test reach the pruner.

A bound of an unsigned key column is now read as the signed number Iceberg
wrote, and a negative one leaves the whole field unknown: the ClickHouse
functions that stand for those transforms cannot return a negative number -
they map every point before 1970 to zero - so nothing about the key's value
space follows from such a bound and no range of it may be pruned on.

A pair of bounds that comes out inverted now drops the field with a warning
instead of being pruned on, the same as `ManifestFileIterator` already does
for the min/max bounds of a data file.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=290309210c5b2f0e01c13fd0fbae6577fb5cb9cd&name_0=MasterCI&name_1=Integration%20tests%20%28amd_tsan%2C%203%2F6%29

Related: #118606
Related: #116499
Related: #116604

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
scanhex12 added a commit that referenced this pull request Sep 11, 2026
…n shape

`EXPLAIN indexes = 1` prints two lines that contain `Granules:`: the
`Parts: 1 | Granules: 2` summary of the `ReadFromMergeTree` step and the
`Granules: 2/10` of the primary key index analysis. The test grepped for both
and stripped the indentation with `trimLeft`, which made it depend on the shape
of the plan around them:

- with `make_distributed_plan = 1` the step summary is not printed at all, so the
  test lost three lines;
- with parallel replicas the whole subtree is printed under a `│` prefix, which
  `trimLeft` does not strip, so all six lines came out prefixed.

The granule count is now read with `extract(explain, 'Granules: \d+/\d+')`, which
picks the index analysis line out of any indentation or prefix and does not match
the step summary at all. That is also the line the test is about: it says the
index analysis narrowed ten granules down to two.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119302&sha=323a1976ae947f4c28bca9cea92d08d6913e4f86&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29

Related: #118606

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
alexey-milovidov added a commit that referenced this pull request Sep 13, 2026
Edited by hand following .claude/skills/edit-changelog/SKILL.md, consolidating
the nine raw blocks generated between 2026-09-06 and 2026-09-13. The
NightlyChangelog job rejected its own edits every night in that period: the
verifier did not know that #116566 (reverted by #116586) had itself reverted
#109710, so it demanded that no trace of #116586 remain while the rules put
its link on the CatBoost entry. Fixed in the job by
#119866; this edit passes the
patched verifier, and the trailers below give the ledger the missing chain.

Failed runs: https://github.com/ClickHouse/ClickHouse/actions/runs/34006912773
through https://github.com/ClickHouse/ClickHouse/actions/runs/34668133756

Changelog-revert: 116566 109710 Revert "Remove CatBoost integration"
Changelog-revert: 116586 116566 Revert "Revert "Remove CatBoost integration""
Changelog-revert: 117629 117295 Revert "Skip Darwin fast test in PRs unless labeled ci-macos"
Changelog-revert: 118525 118218 Revert "Do not wait for the remote drain when cancelling a remote query"
Changelog-revert: 119043 117866 Revert "Add `ci-coverage` label to force LLVM coverage jobs on tests-only PRs"
Changelog-revert: 119269 118239 Revert "Require agents to run the style check locally before pushing"
Changelog-revert: 119270 115343 Revert "Resume a NATS JetStream subscription after a reconnect"
Changelog-revert: 119274 118919 Revert "Carry the mutation version onto a rewritten lightweight `DELETE`"
Changelog-revert: 119275 114817 Revert "Convert OUTER join to INNER join by null-rejecting join conditions"
Changelog-revert: 119276 110939 Revert "Support real hard links for plain_rewritable metadata."
Changelog-revert: 119279 117449 Revert "Print file offsets in the bare fatal stack traces and build the release binary as PIE"
Changelog-revert: 119281 116629 Revert "Check access rights in the TimeSeries table functions"
Changelog-revert: 119298 118606 Revert "Proper partition pruning with dates"
Changelog-revert: 119323 117768 Revert "Docs: Skip private sync for documentation-only pull requests"
Changelog-revert: 119334 117356 Revert "Unify the spill trigger for hash joins"
Changelog-revert: 119429 114562 Revert "Fix NO_SUCH_COLUMN_IN_TABLE naming a column absent from the table when a part's columns were all renamed or all dropped"
Changelog-deleted-entry: 110939 [New Feature] [raw] * Disks with the `plain_rewritable` metadata (`s3_plain_rewritable`, and `azure`/`local` object storages with `metadata_type = plain_rewritable`) support hard links if configured with the new `enable_hard_links` setting, which enables `ALTER` operations and mutations on `MergeTree` tables stored on them. Mutations and partition operations share the unchanged blobs between parts instead of copying them. The setting is off by default, because a disk that has hard links cannot be read by older servers. [#110939](#110939) ([yanglongwei](https://github.com/ylw510)).
Changelog-deleted-entry: 114562 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Fixed `NO_SUCH_COLUMN_IN_TABLE` naming a column that is not in the table, when reading or merging a part whose columns had all been renamed or all dropped by a mutation that was not applied yet. The merge kept being retried, so the table stopped compacting. Also fixed the columns of a `MergeTree` part produced by such a merge reading as their default values until the mutation was applied. [#114562](#114562) ([Shaohua Wang](https://github.com/tiandiwonder)).
Changelog-deleted-entry: 114817 [Performance Improvement] [raw] * Convert `OUTER JOIN` to `INNER JOIN` when a later JOIN condition filters out its NULL-extended rows, and filter NULL join keys directly at the table scan when column statistics show it is selective. Only conditions of the form `expr1` OP `expr2` are considered, where OP is one of `=`, `<`, `<=`, `>`, `>=`. Each side can be a column or an expression that propagates NULLs. Controlled by the new settings `query_plan_derive_not_null_filters_from_joins` (enabled by default), `query_plan_allow_derived_not_null_filters_execution` (enabled by default) and `query_plan_max_selectivity_for_not_null_filters_execution` (0.7 by default). [#114817](#114817) ([Hechem Selmi](https://github.com/m-selmi)).
Changelog-deleted-entry: 115343 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Fixed a `NATS` engine table reading from a JetStream stream (`nats_stream`) silently stopping to consume messages after the NATS server restarted or the connection was re-established. [#115343](#115343) ([Alexey Milovidov](https://github.com/alexey-milovidov)).
Changelog-deleted-entry: 116629 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * The table functions reading a `TimeSeries` table (`timeSeriesSamples`, `timeSeriesTags`, `timeSeriesMetrics`, `timeSeriesSelector`, `prometheusQuery`, `prometheusQueryRange`) checked no privilege on it: a user holding only `CREATE TEMPORARY TABLE` could read its target tables' column definitions and rows, and write into them. Each now requires the corresponding privilege on the `TimeSeries` table and on the target table, following an `Alias` target through to the table it points at. `timeSeriesSamples`, `timeSeriesTags` and `timeSeriesMetrics` check the target at table level, since they return it whole and cannot restrict the columns, so a column-scoped grant on the target is not enough; the other three run ordinary target queries, which the planner still checks per column. An external target is authorized before it is looked up, so its existence is not disclosed either. A read fails with `ACCESS_DENIED` when the user's effective `SELECT` row-policy filter on the `TimeSeries` table is not always true, since such a policy cannot be enforced on the target's rows, and the three target functions can no longer back a `CREATE TABLE ... AS` (`BAD_ARGUMENTS`). PromQL over the Prometheus HTTP and remote-read endpoints reaches `timeSeriesSelector` whenever it selects series, so those requests now need these privileges for the user the endpoint authenticated. [#116629](#116629) ([Groene AI](https://github.com/groeneai)).
Changelog-deleted-entry: 117356 [Backward Incompatible Change] [raw] * `max_bytes_before_external_join` and `max_bytes_ratio_before_external_join` are now the spill threshold for every hash-based `join_algorithm`, including `grace_hash`, which previously ignored them and spilled on `max_rows_in_join` / `max_bytes_in_join` instead. Those two are a hard cap again for every algorithm: they no longer cause spilling, and a join that spills no longer exceeds them. All join algorithms remain available; `join_algorithm = 'grace_hash'` now needs a non-zero spill threshold, and is skipped in favour of the next algorithm in the list when it has none. Set `legacy_join_size_limits_trigger_spilling = 1` (or `compatibility` to 26.8 or older) to restore the previous behavior. [#117356](#117356) ([Yarik Briukhovetskyi](https://github.com/yariks5s)).
Changelog-deleted-entry: 117449 [Build/Testing/Packaging Improvement] [raw] * ClickHouse is now built as a position independent executable on Linux amd64 and aarch64 with glibc, including the release builds, so the text segment is subject to ASLR. Addresses in the bare stack trace of a fatal log are now file offsets relative to the object that contains them, annotated with that object for frames outside the main executable, so they can be resolved with `addr2line -e <object> <hex>` regardless of where the binary was loaded. For the same reason `system.errors.last_error_trace`, `system.error_log.last_error_trace` and `system.crash_log.trace` now store a frame of the main executable as its file offset, keeping runtime addresses for frames in other objects. [#117449](#117449) ([Groene AI](https://github.com/groeneai)).
Changelog-deleted-entry: 117768 [NOT FOR CHANGELOG / INSIGNIFICANT] [raw] * Not applicable. [#117768](#117768) ([Dominic Tran](https://github.com/dhtclk)).
Changelog-deleted-entry: 118218 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Fixed cancelling a distributed, `s3Cluster` or parallel-replicas `SELECT` taking up to `receive_timeout` (300 s by default) to take effect, and never reaching some of the remote sources, when one of them was draining the packets left over after a `LIMIT` was satisfied. [#118218](#118218) ([Groene AI](https://github.com/groeneai)).
Changelog-deleted-entry: 118239 [NOT FOR CHANGELOG / INSIGNIFICANT] [raw] * Require agents to run the style check locally before pushing. [#118239](#118239) ([Nikita Fomichev](https://github.com/fm4v)).
Changelog-deleted-entry: 118606 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Proper partition pruning with dates. Closes [#103433](#103433). [#118606](#118606) ([Konstantin Vedernikov](https://github.com/scanhex12)).
Changelog-deleted-entry: 118919 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Fixed a pending lightweight `DELETE` read with `apply_mutations_on_fly = 1` evaluating its predicate over patch parts created after it, which made rows disappear from the result and reappear after the mutation materialized. [#118919](#118919) ([Alexey Milovidov](https://github.com/alexey-milovidov)).
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 14, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 18, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 18, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 24, 2026
The single conflict is the signature of `ToDateTimeMonotonicity::get`. Master's ClickHouse#118606
moved the `LowCardinality` and `Nullable` unwrapping to the top of the trait, renaming the
type parameter to `type_with_wrappers`; this branch needs the two bound arguments named.
The resolution keeps master's parameter name and this branch's named bounds, so both
changes apply.

The `Date` and `Date32` to `DateTime` conversions are still unfixed on master: its
`which.isDate()` arm keeps claiming strict monotonicity across the day number where the
`UInt32` seconds result wraps.
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 24, 2026
Master's ClickHouse#118606 unwraps `LowCardinality` and `Nullable` at the top of
`ToDateTimeMonotonicity::get`, so the window check no longer needs to unwrap the source
type itself.
alexey-milovidov added a commit that referenced this pull request Sep 26, 2026
Resolve the cherry-pick of #119302 against 26.3. The original #118606 was
never backported to 26.3 (its backport #119251 was closed after the revert),
so this is effectively the full backport of the Iceberg partition pruning:

- `ManifestListPruning.cpp` does not exist on 26.3 (there is no manifest
  list pruning there), so its part of the reland, which fixed the pre-1970
  bound bug in `ManifestListPruner`, is dropped.
- `IcebergFieldParseHelpers` stays as on 26.3: the new
  `deserializeDecimalFromBinaryRepr` is only used by the decimal partition
  decoding and `ManifestListPruner`, neither of which exists on 26.3.
- `FunctionsConversion.h`, `ManifestFile.h` (`tuple_index`),
  `ManifestFileIterator.cpp` and `ManifestFilesPruning.cpp` take the 26.3
  adaptation from the earlier backport #119251, with the helpers in
  `ManifestFilesPruning.cpp` updated to the form of the reland.
- The tests come from the reland; `05054` there extracts only the
  `Granules: N/M` part of `EXPLAIN`, which is what failed on #119251.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
alexey-milovidov added a commit that referenced this pull request Sep 26, 2026
Resolve the conflicts of the cherry-pick of #119302 to 26.7.

26.7 had the original backport of #118606 merged and then reverted
(#119253, #119431), so the resolution reapplies that 26.7 backport
(reverts `d10ac36aeab8`) and then applies the follow-up commits of #119302
on top of it.

26.7 has no `ManifestListPruning.cpp` (manifest-list level pruning is not
on this branch), so the hunks of #119302 for that file are dropped, and
with them the `deserializeDecimalFromBinaryRepr` refactoring of
`213367fdc76a`, which only existed to share the decimal decoding with that
file; 26.7 keeps its own `decodePartitionDecimalByType`. The
`ManifestFilesPruning.cpp` interval helpers, the `05054` test and the
`test_partition_pruning_with_functions.py` integration test match master.

Related: #119302

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
alexey-milovidov added a commit that referenced this pull request Sep 26, 2026
Resolve the cherry-pick of #119302
onto 26.8. The resolution starts from the earlier 26.8 backport of
#118606 (ff6b795), which
already adapted `FunctionsConversion.h` and `ManifestFilesPruning.cpp` to 26.8,
and then applies the follow-up commits of the reland that touch those files
(323a197, bad2875, 9bb3a34) plus the updated tests.

Dropped, because 26.8 does not have the code they modify:
- `ManifestListPruning.cpp` (manifest-list pruning is not on 26.8), which carried
  the pre-1970 summary-bound fix of 039006e;
- the `deserializeDecimalFromBinaryRepr` helper of 213367f in
  `IcebergFieldParseHelpers`: that commit only deduplicated the decimal decoding,
  26.8 keeps the equivalent local `decodePartitionDecimal` in
  `ManifestFilesPruning.cpp`;
- the `getPreimage` of `ToDateMonotonicity`, which is master-only.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg Partition Pruning not properly working with toDate function

6 participants