Repository navigation
Conversation
A sparse column whose values files are all empty in the part's checksums has no value that is not the default: every non-default value writes at least one byte to them. Reading such a column still created a stream per file (marks load, open and a read buffer for the offsets file and for each empty values file) and decoded its offsets, once per column per reader. On wide tables with many such columns this dominated point lookups, top-N queries, full scans and merges. `MergeTreeReaderWide::addStreams` now creates no streams for a top-level sparse column (not a subcolumn) that has all its streams in the part and only empty values files, and `readSegmentFromDisk` appends the defaults itself: as many rows as reading the offsets would give, from the mark the read seeks to (or from where the previous read of the column ended) up to the end of the part. `prefetchForColumns` skips such columns. The type default is what the part stores, so a `DEFAULT <expr>` column that holds zeros still reads zeros; that is why the column is not treated as absent from the part. Measured on a 400-column table with 100K rows in one part (release build, paired runs): a point lookup on all-default sparse columns -41.5% (FileOpen 902 -> 2, memory 70.8 -> 3.7 MiB), full scan -50.3%, merge of 4 such parts -50.2%; columns with values and dense columns unchanged. Patch by @ snelheidai in ClickHouse#130330 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the only_defaults_next_row member comment to one line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding, 0 on the re-review of the fix) plus my own review (2 findings, 0 on the re-review).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261111-045100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261110-235100 |
|
Workflow [PR], commit [3a6c707] Summary: ✅
AI ReviewSummaryPR #130692 avoids opening streams for top-level sparse columns containing only stored defaults in a Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+19.21 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units8 translation units recompiled, 23 s compile time in total, 8 of them have a recent master baseline. |
The test inserted one row of zeros into a Wide part on `s3_disk`, so both columns were sparse with only default values. Such columns are no longer read from the disk, so the retried `SELECT a, b` made no S3 request and `DiskConnectionsPreserved` stayed 0 (measured: 2 `S3GetObject` per query before, 0 after). Insert non-default values so the query still reads the part from S3 and the test keeps checking connection reuse. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test counts FileOpen and ReadCompressedBytes of `SELECT sum(u)` to show that a sparse column with only defaults is not read. With `merge_tree_read_split_ranges_into_intersecting_and_non_intersecting_injection_probability` above 0 and more than one stream, `ReadFromMergeTree` turns the read into an in-order one and adds the sorting key `k` to the columns it reads, so `k.bin` is read as well. Reads from object storage get more than one stream here, so the test failed in `Stateless tests (amd_tsan, s3 storage, targeted)`. Pin the injection to 0 on that query only; the other queries keep it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #130330
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Sparse columns of a
Widepart that contain only default values in that part are no longer read from disk: their files are not opened.SELECT *and merges on wide tables with many such columns are faster, for example a point lookup on a 400-column table takes 41% less time and 95% less memory.Description
When a sparse column has only default values in a part, its values files are empty in the part's checksums: every non-default value writes at least one byte to them.
MergeTreeReaderWidestill created a stream for each of its files (marks load, open, read buffer) and decoded its offsets: a point lookup on a 400-column table opened 902 files to return one row.addStreamsnow creates no streams for a top-level sparse column that has all its streams in the part and only empty values files, andreadSegmentFromDiskappends as many defaults as reading the offsets would give: from the mark the read starts at (or where the previous read ended) up to the end of the part. Prefetch skips such columns. The type default is what the part stores, so aDEFAULT <expr>column that holds zeros still reads zeros.This is the patch posted by @ snelheidai in #130330 (comment); it does not depend on the issue's
SerializationSparsechange.Local release build, 100K rows in one part, 15 paired runs (issue's tables):
FileOpen902 -> 2Columns with values and dense columns are unchanged: their point-lookup intervals include 0 (between -1.4% and +3.4%), dense merge -1.3% [-9.0, +7.1]. A new stateless test checks the results, the
DEFAULTcase and that no file is read; the performance testsparse_column_only_defaults_widemeasures it in CI. Output is identical to master on a differential over all sparse-capable types, two disks and eight read settings profiles.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/130692]