Skip to content

Packed format for statistics - #93414

Merged
CurtizJ merged 52 commits into
ClickHouse:masterfrom
CurtizJ:statistics-compact-format
Feb 14, 2026
Merged

CurtizJ merged 52 commits into
ClickHouse:masterfrom
CurtizJ:statistics-compact-format

Conversation

@CurtizJ

@CurtizJ CurtizJ commented Jan 5, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Backward Incompatible Change

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

Improved storage format of statistics. All statistics are now stored in a single file.

Version info

  • Merged into: 26.2.1.674

@clickhouse-gh

clickhouse-gh Bot commented Jan 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [88fd122]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan, targeted) error IGNORED

@clickhouse-gh clickhouse-gh Bot added the pr-backward-incompatible Pull request with backwards incompatible changes label Jan 5, 2026
@CurtizJ
CurtizJ force-pushed the statistics-compact-format branch from 595ee45 to 4e627a6 Compare January 5, 2026 15:52
@EmeraldShift

EmeraldShift commented Jan 5, 2026 •

Copy link
Copy Markdown
Contributor

I recall a pain point for some data warehouses based on Parquet is that the Parquet statistics (per file, and per row-group) are compact, and require parsing in their entirety just to extract the statistics for a single column of interest. Does this packed format's design allow partial reads, that would mitigate such a bottleneck?

@CurtizJ

CurtizJ commented Jan 5, 2026

Copy link
Copy Markdown
Member Author

@EmeraldShift

Yes, a packed format will allow partial reads.

P.S.: current format in this PR is a temporary placeholder and will be changed.

@CurtizJ
CurtizJ force-pushed the statistics-compact-format branch from 06c0325 to 6970fcc Compare February 3, 2026 18:28
@CurtizJ
CurtizJ force-pushed the statistics-compact-format branch from 6970fcc to 8451337 Compare February 3, 2026 18:44
@alesapin alesapin self-assigned this Feb 12, 2026

@alesapin alesapin left a comment

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.

LGTM

{
auto block = getInputPort().getHeader().cloneWithColumns(chunk.getColumns());
ProfileEventTimeIncrement<Microseconds> watch(ProfileEvents::MergeTreeDataWriterStatisticsCalculationMicroseconds);
statistics_to_build.buildIfExists(block);

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.

Do I understand correctly that we always have statistic only for a single column and that is why this code works for Vertical Merge? Looks like semantically nothing prevents from calculating Uniq of pair of columns, by I guess we don't plan to have such feature.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes.


/// Helper class, which holds chain of buffers to write data file with marks.
/// It is used to write: one column, skip index or all columns (in compact format).
template<bool only_plain_file>

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.

What was only_plain_file?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It meant "do not write file with marks" and was used only for statistics.

return rename_vector;
}

static void processStatisticsChanges(

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.

Sorry, I cannot validate this function.

/// Buffer chain: plain_file <- plain_hashing <- compressor <- compressed_hashing
auto plain_file = data_part_storage.writeFile(filename, 4096, write_settings);
HashingWriteBuffer plain_hashing(*plain_file);
CompressedWriteBuffer compressor(plain_hashing, compression_codec, 1024 * 1024);

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.

This guy already add checksum for each block. I don't understand why we store such files in checksums.txt.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it may be redundant for the compressed files, but we use checksums as map with files to bypass access to filesystem in many places.


readIntBinary(rows, buf);
std::vector<StatisticsType> stat_types;
for (size_t i = 0; i < static_cast<UInt8>(StatisticsType::Max); ++i)

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.

overcomplicated serde, but okay

@CurtizJ
CurtizJ added this pull request to the merge queue Feb 14, 2026
Merged via the queue into ClickHouse:master with commit 5fe22f3 Feb 14, 2026
130 of 131 checks passed
@CurtizJ
CurtizJ deleted the statistics-compact-format branch February 14, 2026 20:57
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 14, 2026
alexey-milovidov added a commit that referenced this pull request Feb 15, 2026
…mat"

This reverts commit 5fe22f3, reversing
changes made to d8b3bc1.
@alexey-milovidov alexey-milovidov mentioned this pull request Sep 20, 2026
47 of 72 tasks
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Nov 13, 2026
…ed as paths, two readings of one input

Blind reviews of the pull requests that introduced nine bugs fixed later (ported in ClickHouse#131294-ClickHouse#131302) showed these gaps:
- Data the server wrote itself and reads back (parts, patch parts, packed-file indexes, `ssd_cache` files) was
  treated as trusted, so out-of-bounds reads on it were dismissed or rated as Nits (ClickHouse#126553, ClickHouse#116007, ClickHouse#86095).
- No prompt for overflow of sizes computed from user-controlled counts (`ColumnString::replicate`, ClickHouse#61075).
- No prompt for names read from data that become paths (packed archive index, ClickHouse#93414).
- A security check that reads its input differently from the consumer (first vs last repeated key, Boolean
  spellings), which the real review of ClickHouse#106855 missed.
Also ask for a separate pass over parsers and security decisions in large pull requests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backward-incompatible Pull request with backwards incompatible changes 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.

5 participants