Skip to content

Lazy-load part-level column statistics - #114610

Closed
zoomxi wants to merge 1 commit into
ClickHouse:masterfrom
zoomxi:statistic-lazy-part-only
Closed

zoomxi wants to merge 1 commit into
ClickHouse:masterfrom
zoomxi:statistic-lazy-part-only

Conversation

@zoomxi

@zoomxi zoomxi commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

When loading a part's statistics, the part currently loads statistics for every column via getEstimates, even when only a few columns are needed. On wide tables this performs a lot of pointless deserialization.

Related: #104691

This change makes per-part statistics load lazily, only for the requested columns:

  • IMergeTreeDataPart::getEstimates now takes the set of requested columns, loads only the missing ones, and caches the result per column. A deterministic miss (no statistics declared, file absent, or corrupted) is recorded as a nullopt entry so the column is not re-probed on every query.
  • Part pruning asks for only the filter columns: StatisticsPartPruner exposes getCandidateColumns and filterPartsByStatistics passes them to getEstimates.
  • system.parts_columns discovers which columns have statistics via the new getColumnsWithStatistics and loads only those.

A new LoadedStatisticsColumns profile event counts the per-column statistics that are actually deserialized.

The performance test measures a 100-column wide table with 50 parts and a query filtering on 3 columns; part pruning loads 150 columns instead of 5000.

Changelog category (leave one):

  • Performance Improvement

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

Part-level column statistics are now loaded lazily, only for the columns that are actually needed, reducing statistics deserialization on wide tables.

@zoomxi

zoomxi commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor Author

@hanfei1991 Would you mind taking a look? Thanks.

@rschu1ze rschu1ze added the hold Skip for auto-updating. label Aug 13, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 4, 2026
@alexey-milovidov alexey-milovidov removed the hold Skip for auto-updating. label Oct 24, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

@zoomxi, the whole statistics implementation was wrong, see #120758
Now as it is rewritten, you can continue on this PR.

@alexey-milovidov

Copy link
Copy Markdown
Member

I'm also working on these improvements:
#126627
#126625
#126621

@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Nov 14, 2026
@zoomxi

zoomxi commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@zoomxi, the whole statistics implementation was wrong, see #120758 Now as it is rewritten, you can continue on this PR.

@alexey-milovidov Sorry for the late reply. I looked at the current implementation, and it already covers what this PR was aiming for: column statistics are loaded on demand, only for the columns that are actually needed.

I'll close this PR.

@zoomxi zoomxi closed this Nov 18, 2026
@zoomxi
zoomxi deleted the statistic-lazy-part-only branch November 19, 2026 03:53
@clickhouse-gh clickhouse-gh Bot added comp-statistics Column statistics: statistics kept per part on a column (tdigest, uniq, count-min sketch, minmax)... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 22, 2026
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 comp-statistics Column statistics: statistics kept per part on a column (tdigest, uniq, count-min sketch, minmax)... external Author is not a member of the ClickHouse organization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants