Skip to content

Improve constant folding for associative operations#23215

Open
hadrian-reppas wants to merge 6 commits into
apache:mainfrom
hadrian-reppas:assoc_expr_simplify
Open

Improve constant folding for associative operations#23215
hadrian-reppas wants to merge 6 commits into
apache:mainfrom
hadrian-reppas:assoc_expr_simplify

Conversation

@hadrian-reppas

@hadrian-reppas hadrian-reppas commented Jun 27, 2026

Copy link
Copy Markdown

Which issue does this PR close?

Closes #17158

Rationale for this change

The query planner currently does not optimize expressions like c1 || 'a' || 'b' || c2 (which it could simplify it to c1 || 'ab' || c2). This is because the ConstEvaluator looks for BinaryExprs where both arguments are Literals. The expression above looks like

        ||
       /  \
      ||   c2
     /  \
   ||   'b'
  /  \
c1   'a'

so it does not get optimized. Since string concatenation is associative, we can rewrite the expression to look like

        ||
       /  \
      ||   c2
     /  \
   c1   ||
       /  \
     'a'  'b'

which the ConstEvaluator can optimize to

        ||
       /  \
      ||   c2
     /  \
   c1   'ab'

We start by flattening nested occurrences of a the same associative operator into a list. Then we rebuild the expression tree from this list so that adjacent Literals appear together in the same subtree. This rewrite happens in the expr_simplifier::Simplifier so that the ConstEvaluator can do its work on a subsequent pass.

What changes are included in this PR?

This PR implements the is_associative_with_adjacent_literals and reassociate_literals functions.

There are some remaining questions:

  1. Is this a sensible approach?
  2. What other operators/types are associative?
  3. Should we do something similar for commutative operations (eg move all literals to the front so they can be constant folded together)?

Are these changes tested?

Yes

Are there any user-facing changes?

No

