Skip to content

perf(logical-plan): box CreateExternalTable / CreateFunction in DdlStatement (-45% LogicalPlan size)#22733

Merged
zhuqi-lucas merged 4 commits into
apache:mainfrom
zhuqi-lucas:perf/box-large-ddl-variants
Jun 5, 2026
Merged

perf(logical-plan): box CreateExternalTable / CreateFunction in DdlStatement (-45% LogicalPlan size)#22733
zhuqi-lucas merged 4 commits into
apache:mainfrom
zhuqi-lucas:perf/box-large-ddl-variants

Conversation

@zhuqi-lucas
Copy link
Copy Markdown
Contributor

@zhuqi-lucas zhuqi-lucas commented Jun 3, 2026

Which issue does this PR close?

Closes #22732.

Rationale for this change

LogicalPlan is 320 bytes today, sized by the Ddl(DdlStatement) variant — which is itself 320 bytes because it carries CreateExternalTable (312 bytes) and CreateFunction (288 bytes). Every non-DDL variant is at most 176 bytes (Join). Every SELECT query pays the full 320-byte payload on every mem::take / mem::swap / Arc<LogicalPlan> write during planning, even though it never instantiates a DDL node.

Profiling sql_planner (samply, macOS aarch64) showed ~13% of CPU in libsystem_platform.dylib (memcpy / memmove). Shrinking the most frequently-moved type directly attacks that pool.

What changes are included in this PR?

Box the two oversized DDL variants:

pub enum DdlStatement {
    CreateExternalTable(Box<CreateExternalTable>),
    // …
    CreateFunction(Box<CreateFunction>),
    // …
}

After this change:

  • DdlStatement drops from 320 → ~152 bytes (max variant is now CreateIndex at 144).
  • LogicalPlan drops from 320 → 176 bytes (–45%) — the enum discriminant fits inside Join's alignment padding, so the enum is exactly the same width as Join.

DDL plan construction takes one extra Box::new(...) allocation per DDL statement — negligible because DDL plans are one-shot and not on the per-query hot path.

The diff is mechanical: construction sites add Box::new(...), the few field-destructuring patterns are converted to a let CreateExternalTable { … } = ce.as_ref(); shape, and the FFI/proto crates need one *cmd / Box::new(cmd) adjustment at the type boundaries.

A new test_size_of_logical_plan unit test pins size_of::<LogicalPlan>() == 176 and asserts DdlStatement stays smaller than Join, so future variant growth that would re-balloon the enum trips the test rather than silently regressing the planning hot path. (Same shape as the existing test_size_of_expr in expr.rs.)

Are these changes tested?

  • 711 optimizer + 217 expr + 86 sql + 7 proto unit tests pass.
  • SLT create_external_table / create_function / ddl pass.
  • cargo clippy --workspace --all-targets -- -D warnings clean.

Are there any user-facing changes?

Yes (semantic API only). Code that pattern-matches DdlStatement::CreateExternalTable(CreateExternalTable { … }) must change to bind the box and deref. Code that constructs these variants must wrap with Box::new(...). No behavioral change.

…atement

These two variants dominate the LogicalPlan enum size: CreateExternalTable
is 312 bytes and CreateFunction is 288 bytes, while every non-DDL variant
is at most 176 bytes (Join). The DdlStatement variant therefore forces
LogicalPlan to 320 bytes, even though no SELECT-path workload ever
materializes a CreateExternalTable / CreateFunction.

