Skip to content

perf: avoid quadratic planning for SELECTs with many aggregates - #25739

Merged
alamb merged 2 commits into
apache:mainfrom
1fanwang:1fanwang-datafusion-issue-prioritization
Oct 1, 2026
Merged

alamb merged 2 commits into
apache:mainfrom
1fanwang:1fanwang-datafusion-issue-prioritization

Conversation

@1fanwang

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Planning a SELECT with many aggregate expressions takes time that grows with the square of the number of expressions. The report measured 2.7 s of SQL planning for 2,500 items, and a profile shows almost all of it goes into building the projection above the aggregate.

For each select item, the planner replaces sub-expressions that the aggregate already computes with references to its output columns. It rebuilt the lookup table of those expressions for every item, so N items built N tables of N entries. Hashing an aggregate expression also hashes its function signature, which makes each rebuild slow.

What changes are included in this PR?

  • The projection builder now builds that table once and reuses it for every item, through a crate-private Columnizer. columnize_expr keeps its signature and uses the same helper. This follows perf: reuse column normalization context across expressions #25010, which reuses the column normalization context in the same function.
  • The sql_planner benchmark gains a case with 1,000 aggregates.

Very wide selects still do some quadratic work. Two SQL planner helpers, rebase_expr and find_aggregate_exprs, compare each expression against a list, and schema field lookups scan every field. I'd rather handle those in separate PRs, so this one only references the issue.

What is the testing strategy for this PR?

The rewrite gives the same result as before, so the existing expression, SQL planner and optimizer tests and the sqllogictest suite cover it, and they pass locally.

sql_planner benchmark against main on an 18-core M-series Mac, release-nonlto:

Benchmark main this PR change
logical_wide_aggregate_1000_exprs (new) 182.3 ms 31.1 ms -83%
logical_wide_aggregate_100_exprs 2.43 ms 0.89 ms -63%
physical_select_aggregates_from_200 6.98 ms 4.69 ms -33%

The query shape from the issue, CAST(sum(id + i) AS VARCHAR) repeated N times, planned with EXPLAIN in datafusion-cli (unoptimized ci build, so absolute times are high):

N main this PR
500 0.72 s 0.66 s
1000 1.56 s 0.87 s
2000 5.05 s 1.83 s
4000 18.83 s 4.57 s
Commands and raw output

Benchmarks. The new case is copied onto main so both runs measure the same queries. The sql_planner bench checks that benchmarks/data/hits_partitioned exists at startup; I used a one-row stand-in, since none of these three cases read it.

PR=eb8f5ce9d4d0b50cffb97648188c84a4034ec92c
git fetch origin main "$PR"
git switch --detach origin/main
git checkout "$PR" -- datafusion/core/benches/sql_planner.rs
cargo bench -p datafusion --bench sql_planner --profile release-nonlto -- \
  'logical_wide_aggregate|physical_select_aggregates_from_200' --save-baseline main
git checkout -f "$PR"
cargo bench -p datafusion --bench sql_planner --profile release-nonlto -- \
  'logical_wide_aggregate|physical_select_aggregates_from_200' --baseline main

main:

physical_select_aggregates_from_200
                        time:   [6.8908 ms 6.9799 ms 7.0789 ms]
logical_wide_aggregate_100_exprs
                        time:   [2.3629 ms 2.4285 ms 2.4977 ms]
logical_wide_aggregate_1000_exprs
                        time:   [180.60 ms 182.29 ms 184.28 ms]

This PR:

physical_select_aggregates_from_200
                        time:   [4.6522 ms 4.6890 ms 4.7269 ms]
                        change: [−33.854% −32.821% −31.767%] (p = 0.00 < 0.05)
                        Performance has improved.
logical_wide_aggregate_100_exprs
                        time:   [881.22 µs 888.79 µs 897.96 µs]
                        change: [−63.824% −62.709% −61.533%] (p = 0.00 < 0.05)
                        Performance has improved.
logical_wide_aggregate_1000_exprs
                        time:   [30.705 ms 31.131 ms 31.628 ms]
                        change: [−83.222% −82.922% −82.577%] (p = 0.00 < 0.05)
                        Performance has improved.

datafusion-cli timing, with the CLI built by cargo build --profile ci -p datafusion-cli on each side:

#!/usr/bin/env bash
# Usage: wide-timing.sh <datafusion-cli>
set -euo pipefail
python3 - <<'EOF'
for n in (500, 1000, 2000, 4000):
    items = ', '.join(f'CAST(sum(id + {i}) AS VARCHAR) AS c{i}' for i in range(n))
    with open(f'wide_{n}.sql', 'w') as f:
        f.write('CREATE TABLE t AS SELECT value AS id FROM range(1000);\n')
        f.write(f'EXPLAIN SELECT {items} FROM t;\n')
EOF
for n in 500 1000 2000 4000; do
  /usr/bin/time -p "$1" -q -f "wide_$n.sql" 2>&1 >/dev/null | awk -v n="$n" '/^real/ {print "N=" n, $2 "s"}'
done
== main
N=500 0.72s
N=1000 1.56s
N=2000 5.05s
N=4000 18.83s
== this PR
N=500 0.66s
N=1000 0.87s
N=2000 1.83s
N=4000 4.57s

Are there any user-facing changes?

No. Planning is faster, and columnize_expr keeps its signature and behavior.

Building the projection above an aggregate rebuilt the lookup of the
aggregate's output expressions for every select item. Build it once per
projection and reuse it.

Signed-off-by: Stefan Wang <[email protected]>
@github-actions github-actions Bot added logical-expr Logical plan and expressions core Core DataFusion crate labels Sep 25, 2026
@codecov-commenter

codecov-commenter commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.28571% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.60%. Comparing base (9e2b90c) to head (0d15009).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/expr/src/logical_plan/builder.rs 40.00% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25739      +/-   ##
==========================================
- Coverage   82.60%   82.60%   -0.01%     
==========================================
  Files        1144     1144              
  Lines      442904   442915      +11     
  Branches   442904   442915      +11     
==========================================
+ Hits       365878   365884       +6     
- Misses      54874    54876       +2     
- Partials    22152    22155       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alamb

alamb commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Thanks @1fanwang

Can you please submit the benchmark as a separate PR so we can use our automated benchmark bot to compare them?

@alamb

alamb commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

run benchmark sql_planner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c5834836165-2735-d9pb4 6.12.94+ #1 SMP Wed Aug 19 07:47:20 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing 1fanwang-datafusion-issue-prioritization (eb8f5ce) to 696eaf5 (merge-base) diff

Run configuration
run benchmark sql_planner

Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

Comparing 1fanwang-datafusion-issue-prioritization (eb8f5ce) to 696eaf5 (merge-base) diff

