Repository navigation
Speed up IN (subquery) set building by pre-deduplicating each MergeTree partition independently - #114645
Conversation
|
Workflow [PR], commit [b769b72] Summary: ✅
AI ReviewSummaryThis PR adds a default-on optimization for Findings
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 188/253 (74.31%) · Uncovered code |
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 sizes50 object files changed (+57.01 KiB total), 0 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 units474 translation units recompiled, 4228 s compile time in total, 474 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.91 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
📊 Cloud Performance Report
This sync PR adds an on-by-default query-plan optimization: parallel per-partition pre-deduplication when building the set for IN (subquery), applied only when the subquery reads a partitioned MergeTree whose partition key is a deterministic function of the subquery output. Both flagged queries (tpch_adapted Q7 and Q17) were left as not_sure because the master baseline is unstable in the current era, and their deltas — a noisy +17.9% on Q7 and a very noisy +59.4% on Q17 — are consistent with run-to-run variance rather than a real regression. Neither query exercises the new IN-subquery set-building path, so there is no regression here that is plausibly attributable to this change. clickbench🟢 No significant changes tpch_adapted_1_officialFlagged queries (2 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
|
…ndently` description
…itions` perf test
c583f98
Related: #108326
Related: #105126
The set for
IN (subquery)is built by a singleCreatingSetsTransform: all streams of the subquery are merged into one and every row is hashed serially, no matter how many threads read the data. If the partition expression of the subquery's table is a function of the subquery's output columns (the set is keyed on all of them), the reading will now emit each partition through a single port and each stream is deduplicated independently before the filling transform. Because a key then lives in exactly one stream, per-stream deduplication is complete, and the single filling transform only hashes unique rows — the serial part of the build shrinks from all rows to distinct rows, and the deduplication itself runs in parallel.On the table above (100M rows, 1M distinct keys, 8 balanced partitions; 64-core machine, average of 3 runs after 2 warm-ups):
SELECT count() FROM numbers(10) WHERE number IN (SELECT a FROM t)Adaptive abandonment of the preliminary deduplication
The per-stream
DistinctTransformin front of the set fill pays off only when it removes rows: the set deduplicates anyway, so on mostly-unique input the transform removes almost nothing while its hash tables hold roughly a second copy of the unique keys next to the set being built.To keep the optimization strictly non-regressing, the pre-deduplication observes its own effectiveness and gives up when it is not helping (
DeduplicationAbandonController):The transform also mirrors the set fill's
NULLhandling: with the defaulttransform_null_in = 0the fill drops every row with aNULLin any key component, so the pre-deduplication drops them too (using the sameextractNestedColumnsAndNullMaphelper, plus the dictionaryNULLentry forLowCardinality(Nullable)keys) instead of hashing them and letting them distort the abandon decision. Chunks fully resolved by theLowCardinalitydictionary mask are likewise counted as duplicate rows. Together this keeps the abandon decision based on exactly the row population the fill would hash.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up set building for
IN (subquery)on partitionedMergeTreetables by keeping each partition's rows within a single stream and deduplicating each stream independently, so the single set-filling transform — previously hashing every row serially — only sees unique rows. This applies when the partition expression is a deterministic function of the subquery's output columns. The optimization is not applied when the largest partition holds more than twice the rows of the average partition; the new settingforce_creating_set_partitions_independently(disabled by default) bypasses this check. Controlled by the new settingallow_creating_set_partitions_independently(enabled by default).Workflow [PR]
Sync PR [sync-upstream/pr/114645]
Version info
26.8.1.1939(included in26.8and later)