Skip to content

Optimize PhysicalExprSimplifier#20111

Merged
Dandandan merged 6 commits intoapache:mainfrom
AdamGS:adamg/optimize-phyiscal-expr-simplifier
Feb 3, 2026
Merged

Optimize PhysicalExprSimplifier#20111
Dandandan merged 6 commits intoapache:mainfrom
AdamGS:adamg/optimize-phyiscal-expr-simplifier

Conversation

@AdamGS
Copy link
Contributor

@AdamGS AdamGS commented Feb 2, 2026

Which issue does this PR close?

Rationale for this change

An attempt at reducing the cost of physical expression simplification

What changes are included in this PR?

  1. The most important change in this PR is that if an expression is already literal, don't transform it, which means we can stop transforming the tree much earlier. currently on main, even expressions like lit(5) end up running through the loop 5 times. This takes this PR to ~96% improvement on the benchmark.
  2. Allocate a single dummy record batch for simplifying const expressions, instead of one per simplify_const_expr call.
  3. Adds the benchmark I've been using to test the impact of changes
  4. simplify_not_expr and simplify_const_expr now take an Arc instead of &Arc

Are these changes tested?

All existing tests pass with minor modifications.

Are there any user-facing changes?

Two of the individual recursive simplification functions (simplify_not_expr and simplify_const_expr) are public. This PR breaks their signature, but I think we should consider also making them private.

@github-actions github-actions bot added the physical-expr Changes to the physical-expr crates label Feb 2, 2026
Signed-off-by: Adam Gutglick <adamgsal@gmail.com>
@AdamGS AdamGS force-pushed the adamg/optimize-phyiscal-expr-simplifier branch from d7d40e7 to 8d0e19d Compare February 2, 2026 14:06
@AdamGS
Copy link
Contributor Author

AdamGS commented Feb 2, 2026

64505b5 is a 36% improvement in the benchmark on my laptop (I suspect the macos allocator isn't great)

@AdamGS
Copy link
Contributor Author

AdamGS commented Feb 2, 2026

seems like I broke something bigger here, I'll give this PR the attention it deserves later in the week.

@@ -44,13 +44,13 @@ use crate::expressions::{BinaryExpr, InListExpr, Literal, NotExpr, in_list, lit}
/// TreeNodeRewriter, multiple passes will automatically be applied until no more
/// transformations are possible.
pub fn simplify_not_expr(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a breaking change

}
Ok(Transformed::no(e))
})
if let Some(binary) = expr.as_any().downcast_ref::<BinaryExpr>()
Copy link
Contributor Author

@AdamGS AdamGS Feb 2, 2026

Choose a reason for hiding this comment

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

this significantly changes the behavior of the function, we can move the logic into an internal private function and keep this public one, nvm, unlike the others this one is pub(crate)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is not a recursive function anymore, we control the order externally

// specific language governing permissions and limitations
// under the License.

//! This is an attempt at reproducing some predicates generated by TPC-DS query #76,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added the benchmark to make it easy for others to use it, it could be evolved over time if we find more usecases people care about

@AdamGS
Copy link
Contributor Author

AdamGS commented Feb 2, 2026

This PR shows about 56% improvement compared to main on my laptop

