Skip to content

Enable metadata-only MIN/MAX from Iceberg manifest column bounds (e.g., MAX(updated_at))#1173

Open
The-Alchemist wants to merge 3 commits into
duckdb:mainfrom
The-Alchemist:feature/min-max-for-sorted-columns
Open

Enable metadata-only MIN/MAX from Iceberg manifest column bounds (e.g., MAX(updated_at))#1173
The-Alchemist wants to merge 3 commits into
duckdb:mainfrom
The-Alchemist:feature/min-max-for-sorted-columns

Conversation

@The-Alchemist

@The-Alchemist The-Alchemist commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Wire get_partition_stats to expose per-column min/max from manifest data_file.lower_bounds / upper_bounds via a new IcebergPartitionRowGroup, so DuckDB's StatisticsPropagator::TryExecuteAggregates can fold SELECT MIN(col) / SELECT MAX(col) into constants without scanning Parquet.
  • Exact fold for numeric/temporal types only (not FLOAT/DOUBLE/VARCHAR); bail out when any file lacks usable bounds or matching delete manifests are present.
  • Uses manifest column bounds, not Iceberg partition-statistics files (those carry counts/sizes only, no per-column min/max). Independent of Pb/iceberg partitioning aware cardinality estimation #1023 (copies a leaner IcebergPartitionRowGroup focused on min/max; reconcile if both land).

Test plan

  • test/sql/local/iceberg_scans/aggregate_min_max_metadata.test — correctness vs oracle, EXPLAIN shows COLUMN_DATA_SCAN for bigint/timestamp folds, fallbacks for varchar/float/WHERE; verify nested type behavior
  • test/sql/local/iceberg_scans/scan_order_limit_pruning.test still passes

@The-Alchemist The-Alchemist changed the title Enable metadata-only MIN/MAX from Iceberg manifest column bounds Enable metadata-only MIN/MAX from Iceberg manifest column bounds (e.g., MAX(last_updated)) Jul 12, 2026
Expose exact numeric/temporal lower/upper bounds via PartitionRowGroup so
StatisticsPropagator can fold SELECT MIN/MAX without scanning data files.
@The-Alchemist
The-Alchemist force-pushed the feature/min-max-for-sorted-columns branch from 30e6cbe to 513a293 Compare July 12, 2026 02:23
Comment thread src/planning/iceberg_multi_file_list.cpp
@The-Alchemist The-Alchemist changed the title Enable metadata-only MIN/MAX from Iceberg manifest column bounds (e.g., MAX(last_updated)) Enable metadata-only MIN/MAX from Iceberg manifest column bounds (e.g., MAX(updated_at)) Jul 13, 2026
@The-Alchemist
The-Alchemist marked this pull request as ready for review July 13, 2026 17:08
Signed-off-by: Karl Pietrzak <karl@medplum.com>
//! Materialize data-file entries so column bounds are available for MIN/MAX.
idx_t materialized = 0;
while (GetDataFile(materialized, guard)) {
materialized++;

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.

I'm worried this happens before filter pushdown, in which case we are now aggressively materializing all metadata, which is not ideal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point. my latest commit delays materialization until necessary, although that increases the complexity

@The-Alchemist
The-Alchemist force-pushed the feature/min-max-for-sorted-columns branch from 95874aa to bebfef4 Compare July 15, 2026 18:28
…ted.

GetStatistics still supplies manifest-level counts for COUNT(*), but only
drains matching data files when GetColumnStatistics needs bounds.
@The-Alchemist
The-Alchemist force-pushed the feature/min-max-for-sorted-columns branch from bebfef4 to 7b5c5ca Compare July 15, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants