Skip to content

Feature: Paimon minmax index - #100160

Closed
JiaQiTang98 wants to merge 52 commits into
ClickHouse:masterfrom
JiaQiTang98:paimon-minmax-index
Closed

JiaQiTang98 wants to merge 52 commits into
ClickHouse:masterfrom
JiaQiTang98:paimon-minmax-index

Conversation

@JiaQiTang98

@JiaQiTang98 JiaQiTang98 commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Experimental Feature

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

Supports Paimon min-max index pushdown by setting use_paimon_minmax_index_pruning=1

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@clickhouse-gh

clickhouse-gh Bot commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [54f7da6]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_debug, parallel) FAIL
04357_distributed_alias_same_expression FAIL cidb

AI Review

Summary

This PR adds experimental Paimon per-file min/max pruning, wires it through the current PaimonMetadata read paths, regenerates the fixture to cover the previously identified edge cases, and documents the current support boundary from the table-function source. I re-checked the current diff against the prior discussion and did not find a remaining correctness, safety, or evidence gap that still warrants a new review finding.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.10% 79.00% -0.10%

Changed lines: Changed C/C++ lines covered: 238/298 (79.87%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Mar 20, 2026
@JiaQiTang98
JiaQiTang98 marked this pull request as draft March 20, 2026 09:30
@JiaQiTang98
JiaQiTang98 marked this pull request as ready for review March 20, 2026 10:45
Comment thread src/Core/Settings.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

…onPushDown

`master` made the third `boolean_context` argument of
`ActionsDAGWithInversionPushDown` mandatory (call site updated for the
existing `PartitionPruner` in 7af3639). The new `MinMaxIndexPruner`
also builds an inverted DAG to analyze a `WHERE`/`PREWHERE` predicate over
the per-file min/max stats, which is a filter (truthiness) context, so it
passes `boolean_context = true` to match the partition pruner and benefit
from the truthiness-preserving rewrites.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Pushed two updates (46bebf84142..cb5dae99b1f):

  1. Fixed the 04051_paimon_minmax_pruning "Test runs too long (> 180s)" failure (the only real CI failure, in the amd_asan_ubsan flaky check). After the edge-case columns were added, the test issued each of its ~27 queries (plus a SELECT '===' separator) in its own clickhouse-client process, so the per-process startup cost dominated and the run reached ~200s. The queries now run in a single clickhouse-client invocation, with a per-query log_comment so the file-count check still attributes EngineFileLikeReadFiles correctly. The reference output is unchanged — verified byte-for-byte (rows and the 27 file-count values) by replaying the queries through paimonLocal against a local server.

  2. Merged master and adapted to the now-mandatory boolean_context argument of ActionsDAGWithInversionPushDown (made required in 7af3639a667). MinMaxIndexPruner analyzes a WHERE/PREWHERE predicate over the per-file min/max stats — a filter context — so it passes /* boolean_context */ true, matching PartitionPruner (this is the build issue the AI review flagged; it is fixed in cb5dae99b1f). All four Paimon translation units compile cleanly against the merged tree. The merge also picks up Let 03518_alter_logical_race extend its budget when no progress is made #108003, which fixes the unrelated 03518_alter_logical_race flake seen in the previous run.

Previous CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100160&sha=46bebf84142c1326d976662338f7ac20560205fa&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29

…ry section

After merging master, the in-progress version advanced to 26.7 and a new
`26.7` block was added to `SettingsChangesHistory.cpp`. The new
`use_paimon_minmax_index_pruning` setting introduced by this PR was still
listed under the now-released `26.6` block; since the PR will ship in 26.7,
its history entry belongs in the 26.7 block (matching the existing convention
of recording a new setting under the in-progress version).
alexey-milovidov and others added 2 commits July 7, 2026 02:56
…t run

Address review: the per-query file-count check summed
`ProfileEvents['EngineFileLikeReadFiles']` over all `system.query_log` rows
whose `log_comment` matched `CLICKHOUSE_TEST_UNIQUE_NAME`. That name is derived
only from the test name plus the database, so a local rerun against the same
server/database left stale rows matching the filter and doubled the reference
counts even when pruning was correct.

Append a per-run random suffix to the `log_comment` token so the query-log
filter matches only this invocation. The suffix is identical for every query in
the run, so `ORDER BY log_comment` and the reference output are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…de too

The dense `_VALUE_STATS_COLS` path in `MinMaxIndexPruner::canBePruned`
matched a file's value stats to a query column by name, which correctly
locates the stats slot, but then decoded the bytes with the *current*
schema's `DataType`. That is unsafe under Paimon schema (type) evolution:
a change that preserves a column name while changing its physical encoding
- e.g. widening `DECIMAL(10, 0)` to `DECIMAL(20, 0)`, which switches
`getFieldFromBinaryRow` from the fixed-size to the varlen decode path -
makes an older file's stats be misread into a wrong bound, so a file that
still contains matching rows could be falsely pruned (or the decode could
throw).

The legacy (positional) path already fails closed on
`file.schema_id != schema_id`; extend that same guard to the dense path so
min/max pruning is skipped for any file whose `schema_id` differs from the
one this pruner was built from (such files are read in full, which is
always correct). For tables that never evolved, every file carries the
current `schema_id`, so pruning is unchanged.

Addresses the AI review blocker on
`src/Storages/ObjectStorage/DataLakes/Paimon/PartitionPruner.cpp`.
alexey-milovidov and others added 2 commits July 21, 2026 21:39
The generator caught `Catalog.TableAlreadyExistException` and reused the
existing `tests.paimon_minmax_test` table, so re-running the documented
regeneration command against an existing warehouse appended three more
batches/snapshots instead of rebuilding the canonical 3-file fixture (and
could inherit a stale schema from an older generator version). Drop the
table first (`ignoreIfNotExists=true`) and recreate it from scratch, so
the committed fixture can be regenerated reproducibly.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Reconcile with master's PaimonMetadata refactor. Resolved conflicts:
- PaimonMetadata.cpp: kept both the PR's `use_paimon_minmax_index_pruning`
  and master's `use_paimon_metadata_files_cache` Setting externs.
- PaimonMetadata.h: master dropped `using namespace Paimon` and qualified
  `Paimon::PartitionPruner`; threaded the `minmax_pruner` parameter
  (qualified `Paimon::MinMaxIndexPruner`) into collectDataFilesFromManifests,
  collectIncrementalDataFiles, collectDeltaFilesForSnapshot and
  collectFullScanDataFiles to match the merged .cpp definitions.
@alexey-milovidov

Copy link
Copy Markdown
Member

Picked up the PR: merged the latest master (the branch was ~4800 commits / ~1 week behind) and addressed the open AI Review "Request changes" thread.

Merge / conflict resolution

master had refactored PaimonMetadata again. Resolved the two conflicts:

  • PaimonMetadata.cpp — kept both the PR's use_paimon_minmax_index_pruning and master's new use_paimon_metadata_files_cache Setting externs. The min-max integration through collectDeltaFilesForSnapshot / collectIncrementalDataFiles / collectFullScanDataFiles / collectDataFilesFromManifests merged cleanly with master's read-path refactor.
  • PaimonMetadata.h — master dropped using namespace Paimon and now qualifies Paimon::PartitionPruner; I threaded the minmax_pruner parameter (qualified Paimon::MinMaxIndexPruner) into all four collector declarations so they match the merged .cpp definitions.

The use_paimon_minmax_index_pruning entry is in the 26.7 SettingsChangesHistory block (the current in-progress version). The PR diff introduces zero submodule/contrib changes versus master.

Review thread

  • PaimonMinmaxTestGenerator.java regeneration is not idempotent — fixed: the generator now drops the target table first (catalog.dropTable(tableId, /*ignoreIfNotExists=*/ true)) and recreates it from scratch, so re-running the documented regeneration command rebuilds the canonical 3-file fixture deterministically instead of appending extra snapshots.

Verification

Built all nine Paimon translation units against the merged tree on ARM — they compile cleanly with no warnings or errors. The committed fixture and 04051_paimon_minmax_pruning reference output are unchanged (the Java change only affects manual regeneration).

…ettings history entry to 26.8

The new `MinMax index pruning` docs section read as if pruning applies to
any Paimon column, but `canDecodeMinMaxStats` intentionally skips several
types - most notably `TIMESTAMP(p)` / `TIMESTAMP WITH LOCAL TIME ZONE(p)`
with `p > 3`, which includes Paimon's default `p = 6` when the precision is
omitted. A user could therefore enable `use_paimon_minmax_index_pruning` on
a table with a plain `TIMESTAMP` column and assume pruning was active while
it was silently disabled for that column. Document the supported type list
and the two other cases where a file is never pruned (non-zero or unknown
null count, and a file written under an older schema).

Also move the `use_paimon_minmax_index_pruning` entry in
`SettingsChangesHistory.cpp` from the released `26.7` block to `26.8`, the
version currently in progress, and give it a real description.
@alexey-milovidov

Copy link
Copy Markdown
Member

Picked up the PR again: merged the latest master and addressed the remaining AI Review nit.

Merge

The branch was ~2994 commits / about a week behind. This time master did not conflict with the Paimon sources — the merge (71ac9905fdc) was clean. All nine Paimon translation units compile against the merged tree with no warnings or errors, and the three external APIs this code depends on are unchanged: ActionsDAGWithInversionPushDown(node, ctx, /*boolean_context*/ true), KeyCondition(inverted_dag, ctx, names, expr, single_point), and KeyDescription::getKeyFromAST(ast, cols, {}, ctx). The PR diff still introduces zero submodule/contrib changes versus master (the submodule changed label is stale).

I also moved the use_paimon_minmax_index_pruning entry in SettingsChangesHistory.cpp from the now-released 26.7 block to 26.8, the version currently in progress, and replaced the placeholder "New setting." text with a real description.

Review thread

[docs/en/sql-reference/table-functions/paimon.md:124] Document the min-max pruning support boundary — fixed. The section read as if pruning applied to any Paimon column, while canDecodeMinMaxStats intentionally skips several types. A new Supported column types subsection now lists the accepted types and calls out explicitly that TIMESTAMP(p) / TIMESTAMP WITH LOCAL TIME ZONE(p) with p > 3 is not pruned — which includes Paimon's default p = 6 when the precision is omitted, so enabling the setting does not speed up predicates on a plain TIMESTAMP column. While there I documented the two other silent no-prune cases as well: a non-zero or unknown null count for the column, and a data file written under an older schema_id than the current table schema.

CI

All three red jobs on the previous head were unrelated to Paimon, and two of them are already fixed on master, so the merge above should clear them:

@groeneai, could you investigate #110133 (the 03915_exchange_tables_race / EXCHANGE TABLES race) and provide a fix in a separate PR? It is still open and shows up as a blocker on unrelated PRs. If a fix is already in progress, please link it there.

@groeneai

Copy link
Copy Markdown
Collaborator

Investigated. No separate fix is needed: #110133 is already fixed on master by your own #110048, and the red on this PR is base staleness rather than a live bug. I have linked the one still-open PR for the signature on the issue: #110133 (comment)

The blocking log_check entry came from 85a44448, which is 1474 commits behind the #110048 merge (2bf30333). I checked content rather than dates: Context.cpp at 85a44448 has no dropStorageCacheEntry and none of the storage-cache pinning comments, and at the current head e2098991 it has both. So that job never ran the fix.

Since the merge: 22166 runs of 03915_exchange_tables_race across 1959 commits with 0 FAIL/ERROR, and on the exact failing shard (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, WasmEdge, parallel, 2/3) 1163 runs, 1162 OK, 0 FAIL/ERROR, so the test is still running and green rather than silently skipped. The Arguments of 'multiply' have incorrect data types phrase had 120 hits over 95 PRs and 8 master events before the merge and 0 after.

Your master merge at 71ac9905 brought the fix onto this branch, so the coverage shard should come back green on e2098991. It has not reported yet: of the check-runs registered on that head so far, 0 are failing and no stateless coverage job is among them. Worth noting the issue carries no CI action or Failure flags metadata, so while it stays open its matches are not auto-ignored and it will keep blocking any PR whose base predates the merge. Closing it would stop that.

The still-open #109747 is unrelated to this PR's red. It stops the planner aborting the server on any argument-type mismatch during partial-result evaluation, instead of only removing the one way #110048 produced that mismatch.

@clickhouse-gh

clickhouse-gh Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.40% 86.30% -0.10%
Functions 91.90% 91.90% +0.00%
Branches 78.50% 78.50% +0.00%

Changed lines: Changed C/C++ lines covered: 189/229 (82.53%) · Uncovered code

Full report · Diff report

`master` moved the documentation from the Docusaurus tree under
`docs/en/**/*.md` to the Mintlify tree at `docs/**/*.mdx`, deleting every
file this branch edits. The edits are replayed at the new paths:

- `docs/en/sql-reference/table-functions/paimon.md` -> `docs/reference/functions/table-functions/paimon.mdx`
@clickhouse-gh

clickhouse-gh Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 54f7da683 with master 809fc9a43 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of a63b5b574; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 692.03 MiB 689.05 MiB -2.98 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

9 object files changed (+96.78 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Paimon/PartitionPruner.cpp.o 105.80 KiB 190.93 KiB +85.13 KiB (+80.46%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

34 translation units recompiled, 391 s compile time in total, 34 of them have a recent master baseline.

Job report

…runing docs to the source registration

Two review findings on the Paimon min-max index pruning.

**Legacy positional value statistics.** A data file whose value statistics carry
no `_VALUE_STATS_COLS` column list can only be addressed positionally, and
`MinMaxIndexPruner::canBePruned` assumed that stats position `i` always
describes table schema field `i`. That assumption breaks for a file written with
a projected write schema - for example write columns `[f0, f2]` of a table whose
schema is `[f0, f1, f2]` - where a predicate on `f1` would read `f2`'s bounds and
`mayBeTrueInRange` could prune a file that still contains matching rows. Checking
`file.schema_id == schema_id` does not cover this, because a projected write
schema is a projection *of the current schema*.

A projection is a subset of the schema, so it is detectable by its cardinality: a
statistics row that covers every field must be the full schema, in schema order.
`legacyValueStatsArePositional` now requires the arity encoded in the `BinaryRow`
header of both the min and the max row, and the length of the parallel
`_NULL_COUNTS` array, to agree with the number of schema fields; otherwise
pruning is skipped for that file and the file is read in full, which is always
correct. The same length agreement is now also required between
`_VALUE_STATS_COLS` and the statistics rows in the dense path, so a position
derived from the column list can never address past the row.

`BinaryRow::getArity` is added for this - the arity is stored in the row header
and is the only self-describing part of the layout.

The committed `paimon_minmax_test` fixture takes the legacy path (its
`_VALUE_STATS_COLS` is an empty array) and its statistics rows have arity 10 for
a 10-field schema, so `04051_paimon_minmax_pruning` is unaffected. The new
`gtest_paimon_minmax_stats_layout` covers the rejected layouts, including the
projected-write-schema case, plus the `BinaryRow` arity accessor.

**Docs.** The `Partition pruning` / `MinMax index pruning` sections had been
added directly to `docs/reference/functions/table-functions/paimon.mdx` inside
its `AUTOGENERATED_START` / `AUTOGENERATED_END` region, which keeps the
`Docs check (Mintlify)` job red on `No direct edits to generated or read-only
docs`. They are moved to the table function registration text in
`TableFunctionObjectStorage.cpp`, which is the source the page is generated
from, and the generated page is reverted to its `master` content. While moving
them, the list of cases in which a file is never pruned gained the new legacy
statistics layout case.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Picked up the PR again: merged the latest master, fixed the AI Review blocker in the legacy positional statistics path, and moved the pruning docs out of the generated Mintlify page.

Merge

The branch was ~3485 commits behind. The merge was clean - master did not touch the Paimon sources this time - and there is no submodule drift (git submodule status | grep -c '^+' is 0). The use_paimon_minmax_index_pruning entry in SettingsChangesHistory.cpp is still in the 26.8 block, which is the version currently in progress (Will build ClickHouse 26.8.1.1), so it did not need moving.

Blocker: legacy positional value statistics

First, a correction to the finding's premise: the committed paimon_minmax_test fixture does not write dense _VALUE_STATS_COLS. Its _VALUE_STATS_COLS is an empty array, so 04051_paimon_minmax_pruning exercises the legacy positional branch, not the dense one:

$ clickhouse local --query "SELECT length(_FILE._VALUE_STATS_COLS), length(_FILE._VALUE_STATS._NULL_COUNTS),
      reinterpretAsUInt32(reverse(substring(_FILE._VALUE_STATS._MIN_VALUES, 1, 4)))
   FROM file('.../manifest/manifest-8672c03f-...-0', Avro)"
0	10	10

The reported hole is real, though: file.schema_id == schema_id does not rule out a file written with a projected write schema, because such a projection is a projection of the current schema. With write columns [f0, f2] of a table [f0, f1, f2], a predicate on f1 would read f2's bounds and mayBeTrueInRange could prune a file that still contains matching rows.

I fixed it by making the layout self-check rather than by plumbing a write-column mapping through PaimonManifestEntry::DataFileMeta. A projection is a subset of the schema, so it is detectable by its cardinality: a statistics row that covers every field must be the full schema, in schema order. The new legacyValueStatsArePositional requires the arity encoded in the BinaryRow header of both the min and the max row, and the length of the parallel _NULL_COUNTS array, to agree with the number of schema fields. Anything else fails closed - min-max pruning is skipped and the file is read in full, which is always correct. This is the same fail-close shape as the existing schema_id guard.

The same length agreement is now also required in the dense path between _VALUE_STATS_COLS and the statistics rows, so a position derived from the column list can never address past the row.

BinaryRow::getArity was added for this: the arity lives in the row header and is the only self-describing part of the layout.

I chose this over the "fail closed whenever _VALUE_STATS_COLS is absent" option precisely because of the correction above - that option would have disabled pruning for the entire tested path and for every table written by a Paimon version that does not emit the column list, rather than only for the unsafe layout.

Tests. The fixture's statistics rows have arity 10 for a 10-field schema (schema-0 has 10 fields, no partition keys), so the guard admits them and 04051_paimon_minmax_pruning is unchanged. The rejected layouts are covered by the new src/Storages/ObjectStorage/DataLakes/Paimon/tests/gtest_paimon_minmax_stats_layout.cpp: the projected-write-schema case (arity 2 against a 3-field schema), the too-many-columns case, _NULL_COUNTS disagreeing with the row in either direction, a malformed negative arity, plus the BinaryRow arity accessor itself. All Paimon unit tests pass locally:

[----------] 2 tests from PaimonMinMaxStatsLayout
[       OK ] PaimonMinMaxStatsLayout.BinaryRowExposesArity (0 ms)
[       OK ] PaimonMinMaxStatsLayout.LegacyStatsArePositionalOnlyForTheFullSchema (0 ms)
[  PASSED  ] 6 tests.

A .sql-level negative fixture would need a hand-written Paimon Avro manifest with a projected legacy statistics row, which no Paimon writer produces on demand; the unit test covers the same decision without inventing a fixture that could drift from the real format.

Nit: docs edited inside the generated region

Correct - the Partition pruning / MinMax index pruning sections were inside the AUTOGENERATED_START / AUTOGENERATED_END region of docs/reference/functions/table-functions/paimon.mdx, which is what kept Docs check (Mintlify) red on No direct edits to generated or read-only docs. They now live in the table function registration text in src/TableFunctions/TableFunctionObjectStorage.cpp, which is the source the page is generated from, and the generated page is reverted to its master content. While moving them I turned the trailing paragraph into a When a file is never pruned subsection and added the new legacy-statistics-layout case to it.

CI

The one remaining red job besides the docs check is Stress test (amd_debug) on Logical error: Next task callback is not set for query A (STID: 4567-5424). That is unrelated to Paimon: it is the plan-based parallel replicas issue #111677, and a fix is already in progress in #114022.

Verification

PartitionPruner.cpp, TableFunctionObjectStorage.cpp and the new unit test compile clean on ARM with no warnings, and unit_tests_dbms links and passes.

@JiaQiTang98

Copy link
Copy Markdown
Contributor Author

This PR suggests redesigning after #112702 is completed. Should this RFC prove feasible, the current PR will not be required.
So close it now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-experimental Experimental Feature submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants