Repository navigation
Reuse resolved column metadata in performRequiredConversions - #113008
alexey-milovidov merged 11 commits into
Conversation
|
Workflow [PR], commit [305a49e] Summary: ✅
AI ReviewSummaryThis PR replaces the per-block Final Verdict✅ No new findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: This PR is a one-line micro-optimization in the merge-tree reader that only affects the required-conversions path exercised by JSON subcolumns and on-disk type mismatches (with a matching perf test). Neither flagged query touches that path: ClickBench Q17 is a fixed-column aggregate and TPC-H Q7 is a join over fixed-type columns. Both deltas (+12.4% and +11.6%) land inside master's current variance band and were correctly kept as not_sure by the envelope gate, so they read as run-to-run variance, not a PR effect. Q17 shows a trending master signal worth keeping an eye on independently of this change. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_officialFlagged queries (1 of 22)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes33 object files changed (+153.04 KiB total), 2 added.
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units7 translation units recompiled, 17 s compile time in total, 7 of them have a recent master baseline. |
The test stresses the per-block column resolution in `IMergeTreeReader::performRequiredConversions`: selecting 32 dynamic JSON subcolumns previously re-resolved each subcolumn via `getColumnInPart` on every read block, repeatedly enumerating the JSON serialization and entering `SerializationObjectPool`. Reusing `columns_to_read[pos]` gives a stable ~12% end-to-end speedup on this query (median 0.308 s -> 0.275 s, single thread, 1M rows, 400 dynamic paths). Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 The |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113008&sha=bf9369f35fc4359f2dc5d50d76a61c994d430ba7&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. Context: EXPLAIN ESTIMATE SELECT count() != 1048576 FROM t PREWHERE toDate(x) IN (toDate(65537), toDate(65537))CIDB shows the same finding on master ( |
|
Reproduced on today's master ( Minimal repro. SET allow_suspicious_low_cardinality_types = 1; -- LowCardinality(UInt16) is refused by default
CREATE TABLE t (x LowCardinality(UInt16)) ENGINE = MergeTree ORDER BY x;
INSERT INTO t SELECT number % 65536 FROM numbers(1048576);
EXPLAIN ESTIMATE SELECT count() FROM t WHERE toDate(x) IN (toDate(5)); -- abortsThe same query on a plain What the log shows: the surviving range is the whole part, #112231 does not cover this carrier. Its guard is keyed on a chain that throws; here nothing throws, the chain is refused as non-monotonic, and that PR deliberately treats the honest non-monotonic answer as "not a failure". I am fixing this in a separate PR and will link it here. One refinement on the census: since #111964 merged, the |
|
Root-caused, and the fix is already in progress: #111050 (approved, awaiting merge).
A/B that isolates it, on master
The one site that strips is the one that works. #111050 adds that strip inside the callee, so all Three things worth noting beyond the reported repro:
Also, On your other pointer: #112231 does not cover this one. Its guard keys on I am not opening a separate PR, since that would duplicate #111050. If you would rather have the |
|
🕵 The remaining red, Stress test (amd_debug), is unrelated to this PR: the harness aborted before running the tests because |
|
|
||
| <!-- Reading many dynamic JSON subcolumns stresses the per-block column resolution | ||
| in IMergeTreeReader::performRequiredConversions. --> | ||
| <query>SELECT json.key0, json.key1, json.key2, json.key3, json.key4, json.key5, json.key6, json.key7, json.key8, json.key9, json.key10, json.key11, json.key12, json.key13, json.key14, json.key15, json.key16, json.key17, json.key18, json.key19, json.key20, json.key21, json.key22, json.key23, json.key24, json.key25, json.key26, json.key27, json.key28, json.key29, json.key30, json.key31 FROM t_json_subcolumns_conversions FORMAT Null SETTINGS max_threads = 1</query> |
There was a problem hiding this comment.
This was added by @alexey-milovidov not me, I am not sure the reasoning behind this setting
c8b1c3d
IMergeTreeReaderalready resolves and storescolumns_to_readduring construction, butperformRequiredConversions()calledgetColumnInPart()again for every read block.For dynamic JSON subcolumns, this repeatedly enumerated the full JSON serialization and entered
SerializationObjectPool. In production-derived PostHog profiles, this path accounted for 40,849 of 48,346 (84.5%) dynamic-subcolumn resolution/pool-contention CPU samples.Reuse
columns_to_read[pos]instead of resolving the same column again.Before/after benchmark
Measured on this branch vs. the same tree with only
src/Storages/MergeTree/IMergeTreeReader.cppreverted to the merge-base (master) version, RelWithDebInfo, aarch64. Dataset:CREATE TABLE t (json JSON) ENGINE = MergeTree ORDER BY tuple(), 1M rows oftoJSONString(map('key' || toString(number % 400), number)), single part afterOPTIMIZE TABLE ... FINAL. Query:SELECT json.key0, ..., json.key31 FROM t FORMAT Null SETTINGS max_threads = 1(32 dynamic subcolumns), 10 timed runs after warmup:performRequiredConversions)That is a stable ~12% end-to-end speedup. A
perf record -gprofile of the before binary on the same query attributes 12.65% of CPU samples toperformRequiredConversions, of which 12.49% is the inlinedgetColumnInPart(i.e.SerializationObjectPool::getOrCreate,SerializationObjectDynamicPathconstruction,SerializationObject::enumerateStreams), matching the measured win; in the after binary this subtree is gone.The new test
tests/performance/json_subcolumns_required_conversions.xmlcovers this path in CI.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improves
MergeTreeread performance for JSON subcolumns by reusing resolved subcolumn metadata during required conversions.Version info
26.8.1.1035(included in26.8and later)