Repository navigation
Use a compressible payload in the lazy_materialization_final_limit performance test - #123719
Conversation
…e test Query ClickHouse#1 (`FINAL WHERE v = 7 LIMIT 100`) never reaches its limit: only 47 rows survive FINAL, so it scans all of (k, v) and lazily reads `payload` for those 47 rows. With default granules (~5-6K rows of 2 KB random, incompressible strings, ~10 MB each) every match decodes ~6 MB of payload, ~285 MB in total. After ClickHouse#122479 both compared servers read identical data, but on arm one server of a pair still copies those same bytes out of the page cache ~20% slower in a few percent of fills, and with merges stopped all runs of the query carry it: PR ClickHouse#122571 got a confirmed +17.8% on `Performance Comparison (arm_release, master_head, 6/6)` this way. With `index_granularity = 256` a granule is ~0.5 MB and one compressed block, so each match reads ~0.5 MB. Measured on a two-server rig with the XML's own statements: ClickHouse#1 ReadCompressedBytes 284.1 MB -> 31.8 MB, SelectedRows 1,015,104, #0 and ClickHouse#2 read less too (58.7 -> 13.3 MB). The test still measures FINAL over the same two intersecting parts with lazy materialization of the wide payload. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)Own cold review plus a second-model gate (codex) on
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261003-155500 |
|
Workflow [PR], commit [5374f50] Summary: ✅
AI ReviewSummaryThis PR keeps Missing context / blind spots
Final Verdict✅ No blocker or major findings. |
| CREATE TABLE lazy_mat_final_limit (k UInt64, v UInt64, payload String) | ||
| ENGINE = ReplacingMergeTree | ||
| ORDER BY k | ||
| SETTINGS index_granularity = 256 |
There was a problem hiding this comment.
@groeneai I prefer to test lazy_materialization_final_limit with default granularity, which is going to be the real production case. Can you increase the INSERT size or do something else instead?
There was a problem hiding this comment.
Done in 5374f50: the table keeps the default granularity, and the payload is compressible instead: each 2000-byte value repeats a random 200-byte string 10 times (about 10x with LZ4). #1 still never reaches LIMIT 100 and lazily reads its 47 rows from default granules, but that read is now 38.0 MB instead of 284.3 MB (perf.py --stop-merges on two servers, 98 marks per part as before), and lazy materialization still makes #1 3.8x faster (5.0x before).
A larger INSERT alone makes it worse: with more matching rows #1 reaches LIMIT 100 and lazily reads 100 rows instead of 47, each costing about half a default granule (measured with 200-byte values: 116 MB at 1.2M rows per INSERT vs 50 MB at 500K).
…ation_final_limit Keep the default index granularity, as production tables have, and shrink the lazy read through the payload instead: each 2000-byte value now repeats a random 200-byte string 10 times, so LZ4 compresses it about 10x. The value width, the two intersecting 500K-row parts, the queries and the lazy materialization plan stay as they were. Query ClickHouse#1 never reaches its LIMIT 100 (47 rows match after FINAL) and lazily reads the matching rows out of default-size granules, so most of its time was copying ~284 MB of incompressible payload out of the page cache, the part that differs between the two compared servers on arm. perf.py --stop-merges on two servers, x86 master release build: ClickHouse#1 reads 38.0 MB instead of 284.3 MB, the same on both servers, with 98 marks per part as before, and spends ~6 ms instead of ~47 ms in page-cache reads. ClickHouse#1 with lazy materialization disabled is 3.8x slower (5.0x before). Co-Authored-By: Claude Opus 5.5 <[email protected]>
lazy_materialization_final_limit performance testlazy_materialization_final_limit performance test
Related: #122571 (comment)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The
lazy_materialization_final_limitperformance test now uses a compressible payload at the default index granularity, so itsLIMIT 100query reads about 38 MB instead of about 285 MB.Description
Performance Comparison (arm_release, master_head, 6/6)flagged#1as a confirmed regression on #122571, which only changes another test: job, 31.3 -> 36.9 ms (+17.8%), all 7 right runs slower.Since #122479 both servers read the same data (equal read counters in 1913 of 1913 arm runs; arm runs with
#1more than 10% apart fell from 21.3% to 2.4%). What remains is the read itself: only 47 rows passFINAL WHERE v = 7, soLIMIT 100is never reached and#1lazily readspayloadfor those 47 rows from the default-size granules around each, about 285 MB of incompressible 2 KB strings per run. In the arm runs still more than 10% apart, the slow server spends 21% longer (median) in that page-cache read while bytes, rows and user CPU are equal.The table keeps the default index granularity. Each 2000-byte value now repeats a random 200-byte string 10 times, so it compresses about 10x and the same read copies about 38 MB out of the page cache. The value width, the two intersecting parts, the queries and the plan (
LazilyReadFromMergeTree) are unchanged;#1with lazy materialization disabled is 3.8x slower (5.0x before).Validated with a master release build on x86, two servers under
perf.py --stop-merges:#1reads 38.0 MB instead of 284.3 MB, identically on both servers, with 98 marks per part as before, and spends about 6 ms instead of 47 ms in page-cache reads. Timing#1on two freshly filled tables in one process, 0 of 12 trials differed by more than 5% (3 of 12 before). The arm slow mode does not reproduce on x86, so the arm effect is inferred from the read volume.Workflow [PR]
Sync PR [sync-upstream/pr/123719]
Version info
26.10.1.1616-master(included in26.10and later)