Skip to content

Reduce Adaptive Aggregator memory usage - #128495

Merged
thevar1able merged 22 commits into
ClickHouse:masterfrom
nihalzp:adaptive-aggregator-staging-memory
Nov 11, 2026
Merged

thevar1able merged 22 commits into
ClickHouse:masterfrom
nihalzp:adaptive-aggregator-staging-memory

Conversation

@nihalzp

@nihalzp nihalzp commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Related: #123531

Background: staged records

The adaptive aggregator (enable_adaptive_aggregator, enabled by default) runs a GROUP BY in two phases:

  • Scan. Every thread aggregates its rows into its own hash table until the table holds 16,384 keys (adaptive_aggregator_freeze_threshold). Then the table freezes. A row whose key is already in the table still updates it in place. A row with a new key, a miss, is not inserted: the thread writes it down as a staged record, a few bytes that hold everything the merge needs to aggregate the row later.
  • Merge. The merge reads the staged records of all threads and aggregates them into the result, one slice of the key hash (a partition) at a time.

A staged record holds the key, often its hash, and a payload: the number of rows it stands for when count() is the only aggregate, nothing for a GROUP BY without aggregate functions, and the row's aggregate arguments otherwise. Each thread keeps one buffer per partition, a chain of memory chunks, and there are 1,024 partitions per thread at 16 threads and 2,048 at 64.

The staged records stay in memory until the merge, so they are most of the peak memory: 50-98% of it on ClickBench. That memory has two parts: the bytes of the records, and the unused end of the last chunk of every buffer. The changes below shrink both.

Key changes

  1. Smaller records. Each field, before → after, and why the smaller form is enough:

    • Hash, 8 → 4 bytes, in the records of String keys and of keys serialized from several columns. The merge needs the hash to insert the key into its table, and the record stores it because computing it again would read all the key bytes. But these tables hash with CRC32 (on CPUs with a CRC instruction) or with the hash of packed strings, and both produce only 32 bits: the upper half of the 64-bit value is either zero or a copy of the lower half, and the key itself tells which. So the record keeps the lower half, and the merge rebuilds the rest. Tables with other hash functions keep all 8 bytes.
    • Length of the key and of each String argument, 4 → 1 byte. Nearly all keys and strings are shorter than 255 bytes, so one byte holds the length. A longer one takes the byte 255 followed by the 4-byte length.
    • Count, 4 → 1 byte, when count() is the only aggregate. The count is the number of rows of one key that a thread folds into one record within one block, which is nearly always small. A larger count takes the byte 255 followed by the 4-byte count, as a long length does, so a key that repeats many times in a block takes one record however long it is. A fixed-width key, which is short, writes a larger count as several records of the key, and the merge adds them up, as it adds up all the records of a key.
    • Key packed from several fixed-width columns, from the whole packed integer to the bytes of its columns: 16 → 12 bytes for WatchID, ClientIP. Such keys are packed into one integer of up to 32 bytes, whose bytes past the columns and their null flags are always zero. The record stores only the filled bytes, and the merge reads the integer back with the rest set to zero.
    • Padding, up to 3 bytes → none. Most records were padded to a multiple of 4 bytes, but their fields were always read with unaligned loads, so the padding gained nothing.
    • Fields that the reader can derive: removed. No record of a fixed-width key stores a hash any more, since the merge recomputes it in a few instructions. A record whose variable-size arguments, if any, are all Strings does not store its size, since its end follows from the lengths in it.

    For example, the count() records of a 20-byte SearchPhrase and of a UserID:

    SearchPhrase  before: hash 8 | count 4 | length 4 | key 20  = 36 bytes
                  after:  hash 4 | count 1 | length 1 | key 20  = 26 bytes
    UserID        before: count 4 | key 8                       = 12 bytes
                  after:  count 1 | key 8                       =  9 bytes
    
  2. Smaller chunks. The chunks of a buffer double in size from 2 KiB, so that a small partition takes little memory and a large one takes few chunks.

    • Before: chunks doubled up to 32 KiB. The last chunk of a buffer is partly empty, and with one buffer per partition and thread, 16,384 buffers at 16 threads and 131,072 at 64, these empty ends added up to 2.3 GiB in Q33 at 64 threads.
    • After: chunks double up to 8 KiB, and up to 4 KiB from 17 threads on, where every thread has twice as many partitions. The empty end of a buffer is now at most that cap.
    • Why this costs no time: chunks are carved from shared blocks of up to 256 KiB, so smaller chunks do not mean more allocations, only more chunk starts, which change 3 makes cheap.
    • A record of more than half the cap gets a chunk of exactly its size, since a capped chunk would hold it alone and leave up to half of itself empty.
  3. Folded records for GROUP BY without aggregate functions.

    • Before: every missed row became its own record, even when its key repeated.
    • After: the repeats of a missed key within a block fold into one record, as they already did when count() is the only aggregate. This is correct because such a record only says that its key exists: the merge inserts the key once, however many records carry it.

Results

ClickBench hits (100M rows) on AWS c8a.16xlarge (64 cores, one thread per core), FORMAT Null. Peak memory is memory_usage from system.query_log. Master already has the adaptive aggregator of #123531.

QueryShape16 threads64 threads
MasterPRReductionMasterPRReduction
Q12GROUP BY SearchPhrase: count, where SearchPhrase <> ''1,127 MiB801 MiB29%1,470 MiB1,368 MiB7%
Q13GROUP BY SearchPhrase: count(DISTINCT UserID), where SearchPhrase <> ''1,425 MiB1,116 MiB22%2,239 MiB1,719 MiB23%
Q14GROUP BY SearchEngineID, SearchPhrase: count, where SearchPhrase <> ''1,232 MiB969 MiB21%1,845 MiB1,507 MiB18%
Q15GROUP BY UserID: count524 MiB320 MiB39%794 MiB486 MiB39%
Q16GROUP BY UserID, SearchPhrase: count2,078 MiB1,537 MiB26%2,681 MiB2,038 MiB24%
Q18GROUP BY UserID, minute(EventTime), SearchPhrase: count3,214 MiB2,324 MiB28%4,229 MiB2,876 MiB32%
Q30GROUP BY SearchEngineID, ClientIP: count, sum, avg, where SearchPhrase <> ''342 MiB291 MiB15%548 MiB505 MiB8%
Q32GROUP BY WatchID, ClientIP: count, sum, avg2,334 MiB1,795 MiB23%3,631 MiB2,163 MiB40%
Q33GROUP BY URL: count5,724 MiB5,239 MiB8%8,212 MiB5,930 MiB28%
Q34GROUP BY 1, URL: count5,720 MiB5,239 MiB8%8,288 MiB5,930 MiB28%
Q35GROUP BY ClientIP, ClientIP - 1, ClientIP - 2, ClientIP - 3: count316 MiB283 MiB10%524 MiB437 MiB17%
Geomean21%25%

Query times stay the same, with a geometric mean speedup of 1.01× at both widths.

The same aggregations without ORDER BY and LIMIT produce all their groups, and the reduction is about the same.

QueryShape16 threads64 threads
MasterPRReductionMasterPRReduction
Q12GROUP BY SearchPhrase: count, where SearchPhrase <> ''1,127 MiB797 MiB29%1,544 MiB1,384 MiB10%
Q13GROUP BY SearchPhrase: count(DISTINCT UserID), where SearchPhrase <> ''1,463 MiB1,151 MiB21%2,386 MiB1,839 MiB23%
Q14GROUP BY SearchEngineID, SearchPhrase: count, where SearchPhrase <> ''1,232 MiB976 MiB21%1,917 MiB1,554 MiB19%
Q15GROUP BY UserID: count508 MiB320 MiB37%772 MiB463 MiB40%
Q16GROUP BY UserID, SearchPhrase: count2,111 MiB1,579 MiB25%2,889 MiB2,292 MiB21%
Q18GROUP BY UserID, minute(EventTime), SearchPhrase: count3,318 MiB2,421 MiB27%4,518 MiB3,291 MiB27%
Q30GROUP BY SearchEngineID, ClientIP: count, sum, avg, where SearchPhrase <> ''335 MiB286 MiB15%527 MiB477 MiB9%
Q32GROUP BY WatchID, ClientIP: count, sum, avg2,513 MiB2,037 MiB19%4,800 MiB3,105 MiB35%
Q33GROUP BY URL: count5,993 MiB5,557 MiB7%8,851 MiB6,738 MiB24%
Q35GROUP BY ClientIP, ClientIP - 1, ClientIP - 2, ClientIP - 3: count313 MiB279 MiB11%507 MiB407 MiB20%
Geomean22%23%

GROUP BY without aggregate functions also runs faster. The queries below are the key-only forms of the ones above, SELECT count() FROM (SELECT <keys> FROM hits GROUP BY <keys>). On master, such a query stages one record per missed row. In this PR, the repeats of a missed key within a block are removed: consecutive repeats always, and for String and serialized keys also repeats of the last key missed in the same partition.

GROUP BY keys16 threads64 threads
MasterPRSpeedupMemory reductionMasterPRSpeedupMemory reduction
SearchPhrase, where SearchPhrase <> ''100.2 ms, 1,188 MiB95.3 ms, 788 MiB1.05×34%58.2 ms, 1,736 MiB54.6 ms, 1,389 MiB1.07×20%
SearchEngineID, SearchPhrase, where SearchPhrase <> ''126.8 ms, 1,324 MiB122.7 ms, 948 MiB1.03×28%69.0 ms, 2,024 MiB66.4 ms, 1,484 MiB1.04×27%
UserID95.0 ms, 513 MiB59.5 ms, 288 MiB1.59×44%42.3 ms, 515 MiB34.2 ms, 382 MiB1.24×26%
UserID, SearchPhrase511.9 ms, 3,126 MiB234.7 ms, 1,501 MiB2.18×52%168.7 ms, 3,245 MiB103.9 ms, 2,133 MiB1.62×34%
UserID, minute(EventTime), SearchPhrase426.1 ms, 4,212 MiB380.3 ms, 2,327 MiB1.12×45%196.8 ms, 6,185 MiB160.1 ms, 3,059 MiB1.23×51%
SearchEngineID, ClientIP, where SearchPhrase <> ''49.5 ms, 202 MiB49.0 ms, 152 MiB1.01×25%29.2 ms, 366 MiB28.5 ms, 340 MiB1.02×7%
WatchID, ClientIP214.4 ms, 2,025 MiB214.7 ms, 1,379 MiB1.00×32%106.8 ms, 2,377 MiB103.2 ms, 1,865 MiB1.03×22%
URL559.4 ms, 6,315 MiB520.3 ms, 5,529 MiB1.08×12%300.5 ms, 9,108 MiB254.2 ms, 6,587 MiB1.18×28%
ClientIP, ClientIP - 1, ClientIP - 2, ClientIP - 380.1 ms, 519 MiB50.7 ms, 183 MiB1.58×65%36.5 ms, 515 MiB33.5 ms, 359 MiB1.09×30%
Geomean1.25×39%1.16×28%

Changelog category (leave one):

  • Performance Improvement

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

The adaptive aggregator (enable_adaptive_aggregator, enabled by default) uses less memory for GROUP BY with many distinct keys: it stages smaller records in smaller chunks. Across 11 ClickBench aggregation queries, peak memory is 25% lower at 64 threads and 21% lower at 16 threads, at the same speed. A GROUP BY without aggregate functions now deduplicates the repeats of a key whenever it can, which makes such queries up to 2.2x faster.


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

Version info

  • Merged into: 26.11.1.1957-master (included in 26.11 and later)

@clickhouse-gh

clickhouse-gh Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e502f55]

Summary: ✅


AI Review

Summary

Reviewed #128495 at e502f5569637e70c563fb7db59d1bc19d2adc46c; the checkout has the same tree. The change reduces adaptive aggregation memory through compact staged records, smaller chunks, and combined key-only misses. No unresolved blockers or majors found. The previous long-key count finding is addressed: byte-staged keys retain oversized counts in one record.

Consumers checked for the changed record representation:

  • drainAdaptivePartition and countPartitionGroups select the same format and packed-key width as appendDelayedRecords, including count-first and filtered merge passes.
  • executeStagedArgumentRecords and decodeStagedVariableArguments reconstruct fixed and variable arguments using the selected format's offsets and lengths.
  • spillAdaptivePartitions preserves record bytes; SpilledPartition::readBack supplies the padding required by shortened-key loads, and spill readers copy retained string keys.
  • mergeAndConvertAdaptiveBucket converts keys before releasing staged records; aggregate-state outputs retain their arenas.

The PR provides before/after memory and timing measurements and focused regression coverage. The fetched CI reports report 14,410 passed, zero failed, and 4,479 skipped tests. No local build or tests were run.

Final Verdict

Status: ✅ Approve. No new inline findings; the previously resolved thread remains resolved.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Nov 1, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). label Nov 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

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

⚠️ Significant changes: object file sizes.

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.

Object file sizes ⚠️

15 object files changed (+1.50 MiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Interpreters/AdaptiveAggregation/Merge.cpp.o 8.39 MiB 9.50 MiB +1.11 MiB (+13.26%)
src/CMakeFiles/dbms.dir/Interpreters/AdaptiveAggregation/Producer.cpp.o 1.63 MiB 2.01 MiB +393.53 KiB (+23.57%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.93 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 7.6 s 16.0 s +8.9 s (+125%)
Compile time of recompiled translation units

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

Job report

@thevar1able thevar1able self-assigned this Nov 2, 2026
…_bytes_to_spill` for the smaller staged records
@nihalzp nihalzp mentioned this pull request Nov 10, 2026
7 of 33 tasks

@thevar1able thevar1able left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@thevar1able
thevar1able added this pull request to the merge queue Nov 11, 2026
Merged via the queue into ClickHouse:master with commit 55ae036 Nov 11, 2026
370 of 371 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 11, 2026
@snelheidai

Copy link
Copy Markdown

At 4 vCPU this PR makes ClickBench Q32 (GROUP BY WatchID, ClientIP with count, sum and avg) about 5% slower, while cutting its peak memory by 19% as intended.

Q32, 4 vCPU master 1dc32628 + this PR paired ratio [95% CI]
time, ms 2199 2306 1.053 [1.037, 1.069]
CPU time, ms 8241 8765 1.063 [1.056, 1.070]
peak memory, MiB 2010 1618 0.805

"+ this PR" is the PR's CI build (e502f556 merged into 1dc32628), so the two builds differ only by this PR. Master builds from before and after the merge (9e17b5d0, 4a885067) show the same slowdown: 1.060 [1.050, 1.070] on this machine and 1.054 [1.047, 1.060] on a second 4-vCPU machine.

Setup: Xeon 8375C, 4 vCPU, 30 GiB; hits with 100M rows, warm page cache; 6 rounds in rotating order, with a fresh server per round and build. Time and CPU (UserTimeMicroseconds) are medians over rounds of the faster of runs 2 and 3, server-side from query_log; peak memory is memory_usage. Both builds return correct results.

perf (12 s of a Q32 loop, share of samples) shows the extra time mainly in the merge's top-K count pass, and some in staging and draining: countPartitionGroups<AggregationMethodKeysFixed<…UInt128…>> 28.8% → 32.0%, appendDelayedRecords<…KeysFixed…> 19.9% → 21.5%, drainAdaptivePartition 3.9% → 4.6%, while gatherSelectedIntoRows falls from 5.8% to 3.3%.

I tested only 4 vCPU; your 16- and 64-thread runs report unchanged times overall. In a full ClickBench run with the master builds, none of the other queries in your table was significantly slower at 4 vCPU (Q31, the same keys with WHERE SearchPhrase <> '': 1.007), and their peak memory fell by 6-36%.

@snelheidai

Copy link
Copy Markdown

Follow-up to my earlier comment on the 4-vCPU Q32 slowdown: it does not come from the 12-byte packed key. In local builds, two other changes in this PR account for it: the 8 KiB chunk cap and the merged append loop in appendDelayedRecords. Undoing both brings Q32 back to its time before this PR and keeps 97% of the memory saving.

Not the packed key. Master builds before and after this PR (9e17b5d0, 4a885067), time ratio after/before [95% CI], 4 rounds. All variants use ORDER BY c DESC LIMIT 10 except the last:

variant after / before
Q32 1.054 [1.046, 1.063]
same keys, count() only 1.034 [1.028, 1.040]
WatchID, toUInt64(ClientIP): a full 16-byte key, peak memory unchanged (2011 → 2002 MiB) 1.063 [1.056, 1.070]
GROUP BY WatchID 1.038 [1.033, 1.042]
Q32 aggregation without ORDER BY ... LIMIT 1.002 [0.970, 1.035]

The full 16-byte key, which is not packed and saves no memory, slows down the most.

Two contributors. Local builds (Release, clang-21, no ThinLTO) of 9e17b5d0 with and without this PR's diff. There the PR makes Q32 about 4% slower and the 16-byte key about 6%. Ratios against the PR build, 4 rounds:

  • Chunk cap. With the 32 KiB cap from before this PR in forProducers: Q32 0.988 [0.985, 0.991], and about 1.2% faster on all five variants. Peak memory is up to 1% higher (Q32 1618 → 1629 MiB).
  • Append loop. Before this PR, argument records of a fixed-width key with only fixed-size arguments had their own loop, which added the byte totals once per batch. The general loop updates both totals per record, and in the CI build one of them stays on the stack (a load, add and store per record). With the one-size loop restored (patch below): Q32 0.987 [0.966, 1.009], 16-byte key 0.980 [0.963, 0.997].

Both together, 5 rounds:

variant vs PR build vs before
Q32 0.966 [0.956, 0.977] 0.998 [0.970, 1.026]
16-byte key 0.978 [0.963, 0.993] 1.032 [1.014, 1.051]
GROUP BY WatchID 1.020 [0.954, 1.091] 1.024 [0.948, 1.106]

Q32 peak memory: 2012 MiB before, 1618 with the PR, 1629 with both changes. The GROUP BY WatchID row is within noise. Results are identical across all builds in ten order-independent checks (top 10 with tie-breaks, full-result hashes, a key that is also an argument, nullable keys, 24- and 6-byte keys, HAVING c > 1, a forced spill). 64 adaptive-aggregation and aggregation-spill stateless tests pass with the PR alone and with both changes.

Not resolved: the 16-byte key's remaining 3.2%. In the earlier profile, the other increases were in countPartitionGroups and drainAdaptivePartition. Restoring the old record layout on the PR build (key first at a compile-time offset, masking only the partial key word) did not change the 16-byte key time (0.997 [0.984, 1.010]). This VM has no PMU counters, so I could not tell stalls from extra instructions.

Limits. Everything was measured at 4 vCPU only (2 partitions per bucket), and the local builds show a smaller regression than the CI builds (Q32 about 4% vs 5.4%). The 32 KiB cap was a diagnostic applied at every producer count. A rule like 32 KiB up to 4 producers and the current 8/4 KiB above would give the measured setting here and keep the memory saving at 16 and 64 threads, but I did not measure other thread counts.

If they fit, both changes could go into a follow-up PR; the cap is a one-line change in forProducers.

Append-loop patch for current master (whitespace-insensitive view: the existing per-record loop moves unchanged into the else branch)
diff --git a/src/Interpreters/AdaptiveAggregation/Producer.cpp b/src/Interpreters/AdaptiveAggregation/Producer.cpp
index 1f8500d..3b21e45 100644
--- a/src/Interpreters/AdaptiveAggregation/Producer.cpp
+++ b/src/Interpreters/AdaptiveAggregation/Producer.cpp
@@ -837,6 +837,24 @@ AdaptiveStagedBytes NO_INLINE Aggregator::appendDelayedRecords(
         for (size_t batch_begin = 0; batch_begin < total; batch_begin += argument_rows.size())
         {
             const size_t batch_end = std::min(total, batch_begin + argument_rows.size());
+            if constexpr (!Record::with_variable_arguments)
+            {
+                /// The records of a fixed-width key with only fixed-size arguments have one size: the loop keeps just
+                /// the appends, and the batch adds up the bytes of its records once.
+                for (size_t i = batch_begin; i < batch_end; ++i)
+                {
+                    prefetch_append(i);
+                    const UInt64 hash = hashes[i];
+                    char * record = partitions.append(layout.partitionOf(hash), format.stride);
+                    argument_rows[i - batch_begin] = record;
+                    write_key(i, 0, format.writeHeader(record, hash, 0, format.stride));
+                    check_record(format, record, i, hash);
+                }
+                key_bytes += (batch_end - batch_begin) * format.keyBytes(0);
+                record_bytes += (batch_end - batch_begin) * format.stride;
+            }
+            else
+            {
                 for (size_t i = batch_begin; i < batch_end; ++i)
                 {
                     prefetch_append(i);
@@ -914,6 +932,7 @@ AdaptiveStagedBytes NO_INLINE Aggregator::appendDelayedRecords(
                     key_bytes += stored_key_size;
                     record_bytes += bytes;
                 }
+            }
 
             const size_t batch_rows = batch_end - batch_begin;
             for (const auto & field : argument_layout.fixed_fields)

@nihalzp

nihalzp commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

@snelheidai Thanks for the report. Fixed in #131003.

@snelheidai

Copy link
Copy Markdown

@nihalzp On the 4-vCPU Xeon where I measured the slowdown, #131003 removes only part of it. With official builds, Q32 stays about 4% slower than before #128495, and the 16-byte-key variant from my second comment (GROUP BY WatchID, toUInt64(ClientIP)) about 6%:

time ratio [95% CI], 4 vCPU Q32 16-byte key
master / before #128495 1.057 [1.043, 1.071] 1.065 [1.050, 1.079]
#131003 / before #128495 1.041 [1.026, 1.057] 1.062 [1.048, 1.076]
#131003 / master 0.985 [0.963, 1.008] 0.997 [0.984, 1.011]

Builds: before #128495 is master 9e17b5d0, master is ab16fef5, and #131003 is its CI build (ca1bf659 merged into ab16fef5). Master 5ce19842, which adds #130281, runs both queries as ab16fef5 does (Q32 1.003 [0.997, 1.009]). Q32 keeps the memory saving: 1627 MiB peak with #131003, 2009 MiB before.

Local builds of 9e17b5d0 with exactly the #128495 and #131003 diffs agree. There, #131003 makes Q32 1.4% faster (0.986 [0.983, 0.990]) and leaves it 2.4% slower than before #128495 (1.024 [1.016, 1.032]); the 16-byte key stays 4.7% slower (1.047 [1.033, 1.061]). Your c8a.16xlarge runs show Q32 faster than before; I have measured only this machine, a Xeon 8375C VM with 4 vCPUs.

The one-size append loop from my second comment, which #131003 does not include, is not a clean fix for the rest. On top of #131003 (local builds) it brings Q32 back to its time before #128495 (1.008 [0.998, 1.018]), but it makes the count-only query on the same keys 1.6% and 2.0% slower in two runs (1.016 [1.010, 1.022], 1.020 [1.015, 1.025]), so that query ends level with its time before #128495 instead of 1.7% faster. Its records go through the key-record loop (append_key_records) of appendDelayedRecords, which the patch does not change. In a profile, that function takes 17% more samples for this query, and the loop's disassembly has the same instructions with more values reloaded from the stack. So in this build the patch speeds up one loop of the function at the cost of the other, and I would not apply it as posted. Keeping the byte totals in loop-local variables instead did not help (Q32 1.002 [0.993, 1.012], count-only 1.024 [1.010, 1.038]).

Method: hits with 100M rows, warm page cache; server-side query time; a fresh server per round and build, 8 rounds in rotating order, geometric mean of the per-round ratios. Local builds are Release, clang-21, without ThinLTO. All builds return identical results in 11 order-independent checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants