Uh oh!
There was an error while loading. Please reload this page.
Project RecordBatch before evaluating case - #18055
Conversation
I hadn't considered physical expression serialisation in my implementation. Perhaps it would be better to hide the projection logic inside |
pepijnve
commented
Oct 14, 2025
apache/arrow-rs#8591 should help mitigate the overhead of the |
pepijnve
commented
Oct 15, 2025
@alamb this one is the next episode in my quest to squeeze more performance out of case. The TL;DR is that we project away unneeded columns from the record batch to avoid work during filtering. I thought this would be most elegant as a decorator expression, but that's immediately visible externally and as a consequence would need serialisation support. The alternative is that I pull this into CaseExpr, perhaps as a distinct (or wrapping) evaluation mode? Any opinion on the direction in which to proceed? |
alamb
commented
Oct 15, 2025
LOVE IT! I will continue to help support you / review these PRs. I love a good set of performance optimizations I am also going to start tracking the collection here as a larger theme |
alamb
commented
Oct 15, 2025
There is similar code for filtering here (namely that evaluates the filter expression first, and then only calles datafusion/datafusion/physical-plan/src/filter.rs Lines 644 to 668 in a8925f3 |
This touches on one of the things I was struggling with a bit working in the I already need the schema anyway in order to decide if it makes sense to project or not. One simple solution is to just keep a reference to that one. But things get a bit weird when a |
At somepoint in the past we discussed some sort of "precompile" step for PhysicalExprs -- which was invoked right before the plan started executing. The usecase as I recall was to compile regexp once (rather than per batch). Maybe it is time to do that now 🤔 There is more background here if you are interested |
pepijnve
commented
Oct 24, 2025
Closing in favour of #18275 which handles the projection logic internally. |
Which issue does this PR close?
SELECT *, CASE ... END#18056Rationale for this change
When
CaseExprcallsPhysicalExpr::evaluate_selectionthat function will filter the entire inputRecordBatchbefore callingPhysicalExpr::evaluate. This filtering filters all columns of theRecordBatch, even ones that will not be accessed by thePhysicalExpr. For wide record batches and narrow expressions it can be beneficial to project the record batch first to reduce the amount of wasted filtering work.What changes are included in this PR?
ProjectedExprtype which projects incoming record batches and then evaluates a project version of the originalPhysicalExprAre these changes tested?
casehas been extendedAre there any user-facing changes?
No