Skip to content

Append decoded Parquet String values in bulk - #124864

Open
groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:parquet-string-bulk-append
Open

groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:parquet-string-bulk-append

Conversation

@groeneai

@groeneai groeneai commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #124609

Changelog category (leave one):

  • Performance Improvement

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

Reading String columns from Parquet files is faster: a run of one dictionary value, a batch of dictionary indexes and a PLAIN page are now appended to the column at once instead of one value at a time. ClickBench queries over hits.parquet that read sparse string columns (Q11, Q12, Q26) are 5-22% faster.

Description

Analysis and patch by @ snelheidai in #124609, re-measured on x86 here.

Dictionary::appendRepeated (RLE run of one dictionary index), Dictionary::appendIndexes (batch of indexes) and PlainStringDecoder::decode (PLAIN page) called ColumnString::insertData per value, though a run of empty strings, typical for sparse columns, is one offsets fill.

Now:

  • appendRepeated: insertManyDefaults(n) for an empty value, else one chars.resize for the run.
  • appendIndexes: sum the lengths, one chars.resize, then copy per index.
  • PlainStringDecoder::decode without a row filter or active string filter: write values and offsets directly, growing the chars with the same power-of-two reserve as insertData.

Offsets are reserved before the chars grow, so an allocation failure or malformed page leaves a consistent column. The row-filtered PLAIN loop and the active StringValueFilter branches are unchanged.

fix/base time, geomean of 8 alternating pairs, 95% CI, max_threads = 4:

Query x86 run 1 x86 run 2 Graviton3 (#124609)
Q11 0.80 [0.76, 0.83] 0.85 [0.78, 0.92] 0.78 [0.74, 0.82]
Q12 0.85 [0.83, 0.87] 0.87 [0.83, 0.92] 0.81
Q26 0.94 [0.91, 0.97] 0.95 [0.92, 0.97] 0.87
Q13 0.93 [0.90, 0.96] 0.96 [0.94, 0.98] 0.90

Q6, Q21 and Q28 gain up to 7%; the rest, including LIKE with apply_string_filters_during_scan = 1, are unchanged. Single-threaded peak memory is equal within 1%; with 4 threads it varies with the row groups in flight on both builds.

Validation: 2240 query results over ClickHouse- and pyarrow-written files match master; Parquet stateless tests match master and pass under ASan; six mutants of the new code each fail existing tests; memory-limit and fault-injection sweeps return the correct result or MEMORY_LIMIT_EXCEEDED. The new perf test parquet_read_strings covers the three shapes (sparse query 0.73x).


Workflow [PR]
Sync PR [sync-upstream/pr/124864]

The v3 Parquet reader appended every decoded String value with
`ColumnString::insertData`, one call per row, in the three places that decode
most string data: `Dictionary::appendRepeated` (an RLE run of one dictionary
index), `Dictionary::appendIndexes` (a batch of dictionary indexes) and
`PlainStringDecoder::decode` (a PLAIN page). Each call re-checks the chars
capacity, stores the chars and offsets ends through the column and pushes one
offset, and for an empty-string run (the dominant run of sparse columns) a
whole run could be a single offsets fill.

Append each run, batch and page at once instead:
- `appendRepeated`: an empty value is `insertManyDefaults(n)`, otherwise one
  `chars.resize` for the whole run, `n` copies and one offsets fill.
- `appendIndexes`: sum the lengths, one `chars.resize`, then copy + offset per
  index.
- `PlainStringDecoder::decode` (no row filter, no active string filter): write
  values and offsets directly with the chars end in a local; when a value does
  not fit, commit the rows written so far and grow the chars with the same
  power-of-two `reserve` that `insertData` uses.

Offsets are reserved before the chars grow (the order of
`ColumnString::doInsertManyFrom`), and the PLAIN loop commits its prefix before
each growth, so an allocation failure or a malformed page leaves a consistent
column. The paths under an active `StringValueFilter` and the row-filtered
PLAIN loop are unchanged.

Analysis and patch by snelheidai in ClickHouse#124609. Adds
`tests/performance/parquet_read_strings.xml` covering the three shapes.

Closes ClickHouse#124609

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-issue PR origin: picked up an external GitHub issue labels Oct 9, 2026
@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings; 1 full pass over the whole diff, its callers and the sibling decoders). My own review of the same head found no blocker or major issue.

# Sev Finding Verdict Evidence / action
- - No findings - -

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-10:20261009-083900

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Performance change, so the "repro" is a measurement: ClickBench over hits.parquet, 4 threads pinned to 4 cores, 8 alternating base/fix pairs per query. Two independent runs give Q11 0.80 and 0.85, Q12 0.85 and 0.87 (fix/base).
b Root cause explained? The three String append sites of the v3 reader called ColumnString::insertData once per value, so every row paid a capacity check, and a run of empty strings paid that per row although it is a single offsets fill.
c Fix matches root cause? Yes. Each site now appends its run, batch or page at once. No other layer changes.
d Test intent preserved / new tests added? No existing test changed. New tests/performance/parquet_read_strings.xml; its sparse query is 0.73x. No new stateless test: six mutants of the new code are each killed by the existing 226 Parquet/string-filter tests.
e Both directions demonstrated? Master and patched binaries built from the same tree, A/B measured as in (a); the same 226 stateless tests give identical per-test results on both; every mutant reddens tests.
f Fix is general across code paths? The change covers every place where the v3 reader appends a String value one by one with a trivial converter and no active filter. Kept as is on purpose: the row-filtered PLAIN loop, the active StringValueFilter branches, DeltaLengthByteArrayDecoder (already bulk) and DeltaByteArrayDecoder (prefix-dependent).
g Fix generalizes across inputs (params/datatypes/wrappers)? Differential sweep, 2240 results identical to master on release and debug builds: 8 files, String / Nullable(String) / read as LowCardinality, full scans, PREWHERE, string filters with apply_string_filters_during_scan 0 and 1, top-K, 1 and 8 threads.
h Backward compatible? (maintainer-approved exception only) Yes: no setting, no format change, same results, same memory growth pattern.
i Invariants and contracts preserved? After each call returns or throws, the column has offsets.size() rows and offsets.back() == chars.size(); checked with max_memory_usage and memory-tracker fault-injection sweeps on ASan and debug builds, and a corrupted PLAIN length prefix (same INCORRECT_DATA as master).

Session id: cron:clickhouse-impl-slot-4:20261009-051000

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [357358e]

Summary: ❌

job_name test_name status info comment
Upgrade check (amd_release) FAIL
Error message in clickhouse-server.log (see upgrade_error_messages.txt) FAIL cidb

AI Review

Summary

Reviewed #124864 at 357358ebd7ee1cbcde5993952bd2afdbd0622672. The change appends Parquet String values in bulk for dictionary runs, dictionary index batches and unfiltered PLAIN pages. No outstanding blockers or majors found. The previously reported dictionary byte-size overflow is fixed in the current code; its thread remains resolved. Performance measurements and existing regression coverage support the change. No local builds or tests were run.

Final Verdict

Status: ✅ Approve

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 357358ebd with master 4e68e80b3 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 16 s compile time in total, 7 of them have a recent master baseline.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 31 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 76e2c62e-211f-4423-a1cd-072298ab23ad
  • MIRAI run: 93c65512-49b4-4854-8874-bc9c5c6c0678
  • PR check IDs:
    • clickbench_525915_1791543296
    • clickbench_525921_1791543296
    • clickbench_525927_1791543296
    • tpch_adapted_1_official_525939_1791543295
    • tpch_adapted_1_official_525954_1791543296
    • tpch_adapted_1_official_525985_1791543296

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 48409dc

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, s3 storage, DBReplicated, parallel, 1/2) / 05316_secret_arguments_declared_by_engines test regression from merged #123364, not from this PR (which changes the Parquet String decoders): under DatabaseReplicated the final query_log count returns 0 2 instead of 0 1 (the password stays hidden; the CREATE DICTIONARY row is counted twice). 22/22 reruns pass; the same diff is on 20+ PRs in this lane today a fix task is created (investigating at full effort, fixing-PR link to follow here)
Mergeable Check, PR praktika rollups of the row above, no independent failure a fix task is created (the row above)

Session id: cron:our-pr-ci-monitor:20261009-133010

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Fixing PR for 05316_secret_arguments_declared_by_engines (DatabaseReplicated 0 1 -> 0 2) from the CI finish ledger above: #124928 (external, open).

…-append

Resolve the conflict in `PlainStringDecoder::decode`: keep the bulk-append path for unfiltered
pages, and check the length prefix before loading it there too, as master now does in every loop
of the decoder (839d3eb: a page retained from a page-cache cell is not padded).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The bulk append sums the lengths of all gathered dictionary entries
before allocating the chars. `n` is not bounded by a page: for a
single-column PREWHERE, `Reader::readRowsInPage` passes the indexes
accumulated across preceding dictionary pages when the next page is
PLAIN, so with a large `input_format_parquet_max_block_size` the sum
can wrap `size_t` (e.g. a 2147483640-byte entry referenced 8589934625
times sums to 2^64 + 2147483384), and the copy loop then writes past
the allocation. The per-value `insertData` it replaced grew the column
as it went, so an allocation failure stopped it first.

Accumulate starting from the current chars size with
`common::addOverflow`, so one check covers both the sum and the final
size, and throw `INCORRECT_DATA` before anything is allocated, as the
DELTA_LENGTH_BYTE_ARRAY decoder does for its lengths.

`appendRepeated` and `PlainStringDecoder::decode` stay as they are:
there `n` is at most one page's value count, so `len * n` is below 2^62.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 357358e

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Upgrade check (amd_release) / Error message in clickhouse-server.log (see upgrade_error_messages.txt) not PR-caused: the upgraded server retries a stateless test's intentionally failing mutation (INCORRECT_FILE_NAME, column skp_idx_a vs skip index a); same error on 12 PRs in 30 days #124532 (mine, open), with #128105 (mine, open)

Session id: cron:our-pr-ci-monitor:20261118-213024

This branch has not been deployed

No deployments
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-parquet-reader-v3 Issues related to the native Parquet reader. groeneai-origin-issue PR origin: picked up an external GitHub issue pr-performance Pull request with some performance improvements

Projects

None yet

1 participant