@github-actions github-actions Bot added the optimizer Optimizer rules label Jun 27, 2026
impl<'n> TreeNodeVisitor<'n> for AdjacentLiteralVisitor {
type Node = Expr;

fn f_down(&mut self, node: &'n Self::Node) -> Result<TreeNodeRecursion> {

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.

last_expr_was_literal is not reset when visiting a nonliteral. For (lit(1) + col("c1")) + lit(2), the rewrite appears to rebuild the same expression but still results in Transformed::yes

Instead you could make has_adjacent_literals inspect the flattened operand sequence for the same operator, and reset adjacency whenever a nonliteral operand appears.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I kept the AdjacentLiteralVisitor and changed it so that it updates last_expr_was_literal correctly. is_associative_with_adjacent_literals needs to take the expression by reference because we call it from the big match statement in the Simplifier. I'm not sure I can construct the flattened operand sequence with just a reference to the expression. I suppose I could construct a Vec<&Expr>, but I'm not sure how much better that would be. Unless I could somehow write one function that does &Expr -> Vec<&Expr> and Expr -> Vec<Expr>.

Comment thread datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs Outdated
@hadrian-reppas

Copy link
Copy Markdown
Author

Also I realized that you have to check that the types match because otherwise reassociating the expression can change when casts happen which can change the answer if there is overflow. For example:

> CREATE TABLE t(x INT);
> INSERT INTO t(x) VALUES (1);
> SELECT (x + CAST(1 AS TINYINT)) + CAST(127 AS TINYINT) FROM t;
129
> SELECT x + (CAST(1 AS TINYINT) + CAST(127 AS TINYINT)) FROM t;
-127

@github-actions github-actions Bot added the sqllogictest SQL Logic Tests (.slt) label Jul 5, 2026
@hadrian-reppas

Copy link
Copy Markdown
Author

@nathanb9, I made some changes and the checks are now green. What do you think?

@hadrian-reppas

Copy link
Copy Markdown
Author

Bumping this @nathanb9

@nathanb9

Copy link
Copy Markdown
Contributor

To me this makes sense @hadrian-reppas
But since I not a maintainer I cannot help get this across the line

@Jefffrey

Copy link
Copy Markdown
Contributor

run benchmarks sql_planner sql_planner_extended

@adriangbot

This comment was marked as duplicate.

@adriangbot

This comment was marked as duplicate.

Comment on lines +2371 to +2383
match &expr {
Expr::BinaryExpr(binary)
if binary.op == op
&& matches!(info.get_data_type(&expr), Ok(dt) if &dt == datatype) =>
{
let Expr::BinaryExpr(binary) = expr else {
unreachable!()
};
flatten(op, datatype, info, *binary.left, out);
flatten(op, datatype, info, *binary.right, out);
}
_ => out.push(expr),
}

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.

Suggested change
match &expr {
Expr::BinaryExpr(binary)
if binary.op == op
&& matches!(info.get_data_type(&expr), Ok(dt) if &dt == datatype) =>
{
let Expr::BinaryExpr(binary) = expr else {
unreachable!()
};
flatten(op, datatype, info, *binary.left, out);
flatten(op, datatype, info, *binary.right, out);
}
_ => out.push(expr),
}
match expr {
Expr::BinaryExpr(binary)
if binary.op == op
&& matches!(info.get_data_type(&expr), Ok(dt) if &dt == datatype) =>
{
flatten(op, datatype, info, *binary.left, out);
flatten(op, datatype, info, *binary.right, out);
}
_ => out.push(expr),
}

minor refactor to avoid the duplicate unstructuring

}

// (A + 1) + 2 -> A + (1 + 2)
expr if is_associative_with_adjacent_literals(&expr, self.info) => {

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.

i do worry about this guard; it seems in the worst case, with Simplifier already doing a traversal (up) of the expr tree, this guard then does another traversal (down) of the tree, repeatedly as the simplifier goes up 🤔

ill see if benchmarks show this as an actual impact

@adriangbot

Copy link
Copy Markdown

🤖 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                                                 HEAD                                   assoc_expr_simplify
-----                                                 ----                                   -------------------
logical_aggregate_with_join                           1.00    459.3±1.00µs        ? ?/sec    1.00    460.1±1.37µs        ? ?/sec
logical_correlated_subquery_exists                    1.00    287.3±1.00µs        ? ?/sec    1.00    288.0±0.92µs        ? ?/sec
logical_correlated_subquery_in                        1.00    287.3±0.98µs        ? ?/sec    1.00    288.3±0.74µs        ? ?/sec
logical_distinct_many_columns                         1.00    570.0±1.22µs        ? ?/sec    1.01    574.4±1.74µs        ? ?/sec
logical_join_4_with_agg_and_filter                    1.00    250.3±0.97µs        ? ?/sec    1.01    252.8±1.07µs        ? ?/sec
logical_join_8_with_agg_sort_limit                    1.00    427.2±1.83µs        ? ?/sec    1.00    427.8±1.22µs        ? ?/sec
logical_join_chain_16                                 1.00    677.1±3.87µs        ? ?/sec    1.01    685.9±3.90µs        ? ?/sec
logical_join_chain_4                                  1.00    120.7±0.32µs        ? ?/sec    1.02    123.1±0.42µs        ? ?/sec
logical_join_chain_8                                  1.00    249.7±0.73µs        ? ?/sec    1.02    254.7±0.86µs        ? ?/sec
logical_multiple_subqueries                           1.00    521.7±2.67µs        ? ?/sec    1.01    527.1±1.77µs        ? ?/sec
logical_nested_cte_4_levels                           1.00    261.3±1.19µs        ? ?/sec    1.02    266.3±1.14µs        ? ?/sec
logical_plan_struct_join_agg_sort                     1.01    185.5±0.64µs        ? ?/sec    1.00    182.9±1.97µs        ? ?/sec
logical_plan_tpcds_all                                1.00     92.8±0.17ms        ? ?/sec    1.00     92.7±0.17ms        ? ?/sec
logical_plan_tpch_all                                 1.00      6.5±0.02ms        ? ?/sec    1.00      6.5±0.02ms        ? ?/sec
logical_scalar_subquery                               1.00    310.2±0.88µs        ? ?/sec    1.00    311.2±0.96µs        ? ?/sec
logical_select_all_from_1000                          1.00    104.0±0.38ms        ? ?/sec    1.01    104.6±0.84ms        ? ?/sec
logical_select_one_from_700                           1.00    327.6±1.88µs        ? ?/sec    1.01    329.9±1.75µs        ? ?/sec
logical_trivial_join_high_numbered_columns            1.00    287.9±0.94µs        ? ?/sec    1.01    289.9±0.80µs        ? ?/sec
logical_trivial_join_low_numbered_columns             1.00    274.6±0.77µs        ? ?/sec    1.01    277.0±0.93µs        ? ?/sec
logical_union_4_branches                              1.00    424.7±0.93µs        ? ?/sec    1.01    427.5±1.23µs        ? ?/sec
logical_union_8_branches                              1.00    818.8±1.59µs        ? ?/sec    1.01   826.6±14.06µ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.00ms        ? ?/sec    1.01      2.4±0.00ms        ? ?/sec
logical_wide_filter_200_predicates                    1.00   1318.1±9.86µs        ? ?/sec    1.01  1327.6±11.34µs        ? ?/sec
logical_wide_filter_50_predicates                     1.00    392.9±2.94µs        ? ?/sec    1.01    395.5±3.87µs        ? ?/sec
optimizer_correlated_exists                           1.00    254.7±1.76µs        ? ?/sec    1.00    254.9±0.88µs        ? ?/sec
optimizer_join_4_with_agg_filter                      1.00    457.3±2.03µs        ? ?/sec    1.00    457.4±2.02µs        ? ?/sec
optimizer_join_chain_4                                1.01    180.5±0.60µs        ? ?/sec    1.00    179.3±0.88µs        ? ?/sec
optimizer_join_chain_8                                1.00    557.2±2.81µs        ? ?/sec    1.01    561.7±1.15µs        ? ?/sec
optimizer_select_all_from_1000                        1.00      6.9±0.01ms        ? ?/sec    1.00      7.0±0.01ms        ? ?/sec
optimizer_select_one_from_700                         1.00    263.9±0.56µs        ? ?/sec    1.01    265.5±0.54µs        ? ?/sec
optimizer_tpcds_all                                   1.00    307.9±0.46ms        ? ?/sec    1.02    315.0±0.30ms        ? ?/sec
optimizer_tpch_all                                    1.00     17.2±0.03ms        ? ?/sec    1.02     17.6±0.03ms        ? ?/sec
optimizer_wide_aggregate_100                          1.00      2.2±0.01ms        ? ?/sec    1.00      2.2±0.01ms        ? ?/sec
optimizer_wide_filter_200                             1.00      3.7±0.02ms        ? ?/sec    8.50     31.7±0.03ms        ? ?/sec
physical_intersection                                 1.00    582.4±1.58µs        ? ?/sec    1.01    588.3±1.65µs        ? ?/sec
physical_join_consider_sort                           1.00   1030.3±3.08µs        ? ?/sec    1.01   1040.0±3.40µs        ? ?/sec
physical_join_distinct                                1.00    268.6±1.56µs        ? ?/sec    1.02    274.0±1.08µs        ? ?/sec
physical_many_self_joins                              1.00      7.8±0.01ms        ? ?/sec    1.01      7.9±0.01ms        ? ?/sec
physical_plan_clickbench_all                          1.00    127.5±0.30ms        ? ?/sec    1.02    129.9±0.26ms        ? ?/sec
physical_plan_clickbench_q1                           1.00   1370.3±7.69µs        ? ?/sec    1.00   1371.1±7.91µ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.1±0.01ms        ? ?/sec    1.02      2.2±0.01ms        ? ?/sec
physical_plan_clickbench_q12                          1.00      2.2±0.01ms        ? ?/sec    1.02      2.3±0.01ms        ? ?/sec
physical_plan_clickbench_q13                          1.00      2.0±0.01ms        ? ?/sec    1.00      2.0±0.01ms        ? ?/sec
physical_plan_clickbench_q14                          1.00      2.1±0.01ms        ? ?/sec    1.01      2.2±0.01ms        ? ?/sec
physical_plan_clickbench_q15                          1.00      2.1±0.01ms        ? ?/sec    1.00      2.1±0.01ms        ? ?/sec
physical_plan_clickbench_q16                          1.00   1747.3±7.90µs        ? ?/sec    1.02   1778.5±5.12µs        ? ?/sec
physical_plan_clickbench_q17                          1.00   1794.6±7.07µs        ? ?/sec    1.00   1791.8±5.76µs        ? ?/sec
physical_plan_clickbench_q18                          1.00  1673.6±10.56µs        ? ?/sec    1.01   1694.8±7.74µs        ? ?/sec
physical_plan_clickbench_q19                          1.00      2.0±0.01ms        ? ?/sec    1.02      2.1±0.01ms        ? ?/sec
physical_plan_clickbench_q2                           1.00   1765.0±7.82µs        ? ?/sec    1.00   1767.8±4.83µs        ? ?/sec
physical_plan_clickbench_q20                          1.00   1539.0±6.03µs        ? ?/sec    1.02   1571.8±5.26µs        ? ?/sec
physical_plan_clickbench_q21                          1.00   1764.0±6.18µs        ? ?/sec    1.02   1802.4±4.62µs        ? ?/sec
physical_plan_clickbench_q22                          1.00      2.2±0.01ms        ? ?/sec    1.01      2.2±0.00ms        ? ?/sec
physical_plan_clickbench_q23                          1.00      2.3±0.01ms        ? ?/sec    1.01      2.3±0.01ms        ? ?/sec
physical_plan_clickbench_q24                          1.00      6.8±0.02ms        ? ?/sec    1.00      6.8±0.01ms        ? ?/sec
physical_plan_clickbench_q25                          1.01   1912.6±7.54µs        ? ?/sec    1.00   1893.3±6.74µs        ? ?/sec
physical_plan_clickbench_q26                          1.01   1751.3±7.77µs        ? ?/sec    1.00   1726.9±5.41µs        ? ?/sec
physical_plan_clickbench_q27                          1.01   1929.3±8.27µs        ? ?/sec    1.00   1908.6±6.74µs        ? ?/sec
physical_plan_clickbench_q28                          1.01      2.4±0.01ms        ? ?/sec    1.00      2.4±0.01ms        ? ?/sec
physical_plan_clickbench_q29                          1.01      2.6±0.01ms        ? ?/sec    1.00      2.5±0.01ms        ? ?/sec
physical_plan_clickbench_q3                           1.00   1649.9±6.52µs        ? ?/sec    1.00   1648.2±5.89µs        ? ?/sec
physical_plan_clickbench_q30                          1.00     15.2±0.03ms        ? ?/sec    1.09     16.5±0.05ms        ? ?/sec
physical_plan_clickbench_q31                          1.00      2.5±0.01ms        ? ?/sec    1.01      2.5±0.01ms        ? ?/sec
physical_plan_clickbench_q32                          1.00      2.4±0.01ms        ? ?/sec    1.02      2.5±0.01ms        ? ?/sec
physical_plan_clickbench_q33                          1.00      2.0±0.01ms        ? ?/sec    1.02      2.0±0.00ms        ? ?/sec
physical_plan_clickbench_q34                          1.00  1777.7±11.60µs        ? ?/sec    1.02   1811.5±5.89µs        ? ?/sec
physical_plan_clickbench_q35                          1.00   1821.0±6.70µs        ? ?/sec    1.03   1879.9±6.23µs        ? ?/sec
physical_plan_clickbench_q36                          1.00      2.1±0.01ms        ? ?/sec    1.02      2.2±0.00ms        ? ?/sec
physical_plan_clickbench_q37                          1.00      2.5±0.01ms        ? ?/sec    1.02      2.5±0.01ms        ? ?/sec
physical_plan_clickbench_q38                          1.00      2.5±0.01ms        ? ?/sec    1.02      2.5±0.01ms        ? ?/sec
physical_plan_clickbench_q39                          1.00      2.6±0.01ms        ? ?/sec    1.02      2.6±0.01ms        ? ?/sec
physical_plan_clickbench_q4                           1.00   1461.9±6.48µs        ? ?/sec    1.01   1470.7±5.85µs        ? ?/sec
physical_plan_clickbench_q40                          1.00      3.3±0.01ms        ? ?/sec    1.01      3.3±0.01ms        ? ?/sec
physical_plan_clickbench_q41                          1.00      2.8±0.01ms        ? ?/sec    1.02      2.9±0.01ms        ? ?/sec
physical_plan_clickbench_q42                          1.00      3.0±0.01ms        ? ?/sec    1.02      3.1±0.01ms        ? ?/sec
physical_plan_clickbench_q43                          1.00      3.1±0.01ms        ? ?/sec    1.01      3.2±0.01ms        ? ?/sec
physical_plan_clickbench_q44                          1.00   1554.0±6.45µs        ? ?/sec    1.00   1550.8±4.64µs        ? ?/sec
physical_plan_clickbench_q45                          1.00   1560.3±6.46µs        ? ?/sec    1.03   1605.4±4.69µs        ? ?/sec
physical_plan_clickbench_q46                          1.00   1881.6±8.34µs        ? ?/sec    1.03  1929.0±14.10µs        ? ?/sec
physical_plan_clickbench_q47                          1.01      2.6±0.02ms        ? ?/sec    1.00      2.6±0.01ms        ? ?/sec
physical_plan_clickbench_q48                          1.00      2.8±0.01ms        ? ?/sec    1.00      2.8±0.01ms        ? ?/sec
physical_plan_clickbench_q49                          1.00      2.9±0.01ms        ? ?/sec    1.02      2.9±0.01ms        ? ?/sec
physical_plan_clickbench_q5                           1.00   1580.2±7.07µs        ? ?/sec    1.01   1596.2±6.14µs        ? ?/sec
physical_plan_clickbench_q50                          1.00      2.7±0.01ms        ? ?/sec    1.05      2.8±0.00ms        ? ?/sec
physical_plan_clickbench_q51                          1.00   1977.4±7.96µs        ? ?/sec    1.01   1988.0±7.41µs        ? ?/sec
physical_plan_clickbench_q6                           1.00   1585.6±7.32µs        ? ?/sec    1.01   1601.3±4.44µs        ? ?/sec
physical_plan_clickbench_q7                           1.00   1420.7±5.31µs        ? ?/sec    1.01   1430.6±5.25µs        ? ?/sec
physical_plan_clickbench_q8                           1.00   1892.3±7.15µs        ? ?/sec    1.01   1915.6±6.33µs        ? ?/sec
physical_plan_clickbench_q9                           1.00   1864.6±7.64µs        ? ?/sec    1.01   1879.3±4.98µs        ? ?/sec
physical_plan_struct_join_agg_sort                    1.01   1311.7±3.68µs        ? ?/sec    1.00   1299.9±4.33µs        ? ?/sec
physical_plan_tpcds_all                               1.00    716.1±0.40ms        ? ?/sec    1.01    725.6±0.61ms        ? ?/sec
physical_plan_tpch_all                                1.00     45.4±0.05ms        ? ?/sec    1.00     45.3±0.05ms        ? ?/sec
physical_plan_tpch_q1                                 1.00   1532.8±2.16µs        ? ?/sec    1.00   1535.3±2.27µs        ? ?/sec
physical_plan_tpch_q10                                1.00      2.9±0.00ms        ? ?/sec    1.02      2.9±0.00ms        ? ?/sec
physical_plan_tpch_q11                                1.00      2.3±0.00ms        ? ?/sec    1.00      2.3±0.00ms        ? ?/sec
physical_plan_tpch_q12                                1.00   1224.2±3.11µs        ? ?/sec    1.02   1244.9±3.28µs        ? ?/sec
physical_plan_tpch_q13                                1.01   1019.6±2.90µs        ? ?/sec    1.00   1012.5±3.40µs        ? ?/sec
physical_plan_tpch_q14                                1.01   1460.3±2.92µs        ? ?/sec    1.00   1451.0±4.38µs        ? ?/sec
physical_plan_tpch_q16                                1.01   1608.7±3.83µs        ? ?/sec    1.00   1588.4±2.51µs        ? ?/sec
physical_plan_tpch_q17                                1.01   1718.9±3.84µs        ? ?/sec    1.00   1695.6±2.41µs        ? ?/sec
physical_plan_tpch_q18                                1.02   1994.2±2.53µs        ? ?/sec    1.00   1956.5±2.37µs        ? ?/sec
physical_plan_tpch_q19                                1.00   1931.7±3.42µs        ? ?/sec    1.04      2.0±0.00ms        ? ?/sec
physical_plan_tpch_q2                                 1.00      3.6±0.00ms        ? ?/sec    1.01      3.6±0.00ms        ? ?/sec
physical_plan_tpch_q20                                1.01      2.2±0.00ms        ? ?/sec    1.00      2.2±0.01ms        ? ?/sec
physical_plan_tpch_q21                                1.00      3.0±0.00ms        ? ?/sec    1.00      3.0±0.00ms        ? ?/sec
physical_plan_tpch_q22                                1.02   1604.5±3.60µs        ? ?/sec    1.00   1574.7±2.54µs        ? ?/sec
physical_plan_tpch_q3                                 1.00   1854.8±2.89µs        ? ?/sec    1.01   1870.6±2.98µs        ? ?/sec
physical_plan_tpch_q4                                 1.00   1208.1±2.88µs        ? ?/sec    1.01   1218.5±2.44µs        ? ?/sec
physical_plan_tpch_q5                                 1.00      2.8±0.00ms        ? ?/sec    1.02      2.8±0.00ms        ? ?/sec
physical_plan_tpch_q6                                 1.00    651.5±1.23µs        ? ?/sec    1.02    665.3±1.48µs        ? ?/sec
physical_plan_tpch_q7                                 1.00      2.9±0.00ms        ? ?/sec    1.02      2.9±0.00ms        ? ?/sec
physical_plan_tpch_q8                                 1.00      3.9±0.00ms        ? ?/sec    1.02      4.0±0.01ms        ? ?/sec
physical_plan_tpch_q9                                 1.00      2.7±0.00ms        ? ?/sec    1.01      2.7±0.00ms        ? ?/sec
physical_select_aggregates_from_200                   1.00     15.7±0.04ms        ? ?/sec    1.00     15.7±0.05ms        ? ?/sec
physical_select_all_from_1000                         1.00    116.6±1.98ms        ? ?/sec    1.00    116.2±0.46ms        ? ?/sec
physical_select_one_from_700                          1.00    783.1±2.61µs        ? ?/sec    1.01    791.6±4.53µs        ? ?/sec
physical_sorted_union_order_by_10_int64               1.00      4.4±0.01ms        ? ?/sec    1.00      4.4±0.00ms        ? ?/sec
physical_sorted_union_order_by_10_uint64              1.01      8.6±0.01ms        ? ?/sec    1.00      8.5±0.01ms        ? ?/sec
physical_sorted_union_order_by_50_int64               1.01    108.7±0.22ms        ? ?/sec    1.00    107.9±0.22ms        ? ?/sec
physical_sorted_union_order_by_50_uint64              1.00    365.5±0.52ms        ? ?/sec    1.00    363.8±0.55ms        ? ?/sec
physical_theta_join_consider_sort                     1.00   1056.1±2.91µs        ? ?/sec    1.01   1067.1±3.15µs        ? ?/sec
physical_unnest_to_join                               1.00    661.0±1.61µs        ? ?/sec    1.01    669.9±2.17µs        ? ?/sec
physical_window_function_partition_by_12_on_values    1.00    734.3±1.09µs        ? ?/sec    1.00    733.1±1.88µs        ? ?/sec
physical_window_function_partition_by_30_on_values    1.00   1456.7±2.66µs        ? ?/sec    1.00   1462.9±7.10µs        ? ?/sec
physical_window_function_partition_by_4_on_values     1.01    451.8±1.07µs        ? ?/sec    1.00    448.9±1.22µs        ? ?/sec
physical_window_function_partition_by_7_on_values     1.01    556.8±1.78µs        ? ?/sec    1.00    551.6±1.32µs        ? ?/sec
physical_window_function_partition_by_8_on_values     1.00    593.9±1.64µs        ? ?/sec    1.00    592.1±1.45µs        ? ?/sec
with_param_values_many_columns                        1.00    429.6±2.06µs        ? ?/sec    1.01    434.9±2.96µs        ? ?/sec

Resource Usage

sql_planner — base (merge-base)

Metric Value
Wall time 2355.5s
Peak memory 131.0 MiB
Avg memory 67.7 MiB
CPU user 1874.0s
CPU sys 1.4s
Peak spill 0 B

sql_planner — branch

Metric Value
Wall time 2490.6s
Peak memory 130.6 MiB
Avg memory 63.6 MiB
CPU user 1880.2s
CPU sys 1.4s
Peak spill 0 B

File an issue against this benchmark runner

@adriangbot

This comment was marked as outdated.

@Jefffrey

Copy link
Copy Markdown
Contributor

run benchmark sql_planner_extended
env:
BENCH_FILTER: logical_plan

@adriangbot

This comment was marked as duplicate.

@adriangbot

Copy link
Copy Markdown

Benchmark for this request hit the 7200s job deadline before finishing.

Benchmarks requested: sql_planner_extended

Kubernetes message
Job was active longer than specified deadline

File an issue against this benchmark runner

tohuya6 pushed a commit to tohuya6/datafusion that referenced this pull request Jul 18, 2026
… size to 5 (apache#23659)

on my M4 Macbook pro, it estimates it would take 50 minutes (!) to run
the benchmark

```sh
datafusion (main)$ cargo bench -p datafusion --bench sql_planner_extended logical_plan
   Compiling datafusion-common v54.0.0 (/Users/jeffrey/Code/datafusion/datafusion/common)
...
   Compiling datafusion v54.0.0 (/Users/jeffrey/Code/datafusion/datafusion/core)
    Finished `bench` profile [optimized] target(s) in 8m 11s
     Running benches/sql_planner_extended.rs (/Users/jeffrey/.cargo_target_cache/release/deps/sql_planner_extended-c026520b80bba716)
Gnuplot not found, using plotters backend
Benchmarking logical_plan_optimize: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 3077.4s, or reduce sample count to 10.
Benchmarking logical_plan_optimize: Collecting 100 samples in estimated 3077.4 s (100 iterations)
```

and running it via the bot just times out:
apache#23215 (comment)

so might actually be useful to reduce the sample size so it can actually
run and be of use to us
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify col1 || 'a' || 'b' || col2 to col1 || 'ab' || col2

4 participants