Skip to content

apply predicate to iceberg_history table - #108492

Merged
Diskein merged 1 commit into
masterfrom
dk-iceberg-history-push-down
Jun 26, 2026
Merged

Diskein merged 1 commit into
masterfrom
dk-iceberg-history-push-down

Conversation

@Diskein

@Diskein Diskein commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Filter the database and table columns through the query predicate
before opening any tables, so that querying system.iceberg_history
with a WHERE database = ... / table = ... condition no longer
iterates every table in every database.

Databases are filtered first, before listing their tables, so a
predicate on database avoids opening connections to remote databases
(PostgreSQL/MySQL/...) whose tables are irrelevant to the query.

Adds the getFilterSampleBlock override and threads the
ActionsDAG::Node * predicate into fillData, applying it via
VirtualColumnUtils::filterBlockWithPredicate.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Changelog category (leave one):

  • Improvement

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

If you provide WHERE with table and database filters then system.iceberg_history will list only matched databases. It can save some time if you have many non-related remote databases on the server.

Version info

  • Merged into: 26.7.1.105

Filter the `database` and `table` columns through the query predicate
before opening any tables, so that querying `system.iceberg_history`
with a `WHERE database = ...` / `table = ...` condition no longer
iterates every table in every database.

Databases are filtered first, before listing their tables, so a
predicate on `database` avoids opening connections to remote databases
(PostgreSQL/MySQL/...) whose tables are irrelevant to the query.

Adds the `getFilterSampleBlock` override and threads the
`ActionsDAG::Node * predicate` into `fillData`, applying it via
`VirtualColumnUtils::filterBlockWithPredicate`.

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

clickhouse-gh Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7973ab5]

Summary: ✅


AI Review

Summary

This PR pushes database/table filtering into system.iceberg_history so queries with predicates should avoid scanning unrelated Iceberg tables. The direction is good, but the current implementation still opens every table in a matched data lake catalog database before the table predicate is applied, so the main contract is not met yet.

Findings

⚠️ Majors

  • [src/Storages/System/StorageSystemIcebergHistory.cpp:170] table predicates are applied after getTablesIterator, but DatabaseDataLake::getTablesIterator already calls tryGetTableImpl for every table that passes its name filter. Since this call passes no name filter, WHERE database = 'db' AND table = 't' still fetches metadata for every table in db before line 181 filters the names. Push the database/table predicate into name enumeration before constructing full storages, for example by using lightweight table names and then calling getTablesIterator with a restricted filter_by_table_name.
Tests
  • ⚠️ Add focused coverage proving that system.iceberg_history with WHERE database = ... AND table = ... does not open/fetch metadata for unrelated tables in a data lake catalog database. A failpoint-based test around the lightweight/full table lookup boundary would be enough.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: make the table predicate take effect before full table storage construction for catalog databases, and add focused coverage for that behavior.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jun 25, 2026
@Diskein
Diskein marked this pull request as ready for review June 25, 2026 16:00
@clickhouse-gh

clickhouse-gh Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 60/69 (86.96%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@asya-ch asya-ch self-assigned this Jun 26, 2026
@Diskein
Diskein enabled auto-merge June 26, 2026 12:45
@Diskein
Diskein added this pull request to the merge queue Jun 26, 2026
Merged via the queue into master with commit 2dac771 Jun 26, 2026
329 of 330 checks passed
@Diskein
Diskein deleted the dk-iceberg-history-push-down branch June 26, 2026 13:27
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 26, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ry-push-down

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

Labels

pr-improvement Pull request with some product improvements 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.

3 participants