Run configuration
run benchmark sql_planner
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                                                 1fanwang-datafusion-issue-prioritization    HEAD
-----                                                 ----------------------------------------    ----
logical_aggregate_with_join                           1.00    406.1±2.07µs        ? ?/sec         1.01    412.2±1.47µs        ? ?/sec
logical_correlated_subquery_exists                    1.01    248.9±1.79µs        ? ?/sec         1.00    247.4±1.84µs        ? ?/sec
logical_correlated_subquery_in                        1.00    250.0±0.92µs        ? ?/sec         1.01    251.9±1.01µs        ? ?/sec
logical_distinct_many_columns                         1.00    332.7±1.29µs        ? ?/sec         1.00    334.0±1.62µs        ? ?/sec
logical_join_4_with_agg_and_filter                    1.00    199.5±0.88µs        ? ?/sec         1.00    200.1±0.94µs        ? ?/sec
logical_join_8_with_agg_sort_limit                    1.00    357.5±2.44µs        ? ?/sec         1.05    374.3±1.53µs        ? ?/sec
logical_join_chain_16                                 1.00    634.0±1.54µs        ? ?/sec         1.01    639.9±5.01µs        ? ?/sec
logical_join_chain_4                                  1.00     79.5±0.34µs        ? ?/sec         1.00     79.9±0.24µs        ? ?/sec
logical_join_chain_8                                  1.00    207.8±0.98µs        ? ?/sec         1.00    208.0±0.50µs        ? ?/sec
logical_multiple_subqueries                           1.02    492.3±4.89µs        ? ?/sec         1.00    484.3±3.27µs        ? ?/sec
logical_nested_cte_4_levels                           1.00    220.3±1.98µs        ? ?/sec         1.00    219.3±1.51µs        ? ?/sec
logical_plan_struct_join_agg_sort                     1.00    125.4±1.48µs        ? ?/sec         1.04    130.4±1.10µs        ? ?/sec
logical_plan_tpcds_all                                1.00     82.3±1.45ms        ? ?/sec         1.02     83.8±0.20ms        ? ?/sec
logical_plan_tpch_all                                 1.00      5.5±0.01ms        ? ?/sec         1.02      5.6±0.02ms        ? ?/sec
logical_scalar_subquery                               1.01    271.5±3.55µs        ? ?/sec         1.00    268.2±1.76µs        ? ?/sec
logical_select_all_from_1000                          1.01      9.2±0.08ms        ? ?/sec         1.00      9.1±0.05ms        ? ?/sec
logical_select_one_from_700                           1.00    293.5±2.11µs        ? ?/sec         1.02    298.1±1.45µs        ? ?/sec
logical_trivial_join_high_numbered_columns            1.00    251.3±4.17µs        ? ?/sec         1.00    251.4±1.21µs        ? ?/sec
logical_trivial_join_low_numbered_columns             1.00    238.3±2.30µs        ? ?/sec         1.00    238.7±1.52µs        ? ?/sec
logical_union_4_branches                              1.00    388.2±1.58µs        ? ?/sec         1.01    390.7±1.55µs        ? ?/sec
logical_union_8_branches                              1.00    788.7±4.79µs        ? ?/sec         1.01    793.1±4.48µs        ? ?/sec
logical_wide_aggregate_1000_exprs                     1.00     44.0±0.35ms        ? ?/sec       
logical_wide_aggregate_100_exprs                      1.00  1640.9±13.29µs        ? ?/sec         2.39      3.9±0.01ms        ? ?/sec
logical_wide_case_50_exprs                            1.00   1810.3±8.92µs        ? ?/sec         1.00  1815.5±16.76µs        ? ?/sec
logical_wide_filter_200_predicates                    1.02   1346.8±8.58µs        ? ?/sec         1.00   1325.1±6.89µs        ? ?/sec
logical_wide_filter_50_predicates                     1.01    363.4±1.88µs        ? ?/sec         1.00    361.0±1.86µs        ? ?/sec
optimizer_correlated_exists                           1.00    226.6±1.26µs        ? ?/sec         1.00    227.2±0.81µs        ? ?/sec
optimizer_join_4_with_agg_filter                      1.00    407.6±1.21µs        ? ?/sec         1.00    407.8±1.74µs        ? ?/sec
optimizer_join_chain_4                                1.00    158.7±0.63µs        ? ?/sec         1.00    159.1±0.21µs        ? ?/sec
optimizer_join_chain_8                                1.00    545.6±1.33µs        ? ?/sec         1.00    544.8±0.74µs        ? ?/sec
optimizer_select_all_from_1000                        1.00      6.8±0.03ms        ? ?/sec         1.00      6.8±0.03ms        ? ?/sec
optimizer_select_one_from_700                         1.00    238.8±4.77µs        ? ?/sec         1.01    240.3±0.61µs        ? ?/sec
optimizer_tpcds_all                                   1.00    290.5±2.66ms        ? ?/sec         1.00    291.6±3.80ms        ? ?/sec
optimizer_tpch_all                                    1.01     15.9±0.10ms        ? ?/sec         1.00     15.8±0.19ms        ? ?/sec
optimizer_wide_aggregate_100                          1.00   1788.0±4.22µs        ? ?/sec         1.00   1780.1±4.17µs        ? ?/sec
optimizer_wide_filter_200                             1.00      4.0±0.01ms        ? ?/sec         1.01      4.0±0.05ms        ? ?/sec
physical_intersection                                 1.00    562.0±2.94µs        ? ?/sec         1.02    570.8±3.07µs        ? ?/sec
physical_join_consider_sort                           1.00   1033.4±1.77µs        ? ?/sec         1.01   1042.9±3.75µs        ? ?/sec
physical_join_distinct                                1.00    229.6±2.11µs        ? ?/sec         1.01    231.9±1.39µs        ? ?/sec
physical_many_self_joins                              1.01      7.9±0.14ms        ? ?/sec         1.00      7.8±0.10ms        ? ?/sec
physical_plan_clickbench_all                          1.00    140.1±8.24ms        ? ?/sec         1.13   158.1±16.78ms        ? ?/sec
physical_plan_clickbench_q1                           1.00  1340.6±22.78µs        ? ?/sec         1.04  1391.5±91.03µs        ? ?/sec
physical_plan_clickbench_q10                          1.00      2.0±0.01ms        ? ?/sec         1.04      2.1±0.15ms        ? ?/sec
physical_plan_clickbench_q11                          1.00      2.2±0.17ms        ? ?/sec         1.03      2.3±0.22ms        ? ?/sec
physical_plan_clickbench_q12                          1.00      2.3±0.01ms        ? ?/sec         1.00      2.3±0.01ms        ? ?/sec
physical_plan_clickbench_q13                          1.00      2.4±0.31ms        ? ?/sec         1.08      2.6±0.07ms        ? ?/sec
physical_plan_clickbench_q14                          1.03      2.4±0.29ms        ? ?/sec         1.00      2.4±0.26ms        ? ?/sec
physical_plan_clickbench_q15                          1.08      2.3±0.26ms        ? ?/sec         1.00      2.1±0.01ms        ? ?/sec
physical_plan_clickbench_q16                          1.00  1786.2±45.18µs        ? ?/sec         1.08  1926.5±194.40µs        ? ?/sec
physical_plan_clickbench_q17                          1.00   1829.4±6.22µs        ? ?/sec         1.04  1905.5±173.88µs        ? ?/sec
physical_plan_clickbench_q18                          1.08  1957.5±157.61µs        ? ?/sec        1.00  1807.0±194.54µs        ? ?/sec
physical_plan_clickbench_q19                          1.08      2.3±0.25ms        ? ?/sec         1.00      2.1±0.11ms        ? ?/sec
physical_plan_clickbench_q2                           1.06  1838.2±192.17µs        ? ?/sec        1.00  1731.9±39.88µs        ? ?/sec
physical_plan_clickbench_q20                          1.01  1539.7±93.28µs        ? ?/sec         1.00  1519.1±32.38µs        ? ?/sec
physical_plan_clickbench_q21                          1.01  1728.0±68.84µs        ? ?/sec         1.00  1716.8±20.29µs        ? ?/sec
physical_plan_clickbench_q22                          1.00      2.1±0.01ms        ? ?/sec         1.06      2.3±0.24ms        ? ?/sec
physical_plan_clickbench_q23                          1.21      2.8±0.26ms        ? ?/sec         1.00      2.3±0.14ms        ? ?/sec
physical_plan_clickbench_q24                          1.00      5.6±0.22ms        ? ?/sec         1.07      6.0±0.29ms        ? ?/sec
physical_plan_clickbench_q25                          1.00  1877.5±49.70µs        ? ?/sec         1.04  1944.9±155.42µs        ? ?/sec
physical_plan_clickbench_q26                          1.00  1761.4±123.92µs        ? ?/sec        1.01  1776.4±110.92µs        ? ?/sec
physical_plan_clickbench_q27                          1.00  1937.7±137.42µs        ? ?/sec        1.00  1933.2±135.27µs        ? ?/sec
physical_plan_clickbench_q28                          1.00      2.2±0.01ms        ? ?/sec         1.01      2.3±0.01ms        ? ?/sec
physical_plan_clickbench_q29                          1.11      3.1±0.03ms        ? ?/sec         1.00      2.8±0.33ms        ? ?/sec
physical_plan_clickbench_q3                           1.00  1659.2±106.30µs        ? ?/sec        1.11  1839.4±176.81µs        ? ?/sec
physical_plan_clickbench_q30                          1.00     13.1±0.38ms        ? ?/sec         1.18     15.5±0.41ms        ? ?/sec
physical_plan_clickbench_q31                          1.00      2.4±0.01ms        ? ?/sec         1.06      2.5±0.26ms        ? ?/sec
physical_plan_clickbench_q32                          1.00      2.4±0.01ms        ? ?/sec         1.00      2.4±0.01ms        ? ?/sec
physical_plan_clickbench_q33                          1.06      2.1±0.24ms        ? ?/sec         1.00      2.0±0.04ms        ? ?/sec
physical_plan_clickbench_q34                          1.00   1779.7±6.22µs        ? ?/sec         1.05  1870.8±158.33µs        ? ?/sec
physical_plan_clickbench_q35                          1.15      2.2±0.24ms        ? ?/sec         1.00  1902.9±92.79µs        ? ?/sec
physical_plan_clickbench_q36                          1.11      2.4±0.27ms        ? ?/sec         1.00      2.1±0.05ms        ? ?/sec
physical_plan_clickbench_q37                          1.00      2.7±0.28ms        ? ?/sec         1.00      2.7±0.26ms        ? ?/sec
physical_plan_clickbench_q38                          1.00      2.5±0.01ms        ? ?/sec         1.01      2.5±0.13ms        ? ?/sec
physical_plan_clickbench_q39                          1.00      2.6±0.07ms        ? ?/sec         1.00      2.5±0.01ms        ? ?/sec
physical_plan_clickbench_q4                           1.00  1455.6±49.22µs        ? ?/sec         1.04  1511.9±127.21µs        ? ?/sec
physical_plan_clickbench_q40                          1.00      3.3±0.16ms        ? ?/sec         1.15      3.7±0.35ms        ? ?/sec
physical_plan_clickbench_q41                          1.16      3.3±0.33ms        ? ?/sec         1.00      2.9±0.18ms        ? ?/sec
physical_plan_clickbench_q42                          1.03      3.2±0.36ms        ? ?/sec         1.00      3.1±0.29ms        ? ?/sec
physical_plan_clickbench_q43                          1.00      3.1±0.01ms        ? ?/sec         1.05      3.2±0.29ms        ? ?/sec
physical_plan_clickbench_q44                          1.11  1696.2±208.74µs        ? ?/sec        1.00   1527.7±4.50µs        ? ?/sec
physical_plan_clickbench_q45                          1.00  1593.3±126.08µs        ? ?/sec        1.04  1659.4±169.50µs        ? ?/sec
physical_plan_clickbench_q46                          1.00  1918.5±169.49µs        ? ?/sec        1.06      2.0±0.23ms        ? ?/sec
physical_plan_clickbench_q47                          1.00      2.7±0.29ms        ? ?/sec         1.02      2.8±0.30ms        ? ?/sec
physical_plan_clickbench_q48                          1.00      2.7±0.15ms        ? ?/sec         1.03      2.8±0.28ms        ? ?/sec
physical_plan_clickbench_q49                          1.07      2.9±0.30ms        ? ?/sec         1.00      2.7±0.01ms        ? ?/sec
physical_plan_clickbench_q5                           1.00   1566.1±6.92µs        ? ?/sec         1.04  1628.8±123.76µs        ? ?/sec
physical_plan_clickbench_q50                          1.01      2.8±0.29ms        ? ?/sec         1.00      2.7±0.27ms        ? ?/sec
physical_plan_clickbench_q51                          1.00   1957.2±5.84µs        ? ?/sec         1.08      2.1±0.24ms        ? ?/sec
physical_plan_clickbench_q52                          1.11      3.0±0.26ms        ? ?/sec         1.00      2.7±0.29ms        ? ?/sec
physical_plan_clickbench_q53                          1.00  1809.8±96.69µs        ? ?/sec         1.00  1804.1±167.00µs        ? ?/sec
physical_plan_clickbench_q54                          1.00  1766.0±56.30µs        ? ?/sec         1.00   1761.1±5.85µs        ? ?/sec
physical_plan_clickbench_q55                          1.00   1680.4±4.79µs        ? ?/sec         1.01   1697.3±5.47µs        ? ?/sec
physical_plan_clickbench_q56                          1.00  1830.1±206.29µs        ? ?/sec        1.12      2.1±0.21ms        ? ?/sec
physical_plan_clickbench_q57                          1.00  1967.8±236.84µs        ? ?/sec        1.00  1960.0±212.85µs        ? ?/sec
physical_plan_clickbench_q58                          1.01      2.6±0.32ms        ? ?/sec         1.00      2.5±0.28ms        ? ?/sec
physical_plan_clickbench_q59                          1.00  1703.0±94.61µs        ? ?/sec         1.04  1773.3±113.18µs        ? ?/sec
physical_plan_clickbench_q6                           1.09  1757.3±195.59µs        ? ?/sec        1.00  1619.3±110.07µs        ? ?/sec
physical_plan_clickbench_q60                          1.00   1673.1±4.30µs        ? ?/sec         1.02   1714.9±9.94µs        ? ?/sec
physical_plan_clickbench_q7                           1.19  1676.9±202.79µs        ? ?/sec        1.00  1409.8±35.67µs        ? ?/sec
physical_plan_clickbench_q8                           1.00      2.1±0.27ms        ? ?/sec         1.02      2.2±0.28ms        ? ?/sec
physical_plan_clickbench_q9                           1.00  1944.6±119.45µs        ? ?/sec        1.06      2.1±0.21ms        ? ?/sec
physical_plan_struct_join_agg_sort                    1.00  1263.4±39.43µs        ? ?/sec         1.05  1323.1±16.41µs        ? ?/sec
physical_plan_tpcds_all                               1.00   672.2±21.84ms        ? ?/sec         1.01   677.2±22.65ms        ? ?/sec
physical_plan_tpch_all                                1.00     43.1±2.05ms        ? ?/sec         1.02     44.1±2.31ms        ? ?/sec
physical_plan_tpch_q1                                 1.00  1410.5±34.47µs        ? ?/sec         1.02  1435.6±27.10µs        ? ?/sec
physical_plan_tpch_q10                                1.00      2.9±0.14ms        ? ?/sec         1.04      3.0±0.02ms        ? ?/sec
physical_plan_tpch_q11                                1.01      2.3±0.14ms        ? ?/sec         1.00      2.3±0.13ms        ? ?/sec
physical_plan_tpch_q12                                1.01  1222.4±28.93µs        ? ?/sec         1.00   1216.1±2.42µs        ? ?/sec
physical_plan_tpch_q13                                1.00    999.7±2.21µs        ? ?/sec         1.00   1003.8±3.23µs        ? ?/sec
physical_plan_tpch_q14                                1.00   1303.4±2.76µs        ? ?/sec         1.03  1343.4±47.17µs        ? ?/sec
physical_plan_tpch_q16                                1.02  1650.7±87.69µs        ? ?/sec         1.00  1611.3±29.13µs        ? ?/sec
physical_plan_tpch_q17                                1.00  1606.0±52.19µs        ? ?/sec         1.07  1724.1±93.27µs        ? ?/sec
physical_plan_tpch_q18                                1.00  1899.1±63.46µs        ? ?/sec         1.01  1909.4±24.23µs        ? ?/sec
physical_plan_tpch_q19                                1.00   1798.2±2.75µs        ? ?/sec         1.03  1844.5±73.15µs        ? ?/sec
physical_plan_tpch_q2                                 1.00      3.5±0.00ms        ? ?/sec         1.01      3.5±0.00ms        ? ?/sec
physical_plan_tpch_q20                                1.00      2.0±0.00ms        ? ?/sec         1.05      2.1±0.14ms        ? ?/sec
physical_plan_tpch_q21                                1.10      3.0±0.18ms        ? ?/sec         1.00      2.7±0.00ms        ? ?/sec
physical_plan_tpch_q22                                1.00  1483.7±19.42µs        ? ?/sec         1.10  1629.6±44.54µs        ? ?/sec
physical_plan_tpch_q3                                 1.00  1802.6±98.09µs        ? ?/sec         1.00  1802.1±81.90µs        ? ?/sec
physical_plan_tpch_q4                                 1.00  1146.1±22.81µs        ? ?/sec         1.00  1143.4±27.48µs        ? ?/sec
physical_plan_tpch_q5                                 1.01      2.6±0.12ms        ? ?/sec         1.00      2.6±0.07ms        ? ?/sec
physical_plan_tpch_q6                                 1.01    581.1±1.39µs        ? ?/sec         1.00    574.6±2.00µs        ? ?/sec
physical_plan_tpch_q7                                 1.00      2.6±0.00ms        ? ?/sec         1.06      2.8±0.14ms        ? ?/sec
physical_plan_tpch_q8                                 1.02      3.7±0.21ms        ? ?/sec         1.00      3.7±0.09ms        ? ?/sec
physical_plan_tpch_q9                                 1.00      2.6±0.00ms        ? ?/sec         1.01      2.6±0.00ms        ? ?/sec
physical_select_aggregates_from_200                   1.00      7.7±0.02ms        ? ?/sec         1.62     12.5±0.16ms        ? ?/sec
physical_select_all_from_1000                         1.00     20.2±0.11ms        ? ?/sec         1.00     20.3±0.15ms        ? ?/sec
physical_select_one_from_700                          1.00    732.9±4.54µs        ? ?/sec         1.02    746.7±2.70µs        ? ?/sec
physical_sorted_union_order_by_10_int64               1.00      3.8±0.09ms        ? ?/sec         1.02      3.9±0.13ms        ? ?/sec
physical_sorted_union_order_by_10_uint64              1.00      7.5±0.11ms        ? ?/sec         1.00      7.5±0.01ms        ? ?/sec
physical_sorted_union_order_by_50_int64               1.00     85.0±1.78ms        ? ?/sec         1.00     85.2±1.75ms        ? ?/sec
physical_sorted_union_order_by_50_uint64              1.00   307.5±10.10ms        ? ?/sec         1.00   307.8±10.47ms        ? ?/sec
physical_theta_join_consider_sort                     1.00   1073.6±9.38µs        ? ?/sec         1.00  1077.7±12.01µs        ? ?/sec
physical_unnest_to_join                               1.00    614.5±2.84µs        ? ?/sec         1.01    619.4±2.80µs        ? ?/sec
physical_window_function_partition_by_12_on_values    1.00    651.2±1.50µs        ? ?/sec         1.01    656.2±2.91µs        ? ?/sec
physical_window_function_partition_by_30_on_values    1.01  1312.4±15.87µs        ? ?/sec         1.00   1304.7±3.11µs        ? ?/sec
physical_window_function_partition_by_4_on_values     1.00    397.6±1.14µs        ? ?/sec         1.01    400.8±1.38µs        ? ?/sec
physical_window_function_partition_by_7_on_values     1.00    488.8±1.43µs        ? ?/sec         1.02    497.2±2.86µs        ? ?/sec
physical_window_function_partition_by_8_on_values     1.00    523.6±1.65µs        ? ?/sec         1.01    528.1±2.47µs        ? ?/sec
with_param_values_many_columns                        1.00    438.7±3.34µs        ? ?/sec         1.00    439.1±2.19µs        ? ?/sec