tpc-ds/q76/cs/16        time:   [409.68 µs 414.78 µs 420.93 µs]
                        change: [−56.502% −56.083% −55.701%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
  4 (4.00%) high severe

tpc-ds/q76/ws/16        time:   [401.58 µs 402.22 µs 402.94 µs]
                        change: [−57.073% −56.921% −56.780%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
  5 (5.00%) high mild

tpc-ds/q76/cs/128       time:   [3.0027 ms 3.0235 ms 3.0522 ms]
                        change: [−56.084% −55.799% −55.362%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) high mild
  3 (3.00%) high severe

tpc-ds/q76/ws/128       time:   [3.0033 ms 3.0116 ms 3.0213 ms]
                        change: [−56.183% −56.050% −55.884%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe

@Dandandan
Copy link
Contributor

run benchmarks

@alamb-ghbot
Copy link

🤖 ./gh_compare_branch.sh gh_compare_branch.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing adamg/optimize-phyiscal-expr-simplifier (ebe60a2) to 545c37f diff using: tpch_mem clickbench_partitioned clickbench_extended
Results will be posted here when complete

@Dandandan
Copy link
Contributor

run benchmark tpcds tpch

@AdamGS AdamGS changed the title WIP: Optimize PhysicalExprSimplifier Optimize PhysicalExprSimplifier Feb 2, 2026
}
}

fn can_evaluate_as_constant(expr: &Arc<dyn PhysicalExpr>) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we create a ticket to avoid the double recursion here?

@AdamGS
Copy link
Contributor Author

AdamGS commented Feb 2, 2026

I pushed another check for consts that seems to have really really good performance (from 56% improvement to 97%), but I'm suspicious, trying to figure out what is going on.

@alamb-ghbot
Copy link

🤖: Benchmark completed

Details

Comparing HEAD and adamg_optimize-phyiscal-expr-simplifier
--------------------
Benchmark clickbench_extended.json
--------------------
┏━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query    ┃        HEAD ┃ adamg_optimize-phyiscal-expr-simplifier ┃        Change ┃
┡━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0 │  2340.07 ms │                              2253.85 ms │     no change │
│ QQuery 1 │   927.86 ms │                               876.95 ms │ +1.06x faster │
│ QQuery 2 │  1778.54 ms │                              1791.83 ms │     no change │
│ QQuery 3 │  1038.96 ms │                              1057.86 ms │     no change │
│ QQuery 4 │  2169.61 ms │                              2188.49 ms │     no change │
│ QQuery 5 │ 28364.86 ms │                             28129.90 ms │     no change │
│ QQuery 6 │  4021.99 ms │                              3973.27 ms │     no change │
│ QQuery 7 │  3002.74 ms │                              2657.23 ms │ +1.13x faster │
└──────────┴─────────────┴─────────────────────────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Benchmark Summary                                      ┃            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Time (HEAD)                                      │ 43644.62ms │
│ Total Time (adamg_optimize-phyiscal-expr-simplifier)   │ 42929.38ms │
│ Average Time (HEAD)                                    │  5455.58ms │
│ Average Time (adamg_optimize-phyiscal-expr-simplifier) │  5366.17ms │
│ Queries Faster                                         │          2 │
│ Queries Slower                                         │          0 │
│ Queries with No Change                                 │          6 │
│ Queries with Failure                                   │          0 │
└────────────────────────────────────────────────────────┴────────────┘
--------------------
Benchmark clickbench_partitioned.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query     ┃        HEAD ┃ adamg_optimize-phyiscal-expr-simplifier ┃        Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0  │     2.63 ms │                                 2.61 ms │     no change │
│ QQuery 1  │    53.37 ms │                                54.07 ms │     no change │
│ QQuery 2  │   138.96 ms │                               132.00 ms │ +1.05x faster │
│ QQuery 3  │   155.51 ms │                               155.16 ms │     no change │
│ QQuery 4  │  1004.73 ms │                              1032.81 ms │     no change │
│ QQuery 5  │  1276.60 ms │                              1274.78 ms │     no change │
│ QQuery 6  │     8.56 ms │                                 7.80 ms │ +1.10x faster │
│ QQuery 7  │    57.70 ms │                                55.85 ms │     no change │
│ QQuery 8  │  1364.19 ms │                              1422.91 ms │     no change │
│ QQuery 9  │  1783.56 ms │                              1720.02 ms │     no change │
│ QQuery 10 │   357.12 ms │                               365.62 ms │     no change │
│ QQuery 11 │   402.15 ms │                               404.57 ms │     no change │
│ QQuery 12 │  1226.16 ms │                              1213.91 ms │     no change │
│ QQuery 13 │  1922.83 ms │                              1881.02 ms │     no change │
│ QQuery 14 │  1246.65 ms │                              1211.66 ms │     no change │
│ QQuery 15 │  1185.17 ms │                              1176.70 ms │     no change │
│ QQuery 16 │  2498.74 ms │                              2488.00 ms │     no change │
│ QQuery 17 │  2468.39 ms │                              2448.85 ms │     no change │
│ QQuery 18 │  5036.36 ms │                              4736.78 ms │ +1.06x faster │
│ QQuery 19 │   119.58 ms │                               123.71 ms │     no change │
│ QQuery 20 │  1930.80 ms │                              1867.44 ms │     no change │
│ QQuery 21 │  2198.85 ms │                              2174.16 ms │     no change │
│ QQuery 22 │  4336.69 ms │                              3668.71 ms │ +1.18x faster │
│ QQuery 23 │ 19423.86 ms │                             12116.54 ms │ +1.60x faster │
│ QQuery 24 │   217.72 ms │                               217.94 ms │     no change │
│ QQuery 25 │   491.04 ms │                               459.84 ms │ +1.07x faster │
│ QQuery 26 │   221.82 ms │                               220.07 ms │     no change │
│ QQuery 27 │  2643.40 ms │                              2639.27 ms │     no change │
│ QQuery 28 │ 23443.23 ms │                             21734.67 ms │ +1.08x faster │
│ QQuery 29 │   968.35 ms │                               998.75 ms │     no change │
│ QQuery 30 │  1263.87 ms │                              1240.78 ms │     no change │
│ QQuery 31 │  1365.81 ms │                              1327.78 ms │     no change │
│ QQuery 32 │  4933.18 ms │                              4269.79 ms │ +1.16x faster │
│ QQuery 33 │  5661.86 ms │                              5341.88 ms │ +1.06x faster │
│ QQuery 34 │  6101.71 ms │                              5531.58 ms │ +1.10x faster │
│ QQuery 35 │  1865.99 ms │                              1824.69 ms │     no change │
│ QQuery 36 │   196.30 ms │                               193.09 ms │     no change │
│ QQuery 37 │    80.68 ms │                                75.25 ms │ +1.07x faster │
│ QQuery 38 │   119.65 ms │                               115.46 ms │     no change │
│ QQuery 39 │   351.67 ms │                               346.75 ms │     no change │
│ QQuery 40 │    45.25 ms │                                40.53 ms │ +1.12x faster │
│ QQuery 41 │    37.28 ms │                                35.83 ms │     no change │
│ QQuery 42 │    33.70 ms │                                32.17 ms │     no change │
└───────────┴─────────────┴─────────────────────────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓
┃ Benchmark Summary                                      ┃             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩
│ Total Time (HEAD)                                      │ 100241.65ms │
│ Total Time (adamg_optimize-phyiscal-expr-simplifier)   │  88381.85ms │
│ Average Time (HEAD)                                    │   2331.20ms │
│ Average Time (adamg_optimize-phyiscal-expr-simplifier) │   2055.39ms │
│ Queries Faster                                         │          12 │
│ Queries Slower                                         │           0 │
│ Queries with No Change                                 │          31 │
│ Queries with Failure                                   │           0 │
└────────────────────────────────────────────────────────┴─────────────┘
--------------------
Benchmark tpch_mem_sf1.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query     ┃      HEAD ┃ adamg_optimize-phyiscal-expr-simplifier ┃        Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1  │ 101.15 ms │                               103.45 ms │     no change │
│ QQuery 2  │  33.48 ms │                                33.29 ms │     no change │
│ QQuery 3  │  40.04 ms │                                35.47 ms │ +1.13x faster │
│ QQuery 4  │  31.09 ms │                                31.39 ms │     no change │
│ QQuery 5  │  89.80 ms │                                92.60 ms │     no change │
│ QQuery 6  │  20.46 ms │                                21.56 ms │  1.05x slower │
│ QQuery 7  │ 155.26 ms │                               162.34 ms │     no change │
│ QQuery 8  │  40.51 ms │                                43.13 ms │  1.06x slower │
│ QQuery 9  │ 105.07 ms │                                99.00 ms │ +1.06x faster │
│ QQuery 10 │  66.12 ms │                                70.42 ms │  1.06x slower │
│ QQuery 11 │  19.60 ms │                                18.83 ms │     no change │
│ QQuery 12 │  51.18 ms │                                52.42 ms │     no change │
│ QQuery 13 │  48.17 ms │                                48.88 ms │     no change │
│ QQuery 14 │  15.07 ms │                                15.21 ms │     no change │
│ QQuery 15 │  30.29 ms │                                30.07 ms │     no change │
│ QQuery 16 │  29.07 ms │                                28.65 ms │     no change │
│ QQuery 17 │ 141.74 ms │                               140.78 ms │     no change │
│ QQuery 18 │ 279.14 ms │                               286.44 ms │     no change │
│ QQuery 19 │  40.13 ms │                                40.63 ms │     no change │
│ QQuery 20 │  54.82 ms │                                56.25 ms │     no change │
│ QQuery 21 │ 183.36 ms │                               194.29 ms │  1.06x slower │
│ QQuery 22 │  22.41 ms │                                23.35 ms │     no change │
└───────────┴───────────┴─────────────────────────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Benchmark Summary                                      ┃           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ Total Time (HEAD)                                      │ 1597.98ms │
│ Total Time (adamg_optimize-phyiscal-expr-simplifier)   │ 1628.43ms │
│ Average Time (HEAD)                                    │   72.64ms │
│ Average Time (adamg_optimize-phyiscal-expr-simplifier) │   74.02ms │
│ Queries Faster                                         │         2 │
│ Queries Slower                                         │         4 │
│ Queries with No Change                                 │        16 │
│ Queries with Failure                                   │         0 │
└────────────────────────────────────────────────────────┴───────────┘

@alamb-ghbot
Copy link

🤖 ./gh_compare_branch.sh gh_compare_branch.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing adamg/optimize-phyiscal-expr-simplifier (2089cd1) to 545c37f diff using: tpcds
Results will be posted here when complete

batch: &RecordBatch,
) -> Result<Transformed<Arc<dyn PhysicalExpr>>> {
// If expr is already a const literal or can't be evaluated into one.
if expr.as_any().is::<Literal>() || (!can_evaluate_as_constant(&expr)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

adding this check for literal value makes a huge difference here, which also what I saw before in #20078, it can also be moved into can_evaluate_as_constant.
I think what happens is that there are trees that used to marked as transformed even though it was just a a literal being evaluated to itself.

Copy link
Contributor Author

@AdamGS AdamGS Feb 2, 2026

Choose a reason for hiding this comment

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

@Dandandan I'm convinced this is the biggest win and a significant win here. Right now even something like lit(5) will run through 5 simplification steps, which are completely avoidable. I've also verified it locally.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes a lot of sense!

@AdamGS AdamGS force-pushed the adamg/optimize-phyiscal-expr-simplifier branch from 2089cd1 to 1999178 Compare February 2, 2026 18:06
@alamb-ghbot
Copy link

🤖: Benchmark completed

Details

Comparing HEAD and adamg_optimize-phyiscal-expr-simplifier
--------------------
Benchmark tpcds_sf1.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query     ┃        HEAD ┃ adamg_optimize-phyiscal-expr-simplifier ┃        Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1  │    72.33 ms │                                71.46 ms │     no change │
│ QQuery 2  │   215.42 ms │                               211.67 ms │     no change │
│ QQuery 3  │   156.56 ms │                               155.79 ms │     no change │
│ QQuery 4  │  1931.85 ms │                              1940.78 ms │     no change │
│ QQuery 5  │   279.96 ms │                               263.34 ms │ +1.06x faster │
│ QQuery 6  │  1462.43 ms │                              1434.35 ms │     no change │
│ QQuery 7  │   511.43 ms │                               517.68 ms │     no change │
│ QQuery 8  │   173.08 ms │                               167.27 ms │     no change │
│ QQuery 9  │   304.24 ms │                               298.72 ms │     no change │
│ QQuery 10 │   181.20 ms │                               173.03 ms │     no change │
│ QQuery 11 │  1302.78 ms │                              1282.06 ms │     no change │
│ QQuery 12 │    71.10 ms │                                69.20 ms │     no change │
│ QQuery 13 │   564.82 ms │                               539.27 ms │     no change │
│ QQuery 14 │  1901.67 ms │                              1890.84 ms │     no change │
│ QQuery 15 │    31.69 ms │                                26.54 ms │ +1.19x faster │
│ QQuery 16 │    66.30 ms │                                64.77 ms │     no change │
│ QQuery 17 │   369.91 ms │                               359.27 ms │     no change │
│ QQuery 18 │   199.04 ms │                               192.24 ms │     no change │
│ QQuery 19 │   236.05 ms │                               214.47 ms │ +1.10x faster │
│ QQuery 20 │    27.52 ms │                                25.63 ms │ +1.07x faster │
│ QQuery 21 │    39.67 ms │                                36.75 ms │ +1.08x faster │
│ QQuery 22 │   727.21 ms │                               696.95 ms │     no change │
│ QQuery 23 │  1786.98 ms │                              1798.79 ms │     no change │
│ QQuery 24 │   709.46 ms │                               691.38 ms │     no change │
│ QQuery 25 │   538.39 ms │                               520.52 ms │     no change │
│ QQuery 26 │   131.62 ms │                               136.64 ms │     no change │
│ QQuery 27 │   511.56 ms │                               539.68 ms │  1.05x slower │
│ QQuery 28 │   309.34 ms │                               292.43 ms │ +1.06x faster │
│ QQuery 29 │   459.58 ms │                               451.87 ms │     no change │
│ QQuery 30 │    78.19 ms │                                76.32 ms │     no change │
│ QQuery 31 │   310.89 ms │                               309.51 ms │     no change │
│ QQuery 32 │    85.79 ms │                                81.08 ms │ +1.06x faster │
│ QQuery 33 │   205.39 ms │                               206.10 ms │     no change │
│ QQuery 34 │   160.00 ms │                               159.45 ms │     no change │
│ QQuery 35 │   170.26 ms │                               176.55 ms │     no change │
│ QQuery 36 │   294.85 ms │                               286.48 ms │     no change │
│ QQuery 37 │   256.45 ms │                               255.95 ms │     no change │
│ QQuery 38 │   154.31 ms │                               152.97 ms │     no change │
│ QQuery 39 │   206.83 ms │                               198.86 ms │     no change │
│ QQuery 40 │   176.85 ms │                               178.49 ms │     no change │
│ QQuery 41 │    32.01 ms │                                25.10 ms │ +1.28x faster │
│ QQuery 42 │   145.77 ms │                               142.93 ms │     no change │
│ QQuery 43 │   125.61 ms │                               126.01 ms │     no change │
│ QQuery 44 │    28.98 ms │                                29.84 ms │     no change │
│ QQuery 45 │    91.36 ms │                                85.67 ms │ +1.07x faster │
│ QQuery 46 │   326.94 ms │                               320.99 ms │     no change │
│ QQuery 47 │  1036.83 ms │                              1022.98 ms │     no change │
│ QQuery 48 │   411.93 ms │                               401.85 ms │     no change │
│ QQuery 49 │   389.24 ms │                               371.60 ms │     no change │
│ QQuery 50 │   329.98 ms │                               335.53 ms │     no change │
│ QQuery 51 │   302.68 ms │                               303.59 ms │     no change │
│ QQuery 52 │   145.54 ms │                               144.70 ms │     no change │
│ QQuery 53 │   150.02 ms │                               145.04 ms │     no change │
│ QQuery 54 │   223.86 ms │                               205.08 ms │ +1.09x faster │
│ QQuery 55 │   144.56 ms │                               145.06 ms │     no change │
│ QQuery 56 │   210.47 ms │                               205.97 ms │     no change │
│ QQuery 57 │   298.86 ms │                               292.35 ms │     no change │
│ QQuery 58 │   509.56 ms │                               498.08 ms │     no change │
│ QQuery 59 │   294.82 ms │                               295.95 ms │     no change │
│ QQuery 60 │   215.46 ms │                               209.57 ms │     no change │
│ QQuery 61 │   249.80 ms │                               240.50 ms │     no change │
│ QQuery 62 │  1286.17 ms │                              1267.91 ms │     no change │
│ QQuery 63 │   151.14 ms │                               146.55 ms │     no change │
│ QQuery 64 │  1191.61 ms │                              1165.56 ms │     no change │
│ QQuery 65 │   353.25 ms │                               353.53 ms │     no change │
│ QQuery 66 │   405.79 ms │                               399.99 ms │     no change │
│ QQuery 67 │   554.69 ms │                               522.57 ms │ +1.06x faster │
│ QQuery 68 │   378.68 ms │                               368.96 ms │     no change │
│ QQuery 69 │   170.95 ms │                               172.04 ms │     no change │
│ QQuery 70 │   499.60 ms │                               485.15 ms │     no change │
│ QQuery 71 │   185.51 ms │                               184.06 ms │     no change │
│ QQuery 72 │  2123.91 ms │                              2164.33 ms │     no change │
│ QQuery 73 │   154.52 ms │                               155.78 ms │     no change │
│ QQuery 74 │   827.03 ms │                               816.11 ms │     no change │
│ QQuery 75 │   416.59 ms │                               400.17 ms │     no change │
│ QQuery 76 │   190.46 ms │                               184.73 ms │     no change │
│ QQuery 77 │   292.51 ms │                               275.52 ms │ +1.06x faster │
│ QQuery 78 │   684.64 ms │                               678.34 ms │     no change │
│ QQuery 79 │   331.67 ms │                               324.30 ms │     no change │
│ QQuery 80 │   532.81 ms │                               525.18 ms │     no change │
│ QQuery 81 │    53.53 ms │                                51.79 ms │     no change │
│ QQuery 82 │   280.85 ms │                               281.06 ms │     no change │
│ QQuery 83 │    82.16 ms │                                80.24 ms │     no change │
│ QQuery 84 │    69.99 ms │                                69.46 ms │     no change │
│ QQuery 85 │   230.00 ms │                               215.99 ms │ +1.06x faster │
│ QQuery 86 │    59.71 ms │                                57.79 ms │     no change │
│ QQuery 87 │   154.89 ms │                               155.25 ms │     no change │
│ QQuery 88 │   261.86 ms │                               268.28 ms │     no change │
│ QQuery 89 │   167.58 ms │                               165.99 ms │     no change │
│ QQuery 90 │    46.79 ms │                                44.80 ms │     no change │
│ QQuery 91 │   101.24 ms │                                95.36 ms │ +1.06x faster │
│ QQuery 92 │    84.40 ms │                                81.12 ms │     no change │
│ QQuery 93 │   283.64 ms │                               280.94 ms │     no change │
│ QQuery 94 │    92.83 ms │                                90.25 ms │     no change │
│ QQuery 95 │   253.50 ms │                               246.74 ms │     no change │
│ QQuery 96 │   113.39 ms │                               115.01 ms │     no change │
│ QQuery 97 │   188.29 ms │                               192.09 ms │     no change │
│ QQuery 98 │   221.06 ms │                               215.30 ms │     no change │
│ QQuery 99 │ 14229.60 ms │                             14234.65 ms │     no change │
└───────────┴─────────────┴─────────────────────────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Benchmark Summary                                      ┃            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Time (HEAD)                                      │ 50744.14ms │
│ Total Time (adamg_optimize-phyiscal-expr-simplifier)   │ 50226.47ms │
│ Average Time (HEAD)                                    │   512.57ms │
│ Average Time (adamg_optimize-phyiscal-expr-simplifier) │   507.34ms │
│ Queries Faster                                         │         14 │
│ Queries Slower                                         │          1 │
│ Queries with No Change                                 │         84 │
│ Queries with Failure                                   │          0 │
└────────────────────────────────────────────────────────┴────────────┘

@alamb-ghbot
Copy link

🤖 ./gh_compare_branch.sh gh_compare_branch.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing adamg/optimize-phyiscal-expr-simplifier (1999178) to 545c37f diff using: tpch
Results will be posted here when complete

@AdamGS AdamGS marked this pull request as ready for review February 2, 2026 18:14
@alamb-ghbot
Copy link

🤖: Benchmark completed

Details

Comparing HEAD and adamg_optimize-phyiscal-expr-simplifier
--------------------
Benchmark tpch_sf1.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query     ┃      HEAD ┃ adamg_optimize-phyiscal-expr-simplifier ┃        Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1  │ 178.34 ms │                               179.50 ms │     no change │
│ QQuery 2  │  87.74 ms │                                88.55 ms │     no change │
│ QQuery 3  │ 128.30 ms │                               120.57 ms │ +1.06x faster │
│ QQuery 4  │  78.20 ms │                                79.79 ms │     no change │
│ QQuery 5  │ 172.40 ms │                               172.43 ms │     no change │
│ QQuery 6  │  69.26 ms │                                68.55 ms │     no change │
│ QQuery 7  │ 207.22 ms │                               204.54 ms │     no change │
│ QQuery 8  │ 172.63 ms │                               169.21 ms │     no change │
│ QQuery 9  │ 228.79 ms │                               221.84 ms │     no change │
│ QQuery 10 │ 193.24 ms │                               182.60 ms │ +1.06x faster │
│ QQuery 11 │  63.27 ms │                                62.77 ms │     no change │
│ QQuery 12 │ 121.28 ms │                               118.46 ms │     no change │
│ QQuery 13 │ 216.96 ms │                               219.01 ms │     no change │
│ QQuery 14 │  90.15 ms │                                88.09 ms │     no change │
│ QQuery 15 │ 127.41 ms │                               125.50 ms │     no change │
│ QQuery 16 │  59.97 ms │                                58.68 ms │     no change │
│ QQuery 17 │ 262.88 ms │                               259.00 ms │     no change │
│ QQuery 18 │ 315.35 ms │                               312.70 ms │     no change │
│ QQuery 19 │ 136.90 ms │                               132.85 ms │     no change │
│ QQuery 20 │ 130.75 ms │                               126.43 ms │     no change │
│ QQuery 21 │ 262.20 ms │                               256.64 ms │     no change │
│ QQuery 22 │  41.45 ms │                                40.06 ms │     no change │
└───────────┴───────────┴─────────────────────────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Benchmark Summary                                      ┃           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ Total Time (HEAD)                                      │ 3344.71ms │
│ Total Time (adamg_optimize-phyiscal-expr-simplifier)   │ 3287.78ms │
│ Average Time (HEAD)                                    │  152.03ms │
│ Average Time (adamg_optimize-phyiscal-expr-simplifier) │  149.44ms │
│ Queries Faster                                         │         2 │
│ Queries Slower                                         │         0 │
│ Queries with No Change                                 │        20 │
│ Queries with Failure                                   │         0 │
└────────────────────────────────────────────────────────┴───────────┘

unwrap_cast::unwrap_cast_in_comparison(node, schema)
})?
.transform_data(|node| const_evaluator::simplify_const_expr(&node))?;
simplify_const_expr_with_dummy(node, &batch)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, I think we can find the subtrees that do and then just skip the others, thinking through this now but it might have to wait for tomorrow

@AdamGS
Copy link
Contributor Author

AdamGS commented Feb 3, 2026

@Dandandan I'll move the last piece related to simplify_const_expr_with_dummy to a separate issue and PR so this can get merged, tried to explain it in #20134 but feel free to edit it/add any state you have in your head.

@Dandandan
Copy link
Contributor

Thanks a lot!

Merged via the queue into apache:main with commit 29d63c1 Feb 3, 2026
37 checks passed
@AdamGS
Copy link
Contributor Author

AdamGS commented Feb 3, 2026

Thank you for the careful review and feedback! Never really touched that part of DataFusion before, so its very cool to be able to get it in so quickly.

@alamb alamb added the performance Make DataFusion faster label Feb 3, 2026
@alamb
Copy link
Contributor

alamb commented Feb 3, 2026

This is a very nice change

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

Labels

performance Make DataFusion faster physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants