Reduce number of traversals per node in PhysicalExprSimplifier
#20082
+19
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
simplify_const_exprtraverses expression tree twice when once is enough #20081.Rationale for this change
Ran into this while investigating #20078, in my benchmarks this saves around %10, which can quickly add up to a few ms per query.
The benchmarking code is here, measuring it on my laptop the effect is:
What changes are included in this PR?
I've also changed
[cfg(test)]to a debug assertion, which seems more in the spirit of #18001, and will make the check fail even if a test in another crate triggers, which effectively increases the coverage.Are these changes tested?
The functionality is identical, and in addition to existing tests I've changed the defensive assertion into a debug check and ran tests for other crates that make use of this codepath (like
datafusion-datasource-parquetanddatafusion-pruning).Are there any user-facing changes?
None