Resource Usage

sql_planner — base (merge-base)

Metric Value
Wall time 2165.5s
Peak memory 137.1 MiB
Avg memory 84.0 MiB
CPU user 1988.1s
CPU sys 1.5s
Peak spill 0 B

sql_planner — branch

Metric Value
Wall time 2155.5s
Peak memory 143.7 MiB
Avg memory 88.0 MiB
CPU user 1985.8s
CPU sys 1.5s
Peak spill 0 B

File an issue against this benchmark runner

@alamb

alamb commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

run benchmark sql_planner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c5836593217-2759-pwskh 6.12.94+ #1 SMP Wed Aug 19 07:47:20 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing 1fanwang-datafusion-issue-prioritization (eb8f5ce) to 696eaf5 (merge-base) diff

Run configuration
run benchmark sql_planner

Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

Comparing 1fanwang-datafusion-issue-prioritization (eb8f5ce) to 696eaf5 (merge-base) diff

Run configuration
run benchmark sql_planner
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                                                 1fanwang-datafusion-issue-prioritization    HEAD
-----                                                 ----------------------------------------    ----
logical_aggregate_with_join                           1.00    407.5±2.08µs        ? ?/sec         1.00    407.5±1.78µs        ? ?/sec
logical_correlated_subquery_exists                    1.01    245.7±1.47µs        ? ?/sec         1.00    244.0±1.47µs        ? ?/sec
logical_correlated_subquery_in                        1.01    248.5±1.26µs        ? ?/sec         1.00    245.7±0.53µs        ? ?/sec
logical_distinct_many_columns                         1.00    334.2±1.86µs        ? ?/sec         1.00    333.3±1.14µs        ? ?/sec
logical_join_4_with_agg_and_filter                    1.00    200.0±0.44µs        ? ?/sec         1.00    200.1±0.82µs        ? ?/sec
logical_join_8_with_agg_sort_limit                    1.00    358.7±1.16µs        ? ?/sec         1.04    373.2±2.37µs        ? ?/sec
logical_join_chain_16                                 1.01    638.5±2.65µs        ? ?/sec         1.00    630.7±1.57µs        ? ?/sec
logical_join_chain_4                                  1.02     79.7±0.38µs        ? ?/sec         1.00     78.3±0.37µs        ? ?/sec
logical_join_chain_8                                  1.01    209.2±0.94µs        ? ?/sec         1.00    206.8±0.53µs        ? ?/sec
logical_multiple_subqueries                           1.00    480.0±1.65µs        ? ?/sec         1.00    478.6±1.87µs        ? ?/sec
logical_nested_cte_4_levels                           1.00    219.8±1.38µs        ? ?/sec         1.01    221.0±7.40µs        ? ?/sec
logical_plan_struct_join_agg_sort                     1.00    125.0±0.46µs        ? ?/sec         1.01    126.0±0.71µs        ? ?/sec
logical_plan_tpcds_all                                1.00     81.5±0.16ms        ? ?/sec         1.02     83.2±0.14ms        ? ?/sec
logical_plan_tpch_all                                 1.00      5.5±0.02ms        ? ?/sec         1.00      5.5±0.01ms        ? ?/sec
logical_scalar_subquery                               1.01    269.1±1.77µs        ? ?/sec         1.00    265.4±1.76µs        ? ?/sec
logical_select_all_from_1000                          1.00      9.1±0.02ms        ? ?/sec         1.00      9.1±0.03ms        ? ?/sec
logical_select_one_from_700                           1.00    292.7±1.64µs        ? ?/sec         1.01    294.6±1.68µs        ? ?/sec
logical_trivial_join_high_numbered_columns            1.00    248.5±1.42µs        ? ?/sec         1.00    248.5±1.37µs        ? ?/sec
logical_trivial_join_low_numbered_columns             1.00    236.5±1.26µs        ? ?/sec         1.00    235.6±1.28µs        ? ?/sec
logical_union_4_branches                              1.00    389.2±1.50µs        ? ?/sec         1.00    388.3±1.59µs        ? ?/sec
logical_union_8_branches                              1.01    790.1±4.62µs        ? ?/sec         1.00    784.8±1.93µs        ? ?/sec
logical_wide_aggregate_1000_exprs                     1.00     43.5±0.08ms        ? ?/sec       
logical_wide_aggregate_100_exprs                      1.00   1637.2±5.12µs        ? ?/sec         2.40      3.9±0.02ms        ? ?/sec
logical_wide_case_50_exprs                            1.00   1815.7±3.32µs        ? ?/sec         1.00   1820.8±3.58µs        ? ?/sec
logical_wide_filter_200_predicates                    1.00   1317.4±6.94µs        ? ?/sec         1.01   1334.5±6.58µs        ? ?/sec
logical_wide_filter_50_predicates                     1.00    362.2±1.21µs        ? ?/sec         1.00    362.1±1.35µs        ? ?/sec
optimizer_correlated_exists                           1.00    225.6±0.57µs        ? ?/sec         1.00    225.6±0.38µs        ? ?/sec
optimizer_join_4_with_agg_filter                      1.01    408.3±1.73µs        ? ?/sec         1.00    402.9±1.31µs        ? ?/sec
optimizer_join_chain_4                                1.01    158.9±0.38µs        ? ?/sec         1.00    157.4±0.19µs        ? ?/sec
optimizer_join_chain_8                                1.01    545.5±1.06µs        ? ?/sec         1.00    541.7±1.13µs        ? ?/sec
optimizer_select_all_from_1000                        1.01      6.8±0.04ms        ? ?/sec         1.00      6.7±0.01ms        ? ?/sec
optimizer_select_one_from_700                         1.00    237.6±1.28µs        ? ?/sec         1.00    238.8±0.49µs        ? ?/sec
optimizer_tpcds_all                                   1.01    289.6±0.30ms        ? ?/sec         1.00    288.0±0.34ms        ? ?/sec
optimizer_tpch_all                                    1.01     15.7±0.02ms        ? ?/sec         1.00     15.6±0.03ms        ? ?/sec
optimizer_wide_aggregate_100                          1.01   1793.6±4.39µs        ? ?/sec         1.00   1777.7±4.36µs        ? ?/sec
optimizer_wide_filter_200                             1.01      3.9±0.01ms        ? ?/sec         1.00      3.9±0.01ms        ? ?/sec
physical_intersection                                 1.00    571.0±3.50µs        ? ?/sec         1.00    570.2±7.85µs        ? ?/sec
physical_join_consider_sort                           1.00   1028.4±2.15µs        ? ?/sec         1.01   1033.9±2.32µs        ? ?/sec
physical_join_distinct                                1.00    228.8±1.27µs        ? ?/sec         1.00    228.4±1.31µs        ? ?/sec
physical_many_self_joins                              1.00      7.8±0.01ms        ? ?/sec         1.00      7.8±0.02ms        ? ?/sec
physical_plan_clickbench_all                          1.00    139.1±0.28ms        ? ?/sec         1.02    141.7±0.30ms        ? ?/sec
physical_plan_clickbench_q1                           1.00   1357.3±8.14µs        ? ?/sec         1.00   1357.9±7.30µs        ? ?/sec
physical_plan_clickbench_q10                          1.00      2.0±0.01ms        ? ?/sec         1.02      2.0±0.01ms        ? ?/sec
physical_plan_clickbench_q11                          1.00      2.2±0.01ms        ? ?/sec         1.01      2.2±0.00ms        ? ?/sec
physical_plan_clickbench_q12                          1.00      2.3±0.01ms        ? ?/sec         1.01      2.3±0.00ms        ? ?/sec
physical_plan_clickbench_q13                          1.00      2.0±0.01ms        ? ?/sec         1.02      2.0±0.00ms        ? ?/sec
physical_plan_clickbench_q14                          1.00      2.2±0.01ms        ? ?/sec         1.01      2.2±0.01ms        ? ?/sec
physical_plan_clickbench_q15                          1.00      2.1±0.00ms        ? ?/sec         1.01      2.1±0.00ms        ? ?/sec
physical_plan_clickbench_q16                          1.00   1770.6±4.24µs        ? ?/sec         1.03   1816.3±4.19µs        ? ?/sec
physical_plan_clickbench_q17                          1.00   1825.4±4.18µs        ? ?/sec         1.01   1841.5±4.89µs        ? ?/sec
physical_plan_clickbench_q18                          1.00   1628.4±5.20µs        ? ?/sec         1.01   1643.2±5.12µs        ? ?/sec
physical_plan_clickbench_q19                          1.00      2.0±0.01ms        ? ?/sec         1.01      2.1±0.00ms        ? ?/sec
physical_plan_clickbench_q2                           1.00   1732.0±5.66µs        ? ?/sec         1.00   1735.6±4.86µs        ? ?/sec
physical_plan_clickbench_q20                          1.00   1535.5±6.47µs        ? ?/sec         1.00   1529.1±5.79µs        ? ?/sec
physical_plan_clickbench_q21                          1.01   1744.8±5.77µs        ? ?/sec         1.00   1734.5±6.30µs        ? ?/sec
physical_plan_clickbench_q22                          1.01      2.2±0.01ms        ? ?/sec         1.00      2.1±0.01ms        ? ?/sec
physical_plan_clickbench_q23                          1.02      2.4±0.02ms        ? ?/sec         1.00      2.3±0.01ms        ? ?/sec
physical_plan_clickbench_q24                          1.01      5.5±0.03ms        ? ?/sec         1.00      5.5±0.01ms        ? ?/sec
physical_plan_clickbench_q25                          1.01   1894.2±6.90µs        ? ?/sec         1.00   1866.9±4.24µs        ? ?/sec
physical_plan_clickbench_q26                          1.01   1746.5±5.04µs        ? ?/sec         1.00   1724.7±5.82µs        ? ?/sec
physical_plan_clickbench_q27                          1.00   1893.2±6.11µs        ? ?/sec         1.01   1903.2±5.34µs        ? ?/sec
physical_plan_clickbench_q28                          1.00      2.3±0.01ms        ? ?/sec         1.01      2.3±0.00ms        ? ?/sec
physical_plan_clickbench_q29                          1.00      2.4±0.01ms        ? ?/sec         1.01      2.4±0.01ms        ? ?/sec
physical_plan_clickbench_q3                           1.00   1622.8±6.12µs        ? ?/sec         1.00   1628.3±4.87µs        ? ?/sec
physical_plan_clickbench_q30                          1.00     12.7±0.05ms        ? ?/sec         1.19     15.1±0.04ms        ? ?/sec
physical_plan_clickbench_q31                          1.00      2.4±0.01ms        ? ?/sec         1.01      2.4±0.00ms        ? ?/sec
physical_plan_clickbench_q32                          1.00      2.4±0.01ms        ? ?/sec         1.01      2.4±0.01ms        ? ?/sec
physical_plan_clickbench_q33                          1.00      2.0±0.01ms        ? ?/sec         1.01      2.0±0.01ms        ? ?/sec
physical_plan_clickbench_q34                          1.00   1784.0±5.64µs        ? ?/sec         1.01   1796.1±4.42µs        ? ?/sec
physical_plan_clickbench_q35                          1.00   1823.1±7.96µs        ? ?/sec         1.01   1836.8±6.29µs        ? ?/sec
physical_plan_clickbench_q36                          1.00      2.1±0.01ms        ? ?/sec         1.00      2.1±0.00ms        ? ?/sec
physical_plan_clickbench_q37                          1.00      2.5±0.01ms        ? ?/sec         1.00      2.5±0.00ms        ? ?/sec
physical_plan_clickbench_q38                          1.00      2.5±0.01ms        ? ?/sec         1.00      2.5±0.01ms        ? ?/sec
physical_plan_clickbench_q39                          1.02      2.6±0.01ms        ? ?/sec         1.00      2.5±0.01ms        ? ?/sec
physical_plan_clickbench_q4                           1.00   1467.0±5.28µs        ? ?/sec         1.00   1468.1±4.86µs        ? ?/sec
physical_plan_clickbench_q40                          1.01      3.2±0.01ms        ? ?/sec         1.00      3.2±0.01ms        ? ?/sec
physical_plan_clickbench_q41                          1.02      2.8±0.01ms        ? ?/sec         1.00      2.7±0.01ms        ? ?/sec
physical_plan_clickbench_q42                          1.02      2.9±0.01ms        ? ?/sec         1.00      2.9±0.01ms        ? ?/sec
physical_plan_clickbench_q43                          1.01      3.1±0.01ms        ? ?/sec         1.00      3.0±0.01ms        ? ?/sec
physical_plan_clickbench_q44                          1.00   1556.7±5.73µs        ? ?/sec         1.00  1550.5±12.67µs        ? ?/sec
physical_plan_clickbench_q45                          1.01   1561.7±4.94µs        ? ?/sec         1.00  1539.8±11.90µs        ? ?/sec
physical_plan_clickbench_q46                          1.03   1898.5±5.05µs        ? ?/sec         1.00   1848.2±5.47µs        ? ?/sec
physical_plan_clickbench_q47                          1.03      2.5±0.01ms        ? ?/sec         1.00      2.5±0.01ms        ? ?/sec
physical_plan_clickbench_q48                          1.02      2.7±0.01ms        ? ?/sec         1.00      2.6±0.01ms        ? ?/sec
physical_plan_clickbench_q49                          1.02      2.7±0.01ms        ? ?/sec         1.00      2.7±0.01ms        ? ?/sec
physical_plan_clickbench_q5                           1.00   1568.7±5.58µs        ? ?/sec         1.01   1590.2±4.62µs        ? ?/sec
physical_plan_clickbench_q50                          1.02      2.7±0.01ms        ? ?/sec         1.00      2.6±0.01ms        ? ?/sec
physical_plan_clickbench_q51                          1.01   1982.6±6.88µs        ? ?/sec         1.00   1957.2±5.11µs        ? ?/sec
physical_plan_clickbench_q52                          1.03      2.6±0.01ms        ? ?/sec         1.00      2.5±0.01ms        ? ?/sec
physical_plan_clickbench_q53                          1.00   1745.7±6.28µs        ? ?/sec         1.00   1740.1±5.92µs        ? ?/sec
physical_plan_clickbench_q54                          1.00  1746.1±22.76µs        ? ?/sec         1.00   1740.3±4.53µs        ? ?/sec
physical_plan_clickbench_q55                          1.01  1681.0±10.15µs        ? ?/sec         1.00   1672.1±6.51µs        ? ?/sec
physical_plan_clickbench_q56                          1.00  1684.0±13.18µs        ? ?/sec         1.00   1691.2±4.18µs        ? ?/sec
physical_plan_clickbench_q57                          1.00   1796.6±4.64µs        ? ?/sec         1.00   1793.0±5.00µs        ? ?/sec
physical_plan_clickbench_q58                          1.00      2.4±0.01ms        ? ?/sec         1.00      2.4±0.01ms        ? ?/sec
physical_plan_clickbench_q59                          1.00   1695.0±4.25µs        ? ?/sec         1.00   1697.1±6.12µs        ? ?/sec
physical_plan_clickbench_q6                           1.00   1575.4±6.00µs        ? ?/sec         1.01   1595.3±4.49µs        ? ?/sec
physical_plan_clickbench_q60                          1.00   1697.5±5.73µs        ? ?/sec         1.00   1705.3±4.82µs        ? ?/sec
physical_plan_clickbench_q7                           1.00   1400.0±3.82µs        ? ?/sec         1.01   1418.8±4.43µs        ? ?/sec
physical_plan_clickbench_q8                           1.00   1901.7±5.38µs        ? ?/sec         1.02   1931.0±5.65µs        ? ?/sec
physical_plan_clickbench_q9                           1.00   1907.9±5.85µs        ? ?/sec         1.01   1932.2±6.23µs        ? ?/sec
physical_plan_struct_join_agg_sort                    1.01   1238.8±1.98µs        ? ?/sec         1.00   1229.8±2.31µs        ? ?/sec
physical_plan_tpcds_all                               1.00    662.4±3.03ms        ? ?/sec         1.00    662.3±0.50ms        ? ?/sec
physical_plan_tpch_all                                1.00     42.5±0.06ms        ? ?/sec         1.00     42.4±0.07ms        ? ?/sec
physical_plan_tpch_q1                                 1.00   1378.4±2.31µs        ? ?/sec         1.02   1403.8±2.86µs        ? ?/sec
physical_plan_tpch_q10                                1.00      2.6±0.00ms        ? ?/sec         1.00      2.6±0.00ms        ? ?/sec
physical_plan_tpch_q11                                1.00      2.2±0.00ms        ? ?/sec         1.01      2.2±0.02ms        ? ?/sec
physical_plan_tpch_q12                                1.00   1216.8±3.73µs        ? ?/sec         1.02  1243.9±10.18µs        ? ?/sec
physical_plan_tpch_q13                                1.00   1005.6±2.44µs        ? ?/sec         1.02   1029.0±8.00µs        ? ?/sec
physical_plan_tpch_q14                                1.01   1314.3±4.92µs        ? ?/sec         1.00   1304.6±2.53µs        ? ?/sec
physical_plan_tpch_q16                                1.00  1593.4±11.57µs        ? ?/sec         1.00   1595.9±3.16µs        ? ?/sec
physical_plan_tpch_q17                                1.00  1580.7±10.08µs        ? ?/sec         1.00   1577.5±2.79µs        ? ?/sec
physical_plan_tpch_q18                                1.00   1878.2±9.90µs        ? ?/sec         1.02  1911.8±14.07µs        ? ?/sec
physical_plan_tpch_q19                                1.00  1805.1±10.57µs        ? ?/sec         1.00   1804.4±3.27µs        ? ?/sec
physical_plan_tpch_q2                                 1.00      3.5±0.00ms        ? ?/sec         1.00      3.5±0.00ms        ? ?/sec
physical_plan_tpch_q20                                1.00      2.1±0.00ms        ? ?/sec         1.01      2.1±0.01ms        ? ?/sec
physical_plan_tpch_q21                                1.00      2.7±0.00ms        ? ?/sec         1.00      2.7±0.01ms        ? ?/sec
physical_plan_tpch_q22                                1.00   1482.8±4.95µs        ? ?/sec         1.01   1497.3±6.16µs        ? ?/sec
physical_plan_tpch_q3                                 1.00   1741.5±3.50µs        ? ?/sec         1.00   1741.5±3.07µs        ? ?/sec
physical_plan_tpch_q4                                 1.01   1116.0±2.83µs        ? ?/sec         1.00   1102.4±1.69µs        ? ?/sec
physical_plan_tpch_q5                                 1.00      2.5±0.00ms        ? ?/sec         1.00      2.5±0.00ms        ? ?/sec
physical_plan_tpch_q6                                 1.00    571.3±0.98µs        ? ?/sec         1.00    571.1±1.23µs        ? ?/sec
physical_plan_tpch_q7                                 1.00      2.6±0.00ms        ? ?/sec         1.00      2.6±0.00ms        ? ?/sec
physical_plan_tpch_q8                                 1.00      3.6±0.01ms        ? ?/sec         1.00      3.6±0.00ms        ? ?/sec
physical_plan_tpch_q9                                 1.00      2.6±0.00ms        ? ?/sec         1.00      2.6±0.00ms        ? ?/sec
physical_select_aggregates_from_200                   1.00      7.7±0.02ms        ? ?/sec         1.61     12.4±0.02ms        ? ?/sec
physical_select_all_from_1000                         1.00     20.1±0.04ms        ? ?/sec         1.00     20.2±0.06ms        ? ?/sec
physical_select_one_from_700                          1.00    739.4±2.54µs        ? ?/sec         1.01    747.2±1.95µs        ? ?/sec
physical_sorted_union_order_by_10_int64               1.00      3.8±0.00ms        ? ?/sec         1.00      3.8±0.00ms        ? ?/sec
physical_sorted_union_order_by_10_uint64              1.01      7.5±0.04ms        ? ?/sec         1.00      7.5±0.01ms        ? ?/sec
physical_sorted_union_order_by_50_int64               1.01     84.4±0.41ms        ? ?/sec         1.00     84.0±0.18ms        ? ?/sec
physical_sorted_union_order_by_50_uint64              1.00    299.2±0.62ms        ? ?/sec         1.00    299.0±0.89ms        ? ?/sec
physical_theta_join_consider_sort                     1.00   1051.8±2.02µs        ? ?/sec         1.00   1052.7±3.76µs        ? ?/sec
physical_unnest_to_join                               1.01    617.5±2.59µs        ? ?/sec         1.00    613.8±3.32µs        ? ?/sec
physical_window_function_partition_by_12_on_values    1.00    654.3±1.61µs        ? ?/sec         1.00    652.2±1.68µs        ? ?/sec
physical_window_function_partition_by_30_on_values    1.00   1297.6±2.50µs        ? ?/sec         1.00   1300.6±3.02µs        ? ?/sec
physical_window_function_partition_by_4_on_values     1.00    394.2±1.34µs        ? ?/sec         1.00    395.9±1.16µs        ? ?/sec
physical_window_function_partition_by_7_on_values     1.00    487.7±1.11µs        ? ?/sec         1.00    489.5±1.75µs        ? ?/sec
physical_window_function_partition_by_8_on_values     1.00    524.4±1.60µs        ? ?/sec         1.00    525.5±1.71µs        ? ?/sec
with_param_values_many_columns                        1.00    437.7±2.55µs        ? ?/sec         1.00    437.4±2.06µs        ? ?/sec

Resource Usage

sql_planner — base (merge-base)

Metric Value
Wall time 1790.4s
Peak memory 142.7 MiB
Avg memory 104.7 MiB
CPU user 1983.3s
CPU sys 1.5s
Peak spill 0 B

sql_planner — branch

Metric Value
Wall time 1790.4s
Peak memory 137.5 MiB
Avg memory 102.0 MiB
CPU user 1999.0s
CPU sys 1.6s
Peak spill 0 B

File an issue against this benchmark runner

@alamb

alamb commented Sep 25, 2026

Copy link
Copy Markdown
Contributor
group                                                 1fanwang-datafusion-issue-prioritization    HEAD
-----                                                 ----------------------------------------    ----
logical_wide_aggregate_100_exprs                      1.00  1640.9±13.29µs        ? ?/sec         2.39      3.9±0.01ms        ? ?/sec
...next run...
logical_wide_aggregate_100_exprs                      1.00   1637.2±5.12µs        ? ?/sec         2.40      3.9±0.02ms        ? ?/sec

Looks good to me

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @1fanwang

@kumarUjjawal

Copy link
Copy Markdown
Contributor

Pushed main to unblock the CI

@alamb
alamb added this pull request to the merge queue Oct 1, 2026
Merged via the queue into apache:main with commit c222b69 Oct 1, 2026
42 checks passed
Omega359 pushed a commit to Omega359/arrow-datafusion that referenced this pull request Oct 11, 2026
…he#25739)

## Which issue does this PR close?

- Part of apache#25248.

## Rationale for this change

Planning a `SELECT` with many aggregate expressions takes time that
grows with the square of the number of expressions. The report measured
2.7 s of SQL planning for 2,500 items, and a profile shows almost all of
it goes into building the projection above the aggregate.

For each select item, the planner replaces sub-expressions that the
aggregate already computes with references to its output columns. It
rebuilt the lookup table of those expressions for every item, so N items
built N tables of N entries. Hashing an aggregate expression also hashes
its function signature, which makes each rebuild slow.

## What changes are included in this PR?

- The projection builder now builds that table once and reuses it for
every item, through a crate-private `Columnizer`. `columnize_expr` keeps
its signature and uses the same helper. This follows apache#25010, which
reuses the column normalization context in the same function.
- The `sql_planner` benchmark gains a case with 1,000 aggregates.

Very wide selects still do some quadratic work. Two SQL planner helpers,
`rebase_expr` and `find_aggregate_exprs`, compare each expression
against a list, and schema field lookups scan every field. I'd rather
handle those in separate PRs, so this one only references the issue.

## What is the testing strategy for this PR?

The rewrite gives the same result as before, so the existing expression,
SQL planner and optimizer tests and the sqllogictest suite cover it, and
they pass locally.

`sql_planner` benchmark against `main` on an 18-core M-series Mac,
`release-nonlto`:

| Benchmark | main | this PR | change |
| --- | --- | --- | --- |
| `logical_wide_aggregate_1000_exprs` (new) | 182.3 ms | 31.1 ms | -83%
|
| `logical_wide_aggregate_100_exprs` | 2.43 ms | 0.89 ms | -63% |
| `physical_select_aggregates_from_200` | 6.98 ms | 4.69 ms | -33% |

The query shape from the issue, `CAST(sum(id + i) AS VARCHAR)` repeated
N times, planned with `EXPLAIN` in `datafusion-cli` (unoptimized `ci`
build, so absolute times are high):

| N | main | this PR |
| --- | --- | --- |
| 500 | 0.72 s | 0.66 s |
| 1000 | 1.56 s | 0.87 s |
| 2000 | 5.05 s | 1.83 s |
| 4000 | 18.83 s | 4.57 s |

<details>
<summary>Commands and raw output</summary>

Benchmarks. The new case is copied onto `main` so both runs measure the
same queries. The `sql_planner` bench checks that
`benchmarks/data/hits_partitioned` exists at startup; I used a one-row
stand-in, since none of these three cases read it.

```
PR=eb8f5ce9d4d0b50cffb97648188c84a4034ec92c
git fetch origin main "$PR"
git switch --detach origin/main
git checkout "$PR" -- datafusion/core/benches/sql_planner.rs
cargo bench -p datafusion --bench sql_planner --profile release-nonlto -- \
  'logical_wide_aggregate|physical_select_aggregates_from_200' --save-baseline main
git checkout -f "$PR"
cargo bench -p datafusion --bench sql_planner --profile release-nonlto -- \
  'logical_wide_aggregate|physical_select_aggregates_from_200' --baseline main
```

`main`:

```
physical_select_aggregates_from_200
                        time:   [6.8908 ms 6.9799 ms 7.0789 ms]
logical_wide_aggregate_100_exprs
                        time:   [2.3629 ms 2.4285 ms 2.4977 ms]
logical_wide_aggregate_1000_exprs
                        time:   [180.60 ms 182.29 ms 184.28 ms]
```

This PR:

```
physical_select_aggregates_from_200
                        time:   [4.6522 ms 4.6890 ms 4.7269 ms]
                        change: [−33.854% −32.821% −31.767%] (p = 0.00 < 0.05)
                        Performance has improved.
logical_wide_aggregate_100_exprs
                        time:   [881.22 µs 888.79 µs 897.96 µs]
                        change: [−63.824% −62.709% −61.533%] (p = 0.00 < 0.05)
                        Performance has improved.
logical_wide_aggregate_1000_exprs
                        time:   [30.705 ms 31.131 ms 31.628 ms]
                        change: [−83.222% −82.922% −82.577%] (p = 0.00 < 0.05)
                        Performance has improved.
```

`datafusion-cli` timing, with the CLI built by `cargo build --profile ci
-p datafusion-cli` on each side:

```bash
#!/usr/bin/env bash
# Usage: wide-timing.sh <datafusion-cli>
set -euo pipefail
python3 - <<'EOF'
for n in (500, 1000, 2000, 4000):
    items = ', '.join(f'CAST(sum(id + {i}) AS VARCHAR) AS c{i}' for i in range(n))
    with open(f'wide_{n}.sql', 'w') as f:
        f.write('CREATE TABLE t AS SELECT value AS id FROM range(1000);\n')
        f.write(f'EXPLAIN SELECT {items} FROM t;\n')
EOF
for n in 500 1000 2000 4000; do
  /usr/bin/time -p "$1" -q -f "wide_$n.sql" 2>&1 >/dev/null | awk -v n="$n" '/^real/ {print "N=" n, $2 "s"}'
done
```

```
== main
N=500 0.72s
N=1000 1.56s
N=2000 5.05s
N=4000 18.83s
== this PR
N=500 0.66s
N=1000 0.87s
N=2000 1.83s
N=4000 4.57s
```

</details>

## Are there any user-facing changes?

No. Planning is faster, and `columnize_expr` keeps its signature and
behavior.

Signed-off-by: Stefan Wang <[email protected]>
Co-authored-by: Kumar Ujjawal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate logical-expr Logical plan and expressions v56.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants