marikomedlock opened a new pull request, #27527:
URL: https://github.com/apache/datafusion/pull/27527
## Which issue does this PR close?
- Closes #27526.
## Rationale for this change
`SimplifyExpressions` and `RewriteSetComparison` merge the schemas of all of
a node's inputs before rewriting its expressions. On a `Union` with N inputs
that merge is O(N²) in the number of fields, and it's wasted: a `Union` has no
expressions of its own. With n-ary unions (#27523), on a plan with 7 unions of
up to 186 inputs, this change cut `SessionState::optimize` from 2.34s to 1.34s
on a 4-vCPU Graviton2 and from 0.332s to 0.199s on an Apple M-series laptop.
Details are in #27526.
## What changes are included in this PR?
- `SimplifyExpressions`: return early, before building the schema, when the
node has no expressions of its own.
- `RewriteSetComparison`: return early when none of the node's own
expressions contains an `Expr::SetComparison`.
For these nodes both rules already returned the plan unchanged, so no plan
changes.
## What is the testing strategy for this PR?
This is a performance change with no change in plans, so the new tests check
that the rules still behave the same around the skipped nodes:
- `simplify_exprs`:
- `test_simplify_skips_union`: a 3-input `Union` comes back untransformed.
- `test_simplify_filter_above_union`: `a > 1 AND true` above a 3-input
`Union` is still simplified to `a > 1`.
- `rewrite_set_comparison` (new test module):
- `skips_union`: a 3-input `Union` comes back untransformed.
- `rewrites_set_comparison_above_union`: `a > ALL (subquery)` in a
`Filter` above a 3-input `Union` is still rewritten, with no set comparison
left in the plan.
- The existing `datafusion-optimizer` tests and the sqllogictest suite pass
unchanged.
This PR doesn't depend on #27525; the numbers above were measured with both
applied.
## Are there any user-facing changes?
No.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]