Boxing both shrinks LogicalPlan from 320 bytes to 176 bytes (-45%) by
making Join the new size-determining variant (the enum discriminant fits
inside Join's alignment padding). Every mem::take / mem::swap /
Arc<LogicalPlan> store on the planning hot path now moves a smaller
payload.

Local sql_planner --quick:
  optimizer_tpch_all:   8.61ms -> 8.18ms  (-5.0%)
  optimizer_tpcds_all:  168.0ms -> 163.5ms (-2.7%)

Profiling shows ~13% of sql_planner CPU in libsystem_platform.dylib
(memcpy / memmove) -- this change directly reduces that pool.

A test_size_of_logical_plan unit test pins the new size and asserts
DdlStatement stays smaller than Join, so future variant growth that
would re-balloon the enum trips the test rather than silently regressing
the planning hot path.

711 optimizer + 218 expr + 86 sql + 7 proto unit tests pass. SLT
create_function / create_external_table / ddl pass. clippy clean.
@github-actions github-actions Bot added sql SQL Planner logical-expr Logical plan and expressions core Core DataFusion crate proto Related to proto crate ffi Changes to the ffi crate labels Jun 3, 2026
@zhuqi-lucas
Copy link
Copy Markdown
Contributor Author

run benchmark sql_planner

@adriangbot
Copy link
Copy Markdown

🤖 Criterion benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4614156589-419-k7zkb 6.12.68+ #1 SMP Wed Apr 1 02:23:28 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 perf/box-large-ddl-variants (8b02e90) to 533ef35 (merge-base) diff
BENCH_NAME=sql_planner
BENCH_COMMAND=cargo bench --features=parquet --bench sql_planner
BENCH_FILTER=
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Criterion benchmark completed (GKE) | trigger

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

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                                                 main                                   perf_box-large-ddl-variants
-----                                                 ----                                   ---------------------------
logical_aggregate_with_join                           1.00    449.5±1.17µs        ? ?/sec    1.00    451.3±1.25µs        ? ?/sec
logical_correlated_subquery_exists                    1.00    280.3±0.96µs        ? ?/sec    1.01    282.2±0.77µs        ? ?/sec
logical_correlated_subquery_in                        1.00    283.7±0.72µs        ? ?/sec    1.00    283.9±0.71µs        ? ?/sec
logical_distinct_many_columns                         1.00    573.2±1.24µs        ? ?/sec    1.00    573.8±1.52µs        ? ?/sec
logical_join_4_with_agg_and_filter                    1.00    250.3±1.39µs        ? ?/sec    1.00    249.8±1.00µs        ? ?/sec
logical_join_8_with_agg_sort_limit                    1.00    421.6±1.39µs        ? ?/sec    1.01    425.8±2.82µs        ? ?/sec
logical_join_chain_16                                 1.00    668.5±3.23µs        ? ?/sec    1.01    675.9±2.57µs        ? ?/sec
logical_join_chain_4                                  1.00    122.1±0.48µs        ? ?/sec    1.00    121.7±0.51µs        ? ?/sec
logical_join_chain_8                                  1.01    249.9±1.32µs        ? ?/sec    1.00    248.6±0.96µs        ? ?/sec
logical_multiple_subqueries                           1.00    514.9±2.10µs        ? ?/sec    1.00    512.6±2.35µs        ? ?/sec
logical_nested_cte_4_levels                           1.02    267.8±1.61µs        ? ?/sec    1.00    262.2±1.09µs        ? ?/sec
logical_plan_struct_join_agg_sort                     1.00    178.0±0.68µs        ? ?/sec    1.01    179.8±0.71µs        ? ?/sec
logical_plan_tpcds_all                                1.00     92.5±0.14ms        ? ?/sec    1.01     93.1±0.21ms        ? ?/sec
logical_plan_tpch_all                                 1.00      6.4±0.01ms        ? ?/sec    1.01      6.5±0.02ms        ? ?/sec
logical_scalar_subquery                               1.01    306.5±0.96µs        ? ?/sec    1.00    302.3±0.81µs        ? ?/sec
logical_select_all_from_1000                          1.00    106.9±1.80ms        ? ?/sec    1.00    107.1±2.07ms        ? ?/sec
logical_select_one_from_700                           1.00    323.0±1.65µs        ? ?/sec    1.01    324.7±1.59µs        ? ?/sec
logical_trivial_join_high_numbered_columns            1.00    282.7±0.98µs        ? ?/sec    1.00    283.6±1.02µs        ? ?/sec
logical_trivial_join_low_numbered_columns             1.00    270.3±1.81µs        ? ?/sec    1.00    271.6±1.07µs        ? ?/sec
logical_union_4_branches                              1.00    421.3±1.60µs        ? ?/sec    1.01    423.6±0.94µs        ? ?/sec
logical_union_8_branches                              1.00    805.7±3.57µs        ? ?/sec    1.00    807.5±1.09µs        ? ?/sec
logical_wide_aggregate_100_exprs                      1.00      4.3±0.01ms        ? ?/sec    1.00      4.3±0.01ms        ? ?/sec
logical_wide_case_50_exprs                            1.00      2.4±0.01ms        ? ?/sec    1.00      2.4±0.00ms        ? ?/sec
logical_wide_filter_200_predicates                    1.00   1309.4±7.59µs        ? ?/sec    1.00   1310.6±6.20µs        ? ?/sec
logical_wide_filter_50_predicates                     1.00    390.8±2.20µs        ? ?/sec    1.00    392.6±4.12µs        ? ?/sec
optimizer_correlated_exists                           1.02    250.7±0.91µs        ? ?/sec    1.00    245.2±0.72µs        ? ?/sec
optimizer_join_4_with_agg_filter                      1.03    435.2±2.02µs        ? ?/sec    1.00    421.1±2.70µs        ? ?/sec
optimizer_join_chain_4                                1.02    176.5±0.43µs        ? ?/sec    1.00    172.4±0.41µs        ? ?/sec
optimizer_join_chain_8                                1.01    555.0±4.85µs        ? ?/sec    1.00    548.1±1.79µs        ? ?/sec
optimizer_select_all_from_1000                        1.04      4.8±0.02ms        ? ?/sec    1.00      4.6±0.01ms        ? ?/sec
optimizer_select_one_from_700                         1.00    249.9±0.40µs        ? ?/sec    1.01    253.2±0.56µs        ? ?/sec
optimizer_tpcds_all                                   1.03    294.0±2.18ms        ? ?/sec    1.00    284.3±0.32ms        ? ?/sec
optimizer_tpch_all                                    1.03     15.5±0.03ms        ? ?/sec    1.00     15.0±0.12ms        ? ?/sec
optimizer_wide_aggregate_100                          1.00      2.1±0.01ms        ? ?/sec    1.00      2.1±0.00ms        ? ?/sec
optimizer_wide_filter_200                             1.00      3.5±0.00ms        ? ?/sec    1.00      3.5±0.01ms        ? ?/sec
physical_intersection                                 1.01    584.1±1.64µs        ? ?/sec    1.00    580.1±1.87µs        ? ?/sec
physical_join_consider_sort                           1.00   1015.7±2.29µs        ? ?/sec    1.00   1012.6±2.48µs        ? ?/sec
physical_join_distinct                                1.00    262.9±1.08µs        ? ?/sec    1.01    265.6±1.06µs        ? ?/sec
physical_many_self_joins                              1.00      7.5±0.02ms        ? ?/sec    1.02      7.6±0.02ms        ? ?/sec
physical_plan_clickbench_all                          1.01    124.1±0.87ms        ? ?/sec    1.00    122.9±1.07ms        ? ?/sec
physical_plan_clickbench_q1                           1.00   1303.5±5.89µs        ? ?/sec    1.00   1299.5±7.60µs        ? ?/sec
physical_plan_clickbench_q10                          1.00   1935.6±5.59µs        ? ?/sec    1.00   1934.4±6.65µs        ? ?/sec
physical_plan_clickbench_q11                          1.00      2.1±0.01ms        ? ?/sec    1.00      2.1±0.01ms        ? ?/sec
physical_plan_clickbench_q12                          1.03      2.2±0.01ms        ? ?/sec    1.00      2.1±0.01ms        ? ?/sec
physical_plan_clickbench_q13                          1.01  1980.2±13.49µs        ? ?/sec    1.00   1961.5±6.89µs        ? ?/sec
physical_plan_clickbench_q14                          1.01      2.1±0.01ms        ? ?/sec    1.00      2.1±0.01ms        ? ?/sec
physical_plan_clickbench_q15                          1.01      2.0±0.01ms        ? ?/sec    1.00      2.0±0.01ms        ? ?/sec
physical_plan_clickbench_q16                          1.00   1692.2±5.94µs        ? ?/sec    1.00   1693.4±5.65µs        ? ?/sec
physical_plan_clickbench_q17                          1.00   1741.1±6.15µs        ? ?/sec    1.00   1742.0±6.42µs        ? ?/sec
physical_plan_clickbench_q18                          1.00   1577.6±5.61µs        ? ?/sec    1.02   1604.8±5.97µs        ? ?/sec
physical_plan_clickbench_q19                          1.00   1925.4±6.16µs        ? ?/sec    1.01   1950.0±6.34µs        ? ?/sec
physical_plan_clickbench_q2                           1.00   1691.0±5.83µs        ? ?/sec    1.00   1684.5±7.85µs        ? ?/sec
physical_plan_clickbench_q20                          1.00   1472.9±5.66µs        ? ?/sec    1.02   1496.5±5.40µs        ? ?/sec
physical_plan_clickbench_q21                          1.00   1683.9±6.37µs        ? ?/sec    1.01   1704.2±6.61µs        ? ?/sec
physical_plan_clickbench_q22                          1.00      2.0±0.01ms        ? ?/sec    1.01      2.1±0.01ms        ? ?/sec
physical_plan_clickbench_q23                          1.00      2.2±0.01ms        ? ?/sec    1.02      2.3±0.01ms        ? ?/sec
physical_plan_clickbench_q24                          1.00      6.6±0.02ms        ? ?/sec    1.00      6.6±0.02ms        ? ?/sec
physical_plan_clickbench_q25                          1.01  1844.6±15.26µs        ? ?/sec    1.00   1832.4±6.15µs        ? ?/sec
physical_plan_clickbench_q26                          1.00   1658.8±7.27µs        ? ?/sec    1.01   1669.2±6.79µs        ? ?/sec
physical_plan_clickbench_q27                          1.00   1851.5±5.12µs        ? ?/sec    1.00   1846.4±5.22µs        ? ?/sec
physical_plan_clickbench_q28                          1.00      2.3±0.01ms        ? ?/sec    1.00      2.3±0.01ms        ? ?/sec
physical_plan_clickbench_q29                          1.01      2.5±0.01ms        ? ?/sec    1.00      2.4±0.01ms        ? ?/sec
physical_plan_clickbench_q3                           1.00   1564.9±6.57µs        ? ?/sec    1.00   1563.6±6.85µs        ? ?/sec
physical_plan_clickbench_q30                          1.00     15.0±0.05ms        ? ?/sec    1.00     15.0±0.06ms        ? ?/sec
physical_plan_clickbench_q31                          1.01      2.3±0.01ms        ? ?/sec    1.00      2.3±0.01ms        ? ?/sec
physical_plan_clickbench_q32                          1.01      2.3±0.01ms        ? ?/sec    1.00      2.3±0.01ms        ? ?/sec
physical_plan_clickbench_q33                          1.01   1906.5±6.26µs        ? ?/sec    1.00   1895.6±6.73µs        ? ?/sec
physical_plan_clickbench_q34                          1.04  1735.0±10.49µs        ? ?/sec    1.00   1670.7±5.58µs        ? ?/sec
physical_plan_clickbench_q35                          1.03  1801.0±14.06µs        ? ?/sec    1.00   1743.4±7.59µs        ? ?/sec
physical_plan_clickbench_q36                          1.03      2.1±0.01ms        ? ?/sec    1.00      2.0±0.01ms        ? ?/sec
physical_plan_clickbench_q37                          1.03      2.5±0.02ms        ? ?/sec    1.00      2.4±0.01ms        ? ?/sec
physical_plan_clickbench_q38                          1.02      2.5±0.01ms        ? ?/sec    1.00      2.4±0.01ms        ? ?/sec
physical_plan_clickbench_q39                          1.02      2.5±0.01ms        ? ?/sec    1.00      2.5±0.01ms        ? ?/sec
physical_plan_clickbench_q4                           1.00   1383.7±4.63µs        ? ?/sec    1.00   1383.4±5.66µs        ? ?/sec
physical_plan_clickbench_q40                          1.02      3.3±0.01ms        ? ?/sec    1.00      3.2±0.02ms        ? ?/sec
physical_plan_clickbench_q41                          1.02      2.8±0.01ms        ? ?/sec    1.00      2.7±0.02ms        ? ?/sec
physical_plan_clickbench_q42                          1.02      3.0±0.01ms        ? ?/sec    1.00      2.9±0.01ms        ? ?/sec
physical_plan_clickbench_q43                          1.03      3.1±0.02ms        ? ?/sec    1.00      3.0±0.01ms        ? ?/sec
physical_plan_clickbench_q44                          1.02   1514.1±9.64µs        ? ?/sec    1.00   1489.9±7.21µs        ? ?/sec
physical_plan_clickbench_q45                          1.02  1521.2±10.65µs        ? ?/sec    1.00   1498.2±7.98µs        ? ?/sec
physical_plan_clickbench_q46                          1.00   1784.7±7.61µs        ? ?/sec    1.00   1788.4±6.50µs        ? ?/sec
physical_plan_clickbench_q47                          1.00      2.5±0.01ms        ? ?/sec    1.01      2.5±0.01ms        ? ?/sec
physical_plan_clickbench_q48                          1.01      2.7±0.01ms        ? ?/sec    1.00      2.7±0.01ms        ? ?/sec
physical_plan_clickbench_q49                          1.00      2.8±0.01ms        ? ?/sec    1.00      2.7±0.01ms        ? ?/sec
physical_plan_clickbench_q5                           1.00   1514.7±5.35µs        ? ?/sec    1.00   1516.0±6.44µs        ? ?/sec
physical_plan_clickbench_q50                          1.00      2.6±0.01ms        ? ?/sec    1.00      2.6±0.01ms        ? ?/sec
physical_plan_clickbench_q51                          1.01   1900.0±6.54µs        ? ?/sec    1.00  1872.3±12.38µs        ? ?/sec
physical_plan_clickbench_q6                           1.00   1528.2±6.37µs        ? ?/sec    1.00   1522.2±6.66µs        ? ?/sec
physical_plan_clickbench_q7                           1.01   1354.9±4.56µs        ? ?/sec    1.00   1347.8±5.38µs        ? ?/sec
physical_plan_clickbench_q8                           1.00  1841.0±13.34µs        ? ?/sec    1.01   1853.2±5.91µs        ? ?/sec
physical_plan_clickbench_q9                           1.00   1805.0±8.17µs        ? ?/sec    1.01   1818.0±7.77µs        ? ?/sec
physical_plan_struct_join_agg_sort                    1.01   1290.2±3.54µs        ? ?/sec    1.00   1275.1±7.95µs        ? ?/sec
physical_plan_tpcds_all                               1.02    733.6±3.44ms        ? ?/sec    1.00    718.4±4.58ms        ? ?/sec
physical_plan_tpch_all                                1.03     45.7±0.07ms        ? ?/sec    1.00     44.4±0.07ms        ? ?/sec
physical_plan_tpch_q1                                 1.02   1490.9±2.65µs        ? ?/sec    1.00   1458.0±5.07µs        ? ?/sec
physical_plan_tpch_q10                                1.04      3.0±0.00ms        ? ?/sec    1.00      2.9±0.00ms        ? ?/sec
physical_plan_tpch_q11                                1.06      2.2±0.01ms        ? ?/sec    1.00      2.1±0.00ms        ? ?/sec
physical_plan_tpch_q12                                1.03   1216.0±3.50µs        ? ?/sec    1.00   1184.1±3.44µs        ? ?/sec
physical_plan_tpch_q13                                1.02   1020.2±3.56µs        ? ?/sec    1.00    996.2±3.11µs        ? ?/sec
physical_plan_tpch_q14                                1.02   1404.5±2.26µs        ? ?/sec    1.00   1377.5±2.50µs        ? ?/sec
physical_plan_tpch_q16                                1.03   1544.3±3.20µs        ? ?/sec    1.00   1493.2±3.47µs        ? ?/sec
physical_plan_tpch_q17                                1.03   1718.1±3.14µs        ? ?/sec    1.00   1668.5±3.48µs        ? ?/sec
physical_plan_tpch_q18                                1.04   1998.2±2.69µs        ? ?/sec    1.00   1925.6±2.25µs        ? ?/sec
physical_plan_tpch_q19                                1.02   1654.4±2.69µs        ? ?/sec    1.00   1622.9±2.74µs        ? ?/sec
physical_plan_tpch_q2                                 1.03      4.1±0.01ms        ? ?/sec    1.00      4.0±0.01ms        ? ?/sec
physical_plan_tpch_q20                                1.04      2.2±0.00ms        ? ?/sec    1.00      2.2±0.00ms        ? ?/sec
physical_plan_tpch_q21                                1.03      3.1±0.01ms        ? ?/sec    1.00      3.0±0.00ms        ? ?/sec
physical_plan_tpch_q22                                1.03   1566.5±2.01µs        ? ?/sec    1.00   1513.7±4.10µs        ? ?/sec
physical_plan_tpch_q3                                 1.04   1933.7±3.45µs        ? ?/sec    1.00   1860.8±3.97µs        ? ?/sec
physical_plan_tpch_q4                                 1.05   1227.4±2.52µs        ? ?/sec    1.00   1171.4±3.00µs        ? ?/sec
physical_plan_tpch_q5                                 1.04      2.7±0.00ms        ? ?/sec    1.00      2.6±0.00ms        ? ?/sec
physical_plan_tpch_q6                                 1.07    650.8±3.39µs        ? ?/sec    1.00    610.8±1.63µs        ? ?/sec
physical_plan_tpch_q7                                 1.03      3.0±0.00ms        ? ?/sec    1.00      3.0±0.00ms        ? ?/sec
physical_plan_tpch_q8                                 1.03      4.0±0.01ms        ? ?/sec    1.00      3.9±0.00ms        ? ?/sec
physical_plan_tpch_q9                                 1.03      2.8±0.00ms        ? ?/sec    1.00      2.7±0.00ms        ? ?/sec
physical_select_aggregates_from_200                   1.01     15.5±0.05ms        ? ?/sec    1.00     15.4±0.02ms        ? ?/sec
physical_select_all_from_1000                         1.01    114.7±0.19ms        ? ?/sec    1.00    114.1±0.34ms        ? ?/sec
physical_select_one_from_700                          1.00    759.6±2.64µs        ? ?/sec    1.00    760.5±1.75µs        ? ?/sec
physical_sorted_union_order_by_10_int64               1.01      4.4±0.00ms        ? ?/sec    1.00      4.3±0.01ms        ? ?/sec
physical_sorted_union_order_by_10_uint64              1.01      8.4±0.01ms        ? ?/sec    1.00      8.3±0.02ms        ? ?/sec
physical_sorted_union_order_by_50_int64               1.00    107.8±0.26ms        ? ?/sec    1.00    108.0±0.36ms        ? ?/sec
physical_sorted_union_order_by_50_uint64              1.00    360.4±2.04ms        ? ?/sec    1.00    361.7±2.60ms        ? ?/sec
physical_theta_join_consider_sort                     1.00   1039.9±2.42µs        ? ?/sec    1.00   1040.2±2.08µs        ? ?/sec
physical_unnest_to_join                               1.01    658.2±2.29µs        ? ?/sec    1.00    653.1±5.93µs        ? ?/sec
physical_window_function_partition_by_12_on_values    1.00    724.4±1.78µs        ? ?/sec    1.01    730.3±1.67µs        ? ?/sec
physical_window_function_partition_by_30_on_values    1.00   1441.9±1.67µs        ? ?/sec    1.01   1451.8±2.59µs        ? ?/sec
physical_window_function_partition_by_4_on_values     1.00    438.3±1.49µs        ? ?/sec    1.01    443.9±1.04µs        ? ?/sec
physical_window_function_partition_by_7_on_values     1.00    544.9±1.48µs        ? ?/sec    1.00    545.8±2.09µs        ? ?/sec
physical_window_function_partition_by_8_on_values     1.00    583.9±1.99µs        ? ?/sec    1.00    584.8±1.43µs        ? ?/sec
with_param_values_many_columns                        1.01    433.5±2.49µs        ? ?/sec    1.00    429.7±2.03µs        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 1565.3s
Peak memory 19.9 GiB
Avg memory 19.8 GiB
CPU user 1878.8s
CPU sys 1.9s
Peak spill 0 B

branch

Metric Value
Wall time 1565.3s
Peak memory 19.9 GiB
Avg memory 19.9 GiB
CPU user 1881.7s
CPU sys 1.4s
Peak spill 0 B

File an issue against this benchmark runner

@zhuqi-lucas zhuqi-lucas marked this pull request as ready for review June 4, 2026 03:39
Copilot AI review requested due to automatic review settings June 4, 2026 03:39
@zhuqi-lucas zhuqi-lucas requested review from adriangb, alamb and kosiew June 4, 2026 03:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces LogicalPlan’s stack size by boxing the two oversized DdlStatement variants (CreateExternalTable and CreateFunction), preventing DDL-only payloads from dominating the enum size on the SELECT-query hot path.

Changes:

  • Box DdlStatement::CreateExternalTable and DdlStatement::CreateFunction and update all construction / match / (de)serialization sites accordingly.
  • Add a unit test to pin size_of::<LogicalPlan>() == 176 and assert DdlStatement stays smaller than Join.
  • Adjust FFI/proto boundaries to move values in/out of the new Box<…> wrappers.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
datafusion/sql/src/statement.rs Wraps DDL plan construction sites with Box::new(...) for the newly-boxed variants.
datafusion/proto/src/logical_plan/mod.rs Updates protobuf ↔ logical-plan conversion to box/unbox CreateExternalTable and adjusts field destructuring accordingly.
datafusion/ffi/src/table_provider_factory.rs Updates FFI plan extraction/construction to unbox/box CreateExternalTable at the boundary.
datafusion/expr/src/logical_plan/plan.rs Adds test_size_of_logical_plan to prevent future LogicalPlan size regressions.
datafusion/expr/src/logical_plan/ddl.rs Changes DdlStatement variant payloads to Box<...> and updates schema/display accessors.
datafusion/core/src/execution/context/mod.rs Unboxes CreateFunction when executing DDL so create_function continues to take an owned CreateFunction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zhuqi-lucas
Copy link
Copy Markdown
Contributor Author

zhuqi-lucas commented Jun 4, 2026

cc @alamb

Benchmark results from #22733 (comment) are in — broad, consistent wins on heavy benchmarks, no real regressions.

Optimizer phase (where the change directly applies):

  • optimizer_tpcds_all: −3.3% (294 → 284 ms)
  • optimizer_tpch_all: −3.2% (15.5 → 15.0 ms)
  • optimizer_select_all_from_1000: −3.8%
  • optimizer_join_4_with_agg_filter: −2.9%

Physical-plan phase (also walks LogicalPlan nodes during translation, so it picks up the win):

  • physical_plan_tpch_q11: −5.6%
  • physical_plan_tpch_q10: −3.8%
  • physical_plan_tpch_all: −2.9%
  • physical_plan_tpcds_all: −2.1%
  • A dozen physical_plan_clickbench_q* queries land in the −2% to −4% band

Regressions: none of material size. A handful of sub-200µs benches sit at +1% inside the noise band; the bench harness shows no statistically distinguishable slowdown anywhere.

Profiling motivation held up: ~13% of sql_planner CPU was in memcpy/memmove. Shrinking LogicalPlan from 320 → 176 bytes (−45%) directly attacks that pool, and the wins are largest on the heaviest queries (TPC-H, TPC-DS, ClickBench) where the optimizer + physical planner walk the most nodes.

@zhuqi-lucas zhuqi-lucas requested a review from 2010YOUY01 June 4, 2026 07:47
Copy link
Copy Markdown
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Makes sense to me and is consistent with our other structures. Thank you @zhuqi-lucas

@alamb alamb added the api change Changes the API exposed to users of the crate label Jun 4, 2026
@alamb
Copy link
Copy Markdown
Contributor

alamb commented Jun 4, 2026

I think it is worth a short note in the upgrade guide too

@zhuqi-lucas
Copy link
Copy Markdown
Contributor Author

I think it is worth a short note in the upgrade guide too

Thank you @alamb for review , i will update the upgrade guide too!

Copy link
Copy Markdown
Contributor

@adriangb adriangb left a comment

Choose a reason for hiding this comment

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

Makes sense to me!

@zhuqi-lucas
Copy link
Copy Markdown
Contributor Author

zhuqi-lucas commented Jun 5, 2026

@alamb added an upgrade guide note in e23fcab46 — covers the construction-site change, pattern-match rewrites, and how to get an owned struct back out with *cmd.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jun 5, 2026
@zhuqi-lucas zhuqi-lucas added this pull request to the merge queue Jun 5, 2026
@zhuqi-lucas
Copy link
Copy Markdown
Contributor Author

Thanks @alamb and @adriangb for review, merged to main branch now.

Merged via the queue into apache:main with commit 2ec0ab5 Jun 5, 2026
39 checks passed
@zhuqi-lucas zhuqi-lucas deleted the perf/box-large-ddl-variants branch June 5, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api change Changes the API exposed to users of the crate core Core DataFusion crate documentation Improvements or additions to documentation ffi Changes to the ffi crate logical-expr Logical plan and expressions proto Related to proto crate sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: LogicalPlan enum is 320 bytes due to oversized DdlStatement variants

5 participants