Respect memory pool size when in GroupedHashAggregateStream when spilling is not possible
Which issue does this PR close?
- Closes #19286.
- Related to #13123
Rationale for this change
GroupedHashAggregateStream currently always reports that it can spill to the memory tracking subsystem even though this is dependent on the aggregation mode and the grouping order.
The optimistic logic in group_aggregate_batch also does not correctly take these conditions into account
What changes are included in this PR?
- Correctly set
MemoryConsumer::can_spillto reflect actual spilling behaviour - Align behaviour of
group_aggregate_batchandspill_previous_if_necessary
Are these changes tested?
Added additional test case to demonstrate problem. This may not actually be necessary since other tests started failing as well. Still working on correcting those.
Are there any user-facing changes?
Yes, memory exhaustion may be reported much earlier in the query pipeline than is currently the case. In my local tests with a per consumer memory limit of 32MiB, grouped aggregation would consume 480MiB in practice. This was then reported by ExternalSortExec which choked on trying to reserve that much memory.
~wasm test failure seems unrelated.~ seems to have been a fluke
Extended test failures are related to the changes in this PR. Will review as soon as I can.
I've extended this PR to include spill support for grouping by partial or fully sorted inputs. This fixed the previously failing tests.
run benchmarks
run benchmark external_aggr
๐ค ./gh_compare_branch.sh gh_compare_branch.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing issue_19286 (d9af260747d28f0188ec7c571c68c3b36d988182) to e914935660875bc415887ade3fea1f5e59bed5e1 diff using: tpch_mem clickbench_partitioned clickbench_extended
Results will be posted here when complete
๐ค: Benchmark completed
Details
Comparing HEAD and issue_19286
--------------------
Benchmark clickbench_extended.json
--------------------
โโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโ
โ Query โ HEAD โ issue_19286 โ Change โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ QQuery 0 โ 2768.36 ms โ 2781.27 ms โ no change โ
โ QQuery 1 โ 1210.78 ms โ 1206.99 ms โ no change โ
โ QQuery 2 โ 2327.35 ms โ 2416.15 ms โ no change โ
โ QQuery 3 โ 1183.49 ms โ 1180.56 ms โ no change โ
โ QQuery 4 โ 2325.06 ms โ 2298.98 ms โ no change โ
โ QQuery 5 โ 29417.81 ms โ 28624.36 ms โ no change โ
โ QQuery 6 โ 4148.20 ms โ 4091.45 ms โ no change โ
โ QQuery 7 โ 3650.20 ms โ 3630.43 ms โ no change โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโ
โ Benchmark Summary โ โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Total Time (HEAD) โ 47031.25ms โ
โ Total Time (issue_19286) โ 46230.18ms โ
โ Average Time (HEAD) โ 5878.91ms โ
โ Average Time (issue_19286) โ 5778.77ms โ
โ Queries Faster โ 0 โ
โ Queries Slower โ 0 โ
โ Queries with No Change โ 8 โ
โ Queries with Failure โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโ
--------------------
Benchmark clickbench_partitioned.json
--------------------
โโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโโ
โ Query โ HEAD โ issue_19286 โ Change โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ QQuery 0 โ 2.72 ms โ 2.58 ms โ +1.06x faster โ
โ QQuery 1 โ 50.10 ms โ 51.38 ms โ no change โ
โ QQuery 2 โ 138.01 ms โ 136.19 ms โ no change โ
โ QQuery 3 โ 157.51 ms โ 160.57 ms โ no change โ
โ QQuery 4 โ 1098.11 ms โ 1119.95 ms โ no change โ
โ QQuery 5 โ 1500.24 ms โ 1539.26 ms โ no change โ
โ QQuery 6 โ 2.32 ms โ 2.31 ms โ no change โ
โ QQuery 7 โ 56.13 ms โ 55.90 ms โ no change โ
โ QQuery 8 โ 1427.96 ms โ 1490.07 ms โ no change โ
โ QQuery 9 โ 1875.95 ms โ 1981.70 ms โ 1.06x slower โ
โ QQuery 10 โ 378.53 ms โ 362.97 ms โ no change โ
โ QQuery 11 โ 410.78 ms โ 411.68 ms โ no change โ
โ QQuery 12 โ 1344.05 ms โ 1409.03 ms โ no change โ
โ QQuery 13 โ 2038.46 ms โ 2032.92 ms โ no change โ
โ QQuery 14 โ 1263.64 ms โ 1304.08 ms โ no change โ
โ QQuery 15 โ 1257.14 ms โ 1228.76 ms โ no change โ
โ QQuery 16 โ 2647.13 ms โ 2698.07 ms โ no change โ
โ QQuery 17 โ 2641.55 ms โ 2717.83 ms โ no change โ
โ QQuery 18 โ 4998.71 ms โ 4972.88 ms โ no change โ
โ QQuery 19 โ 124.97 ms โ 125.49 ms โ no change โ
โ QQuery 20 โ 1930.71 ms โ 1928.07 ms โ no change โ
โ QQuery 21 โ 2261.38 ms โ 2211.14 ms โ no change โ
โ QQuery 22 โ 3892.42 ms โ 3826.63 ms โ no change โ
โ QQuery 23 โ 12536.42 ms โ 12495.60 ms โ no change โ
โ QQuery 24 โ 219.14 ms โ 205.82 ms โ +1.06x faster โ
โ QQuery 25 โ 460.07 ms โ 462.27 ms โ no change โ
โ QQuery 26 โ 225.23 ms โ 220.45 ms โ no change โ
โ QQuery 27 โ 2815.01 ms โ 2776.16 ms โ no change โ
โ QQuery 28 โ 24048.63 ms โ 23714.54 ms โ no change โ
โ QQuery 29 โ 1009.00 ms โ 1006.84 ms โ no change โ
โ QQuery 30 โ 1343.16 ms โ 1329.69 ms โ no change โ
โ QQuery 31 โ 1379.58 ms โ 1335.89 ms โ no change โ
โ QQuery 32 โ 4738.56 ms โ 4639.03 ms โ no change โ
โ QQuery 33 โ 5915.69 ms โ 6034.39 ms โ no change โ
โ QQuery 34 โ 6102.79 ms โ 6002.09 ms โ no change โ
โ QQuery 35 โ 2032.87 ms โ 1890.81 ms โ +1.08x faster โ
โ QQuery 36 โ 120.08 ms โ 119.18 ms โ no change โ
โ QQuery 37 โ 56.33 ms โ 57.36 ms โ no change โ
โ QQuery 38 โ 123.82 ms โ 119.64 ms โ no change โ
โ QQuery 39 โ 199.18 ms โ 190.88 ms โ no change โ
โ QQuery 40 โ 47.56 ms โ 44.04 ms โ +1.08x faster โ
โ QQuery 41 โ 42.18 ms โ 42.97 ms โ no change โ
โ QQuery 42 โ 36.59 ms โ 37.29 ms โ no change โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโ
โ Benchmark Summary โ โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Total Time (HEAD) โ 94950.38ms โ
โ Total Time (issue_19286) โ 94494.42ms โ
โ Average Time (HEAD) โ 2208.15ms โ
โ Average Time (issue_19286) โ 2197.54ms โ
โ Queries Faster โ 4 โ
โ Queries Slower โ 1 โ
โ Queries with No Change โ 38 โ
โ Queries with Failure โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโ
--------------------
Benchmark tpch_mem_sf1.json
--------------------
โโโโโโโโโโโโโโโโณโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโโ
โ Query โ HEAD โ issue_19286 โ Change โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ QQuery 1 โ 134.20 ms โ 136.34 ms โ no change โ
โ QQuery 2 โ 28.81 ms โ 30.21 ms โ no change โ
โ QQuery 3 โ 40.18 ms โ 40.19 ms โ no change โ
โ QQuery 4 โ 29.77 ms โ 30.70 ms โ no change โ
โ QQuery 5 โ 89.80 ms โ 90.01 ms โ no change โ
โ QQuery 6 โ 20.38 ms โ 20.15 ms โ no change โ
โ QQuery 7 โ 237.37 ms โ 230.91 ms โ no change โ
โ QQuery 8 โ 36.99 ms โ 38.81 ms โ no change โ
โ QQuery 9 โ 109.06 ms โ 107.79 ms โ no change โ
โ QQuery 10 โ 65.23 ms โ 65.33 ms โ no change โ
โ QQuery 11 โ 19.01 ms โ 18.58 ms โ no change โ
โ QQuery 12 โ 52.76 ms โ 51.70 ms โ no change โ
โ QQuery 13 โ 48.84 ms โ 50.40 ms โ no change โ
โ QQuery 14 โ 14.48 ms โ 15.95 ms โ 1.10x slower โ
โ QQuery 15 โ 24.77 ms โ 24.87 ms โ no change โ
โ QQuery 16 โ 27.06 ms โ 26.55 ms โ no change โ
โ QQuery 17 โ 164.84 ms โ 153.12 ms โ +1.08x faster โ
โ QQuery 18 โ 281.56 ms โ 285.74 ms โ no change โ
โ QQuery 19 โ 38.84 ms โ 39.09 ms โ no change โ
โ QQuery 20 โ 50.59 ms โ 50.12 ms โ no change โ
โ QQuery 21 โ 326.03 ms โ 327.57 ms โ no change โ
โ QQuery 22 โ 18.84 ms โ 18.21 ms โ no change โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโ
โ Benchmark Summary โ โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Total Time (HEAD) โ 1859.43ms โ
โ Total Time (issue_19286) โ 1852.34ms โ
โ Average Time (HEAD) โ 84.52ms โ
โ Average Time (issue_19286) โ 84.20ms โ
โ Queries Faster โ 1 โ
โ Queries Slower โ 1 โ
โ Queries with No Change โ 20 โ
โ Queries with Failure โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโ
๐ค ./gh_compare_branch.sh gh_compare_branch.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing issue_19286 (d9af260747d28f0188ec7c571c68c3b36d988182) to e914935660875bc415887ade3fea1f5e59bed5e1 diff using: external_aggr
Results will be posted here when complete
๐ค ./gh_compare_branch.sh gh_compare_branch.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing issue_19286 (d9af260747d28f0188ec7c571c68c3b36d988182) to e914935660875bc415887ade3fea1f5e59bed5e1 diff using: external_aggr
Results will be posted here when complete
๐ค ./gh_compare_branch.sh gh_compare_branch.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing issue_19286 (d9af260747d28f0188ec7c571c68c3b36d988182) to e914935660875bc415887ade3fea1f5e59bed5e1 diff using: external_aggr
Results will be posted here when complete
Benchmark runner seems to be struggling
Benchmark runner seems to be struggling
It seems that the benchmark doesn't complete on main (I haven't tried on this branch)
Running `/Users/andrewlamb/Software/datafusion/target/release/external_aggr benchmark --partitions 4 --iterations 5 --path /Users/andrewlamb/Software/datafusion/benchmarks/data/tpch_sf1 -o /Users/andrewlamb/Software/datafusion/benchmarks/results/main/external_aggr.json`
Q1(64.0 MB) iteration 0 took 66.5 ms and returned 1 rows
Q1(64.0 MB) iteration 1 took 40.4 ms and returned 1 rows
Q1(64.0 MB) iteration 2 took 41.3 ms and returned 1 rows
Q1(64.0 MB) iteration 3 took 43.1 ms and returned 1 rows
Q1(64.0 MB) iteration 4 took 40.6 ms and returned 1 rows
Q1(64.0 MB) avg time: 46.38 ms
Error: Shared(ResourcesExhausted("Failed to allocate additional 1850.4 KB for GroupedHashAggregateStream[1] () with 1812.6 KB already allocated for this reservation - 2.7 MB remain available for the total pool"))
Interesting. Iโll have a look at that tomorrow.
I've taken a less conservative approach in my last commit in an attempt to make the OOM handling strategy easier to follow. There's more code inlined into the poll_next implementation now making that method a bit longer, but I think it's easier to understand this way.
@alamb I haven't had a chance to verify if the benchmarks now do pass yet. I'll do that next.
run benchmarks
๐ค ./gh_compare_branch.sh gh_compare_branch.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing issue_19286 (c01a68a5e6c6c449bec545d8d5840a1f8ea290ab) to 2e95f2673ff47c2fc957020d7aca80a27628f472 diff using: tpch_mem clickbench_partitioned clickbench_extended
Results will be posted here when complete
Regarding the external_aggr benchmark, for me it already fails to run on main so I don't think this is a regression. I'll try to see if we can fix this next.
๐ค: Benchmark completed
Details
Comparing HEAD and issue_19286
--------------------
Benchmark clickbench_extended.json
--------------------
โโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโ
โ Query โ HEAD โ issue_19286 โ Change โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ QQuery 0 โ 2836.89 ms โ 2798.95 ms โ no change โ
โ QQuery 1 โ 1290.73 ms โ 1303.25 ms โ no change โ
โ QQuery 2 โ 2528.97 ms โ 2473.68 ms โ no change โ
โ QQuery 3 โ 1172.05 ms โ 1142.70 ms โ no change โ
โ QQuery 4 โ 2340.80 ms โ 2357.78 ms โ no change โ
โ QQuery 5 โ 29450.83 ms โ 29413.10 ms โ no change โ
โ QQuery 6 โ 3893.82 ms โ 3978.39 ms โ no change โ
โ QQuery 7 โ 3844.76 ms โ 3737.40 ms โ no change โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโ
โ Benchmark Summary โ โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Total Time (HEAD) โ 47358.85ms โ
โ Total Time (issue_19286) โ 47205.26ms โ
โ Average Time (HEAD) โ 5919.86ms โ
โ Average Time (issue_19286) โ 5900.66ms โ
โ Queries Faster โ 0 โ
โ Queries Slower โ 0 โ
โ Queries with No Change โ 8 โ
โ Queries with Failure โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโ
--------------------
Benchmark clickbench_partitioned.json
--------------------
โโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโโ
โ Query โ HEAD โ issue_19286 โ Change โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ QQuery 0 โ 2.18 ms โ 2.33 ms โ 1.07x slower โ
โ QQuery 1 โ 51.91 ms โ 50.73 ms โ no change โ
โ QQuery 2 โ 143.37 ms โ 142.11 ms โ no change โ
โ QQuery 3 โ 155.14 ms โ 159.57 ms โ no change โ
โ QQuery 4 โ 1131.44 ms โ 1155.16 ms โ no change โ
โ QQuery 5 โ 1508.29 ms โ 1555.65 ms โ no change โ
โ QQuery 6 โ 2.18 ms โ 2.25 ms โ no change โ
โ QQuery 7 โ 57.23 ms โ 57.08 ms โ no change โ
โ QQuery 8 โ 1458.32 ms โ 1474.71 ms โ no change โ
โ QQuery 9 โ 1882.57 ms โ 1926.79 ms โ no change โ
โ QQuery 10 โ 361.95 ms โ 365.36 ms โ no change โ
โ QQuery 11 โ 417.80 ms โ 428.94 ms โ no change โ
โ QQuery 12 โ 1374.91 ms โ 1412.49 ms โ no change โ
โ QQuery 13 โ 2025.58 ms โ 2110.27 ms โ no change โ
โ QQuery 14 โ 1284.20 ms โ 1297.21 ms โ no change โ
โ QQuery 15 โ 1326.58 ms โ 1287.19 ms โ no change โ
โ QQuery 16 โ 2749.32 ms โ 2752.64 ms โ no change โ
โ QQuery 17 โ 2726.51 ms โ 2743.32 ms โ no change โ
โ QQuery 18 โ 5728.27 ms โ 5154.52 ms โ +1.11x faster โ
โ QQuery 19 โ 124.28 ms โ 123.58 ms โ no change โ
โ QQuery 20 โ 1963.88 ms โ 1900.65 ms โ no change โ
โ QQuery 21 โ 2293.42 ms โ 2253.69 ms โ no change โ
โ QQuery 22 โ 3859.63 ms โ 3849.41 ms โ no change โ
โ QQuery 23 โ 12701.55 ms โ 12415.39 ms โ no change โ
โ QQuery 24 โ 204.18 ms โ 219.63 ms โ 1.08x slower โ
โ QQuery 25 โ 468.83 ms โ 463.39 ms โ no change โ
โ QQuery 26 โ 220.69 ms โ 223.55 ms โ no change โ
โ QQuery 27 โ 2908.46 ms โ 2784.59 ms โ no change โ
โ QQuery 28 โ 23922.68 ms โ 24701.41 ms โ no change โ
โ QQuery 29 โ 962.69 ms โ 968.42 ms โ no change โ
โ QQuery 30 โ 1376.78 ms โ 1368.46 ms โ no change โ
โ QQuery 31 โ 1369.13 ms โ 1359.51 ms โ no change โ
โ QQuery 32 โ 6322.97 ms โ 5296.08 ms โ +1.19x faster โ
โ QQuery 33 โ 6749.43 ms โ 5997.04 ms โ +1.13x faster โ
โ QQuery 34 โ 6341.35 ms โ 6785.67 ms โ 1.07x slower โ
โ QQuery 35 โ 2067.96 ms โ 2001.26 ms โ no change โ
โ QQuery 36 โ 68.73 ms โ 66.96 ms โ no change โ
โ QQuery 37 โ 46.63 ms โ 46.55 ms โ no change โ
โ QQuery 38 โ 65.47 ms โ 68.93 ms โ 1.05x slower โ
โ QQuery 39 โ 101.38 ms โ 101.72 ms โ no change โ
โ QQuery 40 โ 28.53 ms โ 26.45 ms โ +1.08x faster โ
โ QQuery 41 โ 23.54 ms โ 23.84 ms โ no change โ
โ QQuery 42 โ 20.41 ms โ 20.58 ms โ no change โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโ
โ Benchmark Summary โ โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Total Time (HEAD) โ 98600.33ms โ
โ Total Time (issue_19286) โ 97145.10ms โ
โ Average Time (HEAD) โ 2293.03ms โ
โ Average Time (issue_19286) โ 2259.19ms โ
โ Queries Faster โ 4 โ
โ Queries Slower โ 4 โ
โ Queries with No Change โ 35 โ
โ Queries with Failure โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโ
--------------------
Benchmark tpch_mem_sf1.json
--------------------
โโโโโโโโโโโโโโโโณโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโโ
โ Query โ HEAD โ issue_19286 โ Change โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ QQuery 1 โ 144.12 ms โ 141.09 ms โ no change โ
โ QQuery 2 โ 29.65 ms โ 30.92 ms โ no change โ
โ QQuery 3 โ 35.15 ms โ 40.83 ms โ 1.16x slower โ
โ QQuery 4 โ 29.35 ms โ 30.08 ms โ no change โ
โ QQuery 5 โ 90.96 ms โ 89.65 ms โ no change โ
โ QQuery 6 โ 20.10 ms โ 20.11 ms โ no change โ
โ QQuery 7 โ 237.76 ms โ 259.68 ms โ 1.09x slower โ
โ QQuery 8 โ 36.82 ms โ 38.36 ms โ no change โ
โ QQuery 9 โ 111.21 ms โ 119.90 ms โ 1.08x slower โ
โ QQuery 10 โ 65.79 ms โ 65.90 ms โ no change โ
โ QQuery 11 โ 17.88 ms โ 18.52 ms โ no change โ
โ QQuery 12 โ 52.24 ms โ 53.32 ms โ no change โ
โ QQuery 13 โ 47.78 ms โ 49.95 ms โ no change โ
โ QQuery 14 โ 14.38 ms โ 14.86 ms โ no change โ
โ QQuery 15 โ 24.74 ms โ 25.28 ms โ no change โ
โ QQuery 16 โ 26.17 ms โ 27.60 ms โ 1.05x slower โ
โ QQuery 17 โ 155.89 ms โ 163.55 ms โ no change โ
โ QQuery 18 โ 301.87 ms โ 297.74 ms โ no change โ
โ QQuery 19 โ 47.81 ms โ 37.74 ms โ +1.27x faster โ
โ QQuery 20 โ 64.98 ms โ 52.47 ms โ +1.24x faster โ
โ QQuery 21 โ 332.02 ms โ 331.67 ms โ no change โ
โ QQuery 22 โ 18.32 ms โ 18.26 ms โ no change โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโ
โ Benchmark Summary โ โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Total Time (HEAD) โ 1904.99ms โ
โ Total Time (issue_19286) โ 1927.50ms โ
โ Average Time (HEAD) โ 86.59ms โ
โ Average Time (issue_19286) โ 87.61ms โ
โ Queries Faster โ 2 โ
โ Queries Slower โ 4 โ
โ Queries with No Change โ 16 โ
โ Queries with Failure โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโ
Regarding the
external_aggrbenchmark, for me it already fails to run onmainso I don't think this is a regression.
Agreed
I'll try to see if we can fix this next.
โค๏ธ
run benchmarks
I don't think the benchmarks show any actual peformance change, but I am rerunning them to be sure
๐ค ./gh_compare_branch.sh gh_compare_branch.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing issue_19286 (c01a68a5e6c6c449bec545d8d5840a1f8ea290ab) to 2e95f2673ff47c2fc957020d7aca80a27628f472 diff using: tpch_mem clickbench_partitioned clickbench_extended
Results will be posted here when complete
๐ค: Benchmark completed
Details
Comparing HEAD and issue_19286
--------------------
Benchmark clickbench_extended.json
--------------------
โโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโ
โ Query โ HEAD โ issue_19286 โ Change โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ QQuery 0 โ 2768.82 ms โ 2765.70 ms โ no change โ
โ QQuery 1 โ 1313.97 ms โ 1314.59 ms โ no change โ
โ QQuery 2 โ 2429.85 ms โ 2455.74 ms โ no change โ
โ QQuery 3 โ 1151.88 ms โ 1149.40 ms โ no change โ
โ QQuery 4 โ 2323.83 ms โ 2286.93 ms โ no change โ
โ QQuery 5 โ 28922.46 ms โ 29214.73 ms โ no change โ
โ QQuery 6 โ 3895.29 ms โ 3930.29 ms โ no change โ
โ QQuery 7 โ 3785.83 ms โ 3882.16 ms โ no change โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโ
โ Benchmark Summary โ โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Total Time (HEAD) โ 46591.94ms โ
โ Total Time (issue_19286) โ 46999.55ms โ
โ Average Time (HEAD) โ 5823.99ms โ
โ Average Time (issue_19286) โ 5874.94ms โ
โ Queries Faster โ 0 โ
โ Queries Slower โ 0 โ
โ Queries with No Change โ 8 โ
โ Queries with Failure โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโ
--------------------
Benchmark clickbench_partitioned.json
--------------------
โโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโโ
โ Query โ HEAD โ issue_19286 โ Change โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ QQuery 0 โ 2.22 ms โ 2.74 ms โ 1.23x slower โ
โ QQuery 1 โ 50.23 ms โ 51.30 ms โ no change โ
โ QQuery 2 โ 133.81 ms โ 139.80 ms โ no change โ
โ QQuery 3 โ 157.18 ms โ 159.65 ms โ no change โ
โ QQuery 4 โ 1092.15 ms โ 1153.74 ms โ 1.06x slower โ
โ QQuery 5 โ 1543.84 ms โ 1560.65 ms โ no change โ
โ QQuery 6 โ 2.14 ms โ 2.38 ms โ 1.11x slower โ
โ QQuery 7 โ 54.53 ms โ 57.03 ms โ no change โ
โ QQuery 8 โ 1479.46 ms โ 1502.51 ms โ no change โ
โ QQuery 9 โ 1958.82 ms โ 1917.22 ms โ no change โ
โ QQuery 10 โ 410.71 ms โ 364.92 ms โ +1.13x faster โ
โ QQuery 11 โ 442.14 ms โ 423.12 ms โ no change โ
โ QQuery 12 โ 1397.93 ms โ 1412.01 ms โ no change โ
โ QQuery 13 โ 2060.94 ms โ 2073.17 ms โ no change โ
โ QQuery 14 โ 1286.09 ms โ 1280.82 ms โ no change โ
โ QQuery 15 โ 1277.17 ms โ 1312.64 ms โ no change โ
โ QQuery 16 โ 2757.65 ms โ 2767.15 ms โ no change โ
โ QQuery 17 โ 2729.83 ms โ 2717.40 ms โ no change โ
โ QQuery 18 โ 5939.06 ms โ 5162.20 ms โ +1.15x faster โ
โ QQuery 19 โ 125.56 ms โ 124.99 ms โ no change โ
โ QQuery 20 โ 1917.38 ms โ 1907.23 ms โ no change โ
โ QQuery 21 โ 2251.86 ms โ 2208.20 ms โ no change โ
โ QQuery 22 โ 3889.01 ms โ 3832.07 ms โ no change โ
โ QQuery 23 โ 13275.21 ms โ 12340.19 ms โ +1.08x faster โ
โ QQuery 24 โ 224.05 ms โ 212.70 ms โ +1.05x faster โ
โ QQuery 25 โ 461.66 ms โ 476.05 ms โ no change โ
โ QQuery 26 โ 213.19 ms โ 223.85 ms โ 1.05x slower โ
โ QQuery 27 โ 2866.67 ms โ 2782.98 ms โ no change โ
โ QQuery 28 โ 23819.06 ms โ 24724.33 ms โ no change โ
โ QQuery 29 โ 958.48 ms โ 960.03 ms โ no change โ
โ QQuery 30 โ 1366.33 ms โ 1330.67 ms โ no change โ
โ QQuery 31 โ 1375.98 ms โ 1341.69 ms โ no change โ
โ QQuery 32 โ 5207.21 ms โ 5163.16 ms โ no change โ
โ QQuery 33 โ 6203.72 ms โ 6054.05 ms โ no change โ
โ QQuery 34 โ 6418.46 ms โ 5980.95 ms โ +1.07x faster โ
โ QQuery 35 โ 1981.89 ms โ 1949.05 ms โ no change โ
โ QQuery 36 โ 68.58 ms โ 68.12 ms โ no change โ
โ QQuery 37 โ 45.66 ms โ 46.57 ms โ no change โ
โ QQuery 38 โ 66.52 ms โ 69.46 ms โ no change โ
โ QQuery 39 โ 105.19 ms โ 105.74 ms โ no change โ
โ QQuery 40 โ 26.53 ms โ 28.57 ms โ 1.08x slower โ
โ QQuery 41 โ 24.16 ms โ 24.53 ms โ no change โ
โ QQuery 42 โ 20.46 ms โ 20.55 ms โ no change โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโ
โ Benchmark Summary โ โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Total Time (HEAD) โ 97688.73ms โ
โ Total Time (issue_19286) โ 96036.21ms โ
โ Average Time (HEAD) โ 2271.83ms โ
โ Average Time (issue_19286) โ 2233.40ms โ
โ Queries Faster โ 5 โ
โ Queries Slower โ 5 โ
โ Queries with No Change โ 33 โ
โ Queries with Failure โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโ
--------------------
Benchmark tpch_mem_sf1.json
--------------------
โโโโโโโโโโโโโโโโณโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโ
โ Query โ HEAD โ issue_19286 โ Change โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ QQuery 1 โ 138.48 ms โ 141.64 ms โ no change โ
โ QQuery 2 โ 28.19 ms โ 28.36 ms โ no change โ
โ QQuery 3 โ 36.25 ms โ 38.92 ms โ 1.07x slower โ
โ QQuery 4 โ 28.96 ms โ 29.67 ms โ no change โ
โ QQuery 5 โ 90.55 ms โ 91.09 ms โ no change โ
โ QQuery 6 โ 19.93 ms โ 20.31 ms โ no change โ
โ QQuery 7 โ 228.84 ms โ 240.87 ms โ 1.05x slower โ
โ QQuery 8 โ 35.72 ms โ 38.25 ms โ 1.07x slower โ
โ QQuery 9 โ 108.47 ms โ 111.29 ms โ no change โ
โ QQuery 10 โ 66.39 ms โ 63.70 ms โ no change โ
โ QQuery 11 โ 18.86 ms โ 18.68 ms โ no change โ
โ QQuery 12 โ 52.14 ms โ 52.21 ms โ no change โ
โ QQuery 13 โ 46.80 ms โ 49.45 ms โ 1.06x slower โ
โ QQuery 14 โ 14.08 ms โ 13.93 ms โ no change โ
โ QQuery 15 โ 25.02 ms โ 25.20 ms โ no change โ
โ QQuery 16 โ 25.06 ms โ 25.40 ms โ no change โ
โ QQuery 17 โ 154.48 ms โ 156.04 ms โ no change โ
โ QQuery 18 โ 287.30 ms โ 287.54 ms โ no change โ
โ QQuery 19 โ 38.08 ms โ 37.04 ms โ no change โ
โ QQuery 20 โ 50.96 ms โ 50.11 ms โ no change โ
โ QQuery 21 โ 309.00 ms โ 311.44 ms โ no change โ
โ QQuery 22 โ 18.31 ms โ 18.11 ms โ no change โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโ
โ Benchmark Summary โ โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Total Time (HEAD) โ 1821.86ms โ
โ Total Time (issue_19286) โ 1849.24ms โ
โ Average Time (HEAD) โ 82.81ms โ
โ Average Time (issue_19286) โ 84.06ms โ
โ Queries Faster โ 0 โ
โ Queries Slower โ 4 โ
โ Queries with No Change โ 18 โ
โ Queries with Failure โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโ
@alamb https://github.com/apache/datafusion/pull/19287/commits/9f2f22ef0c7ecfd2d8a504308079c1831be79949 makes the external_aggr benchmark succeed.
Because I was setting can spill: false for OutOfMemoryMode::EmitEarly, there was in effect still greedy memory reservation despite the use of FairSpillPool. That was causing one of the streams to not be able to reserve even a minuscule amount of memory.
Additionally the 'emit early' code would only kick in if there was at least one full batch of group values to emit. I've modified the code to still try to do that if it can, but fall back to emitting a smaller batch if memory pressure requires it.
One remaining question I have is how skip_aggregation_probe and group_values_soft_limit are expected to interact with the memory reservation system.
In SkipAggregationProbe::update_state the total number of input rows is accumulated, but the only the current number of group values is compared against that. If disk spilling or early emission is in effect, then the consequence is that the ratio will only decrease since the denominator of the ratio keeps on increasing. In other words, it's unlikely to ever kick in.
The same goes for group_values_soft_limit. It's compared against the number of group values that are held in memory by the aggregation stream itself. If we keep flushing values either down the pipeline or to disk, it's also unlikely to ever trigger.
I think this one is ready to go. I'll just update it once more and run benchmarks one more time to make me feel better and plan to merge it in
run benchmark clickbench_partitioned
๐ค ./gh_compare_branch.sh gh_compare_branch.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing issue_19286 (2ea0e3debd644ed27fffbb6ab7cab922d45693b7) to ead8209803770773980fafaf0fc622bb606be0ee diff using: clickbench_partitioned
Results will be posted here when complete
run benchmark tpch
๐ค: Benchmark completed
Details
Comparing HEAD and issue_19286
--------------------
Benchmark clickbench_partitioned.json
--------------------
โโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโโ
โ Query โ HEAD โ issue_19286 โ Change โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ QQuery 0 โ 2.29 ms โ 2.54 ms โ 1.11x slower โ
โ QQuery 1 โ 49.15 ms โ 49.71 ms โ no change โ
โ QQuery 2 โ 135.30 ms โ 131.44 ms โ no change โ
โ QQuery 3 โ 158.94 ms โ 152.10 ms โ no change โ
โ QQuery 4 โ 1077.08 ms โ 1094.73 ms โ no change โ
โ QQuery 5 โ 1504.96 ms โ 1499.92 ms โ no change โ
โ QQuery 6 โ 2.17 ms โ 2.10 ms โ no change โ
โ QQuery 7 โ 55.89 ms โ 55.15 ms โ no change โ
โ QQuery 8 โ 1444.52 ms โ 1446.30 ms โ no change โ
โ QQuery 9 โ 1867.87 ms โ 1866.52 ms โ no change โ
โ QQuery 10 โ 362.73 ms โ 362.69 ms โ no change โ
โ QQuery 11 โ 415.56 ms โ 423.89 ms โ no change โ
โ QQuery 12 โ 1348.89 ms โ 1347.85 ms โ no change โ
โ QQuery 13 โ 2007.19 ms โ 2053.80 ms โ no change โ
โ QQuery 14 โ 1286.53 ms โ 1277.48 ms โ no change โ
โ QQuery 15 โ 1266.86 ms โ 1283.56 ms โ no change โ
โ QQuery 16 โ 2680.37 ms โ 2685.34 ms โ no change โ
โ QQuery 17 โ 2667.04 ms โ 2684.80 ms โ no change โ
โ QQuery 18 โ 5779.79 ms โ 4956.34 ms โ +1.17x faster โ
โ QQuery 19 โ 123.39 ms โ 122.35 ms โ no change โ
โ QQuery 20 โ 1979.79 ms โ 1893.95 ms โ no change โ
โ QQuery 21 โ 2249.46 ms โ 2178.91 ms โ no change โ
โ QQuery 22 โ 3832.69 ms โ 3714.92 ms โ no change โ
โ QQuery 23 โ 18395.94 ms โ 12136.24 ms โ +1.52x faster โ
โ QQuery 24 โ 215.60 ms โ 212.90 ms โ no change โ
โ QQuery 25 โ 463.47 ms โ 452.82 ms โ no change โ
โ QQuery 26 โ 227.38 ms โ 226.94 ms โ no change โ
โ QQuery 27 โ 2828.96 ms โ 2760.40 ms โ no change โ
โ QQuery 28 โ 25164.08 ms โ 21938.93 ms โ +1.15x faster โ
โ QQuery 29 โ 964.94 ms โ 974.72 ms โ no change โ
โ QQuery 30 โ 1364.88 ms โ 1316.22 ms โ no change โ
โ QQuery 31 โ 1356.24 ms โ 1322.71 ms โ no change โ
โ QQuery 32 โ 5098.17 ms โ 5120.02 ms โ no change โ
โ QQuery 33 โ 6036.11 ms โ 5869.18 ms โ no change โ
โ QQuery 34 โ 6409.47 ms โ 6356.96 ms โ no change โ
โ QQuery 35 โ 1986.02 ms โ 1939.25 ms โ no change โ
โ QQuery 36 โ 66.26 ms โ 70.39 ms โ 1.06x slower โ
โ QQuery 37 โ 45.43 ms โ 44.82 ms โ no change โ
โ QQuery 38 โ 67.59 ms โ 66.48 ms โ no change โ
โ QQuery 39 โ 105.42 ms โ 100.53 ms โ no change โ
โ QQuery 40 โ 27.78 ms โ 26.24 ms โ +1.06x faster โ
โ QQuery 41 โ 24.04 ms โ 23.77 ms โ no change โ
โ QQuery 42 โ 21.02 ms โ 19.77 ms โ +1.06x faster โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโ
โ Benchmark Summary โ โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Total Time (HEAD) โ 103167.27ms โ
โ Total Time (issue_19286) โ 92265.70ms โ
โ Average Time (HEAD) โ 2399.24ms โ
โ Average Time (issue_19286) โ 2145.71ms โ
โ Queries Faster โ 5 โ
โ Queries Slower โ 2 โ
โ Queries with No Change โ 36 โ
โ Queries with Failure โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