akshatsinghrajawat commented on issue #27631: URL: https://github.com/apache/datafusion/issues/27631#issuecomment-7284855859
I traced this through `rewrite_projection`. The filter is split into top-level AND-conjuncts before reaching it, so an OR expression stays as one predicate. `replace_cols_by_column` then substitutes the projected expression at every reference. So Lia's reference-count idea should catch the reported case. One gap I see is that counting references separately in each conjunct could miss repeated uses across different conjuncts. For example, `WHERE u > 10 AND u < 20` has one reference to `u` in each conjunct, but pushing both can still inline its definition twice. Would it make sense to count references to each projected output across the full set of predicates, and, when the count crosses a threshold, keep the conjuncts referencing that output above the projection while still pushing unrelated predicates? References in predicates that are already being kept should also be accounted for. I also noticed that the draft of #25456 already introduces `ProjectionInliner`, with shared column-resolution and reference-counting logic. Reusing that machinery seems preferable to adding another independent implementation. Its current duplication policy would need some thought, though: it allows repeated inlining of columns and leaf expressions, but that could also prevent duplication of cheap expressions like `a + 1` and `CAST`, which is exactly the regression Lia highlighted. I agree with Adrian's clarification that `KeepInPlace` means the cost is unknown, not necessarily that the expression is expensive. I wouldn't use it alone as the duplication signal, especially given the problems with the earlier #25388 attempt. Would this broader reference-count approach be a reasonable first experiment? -- 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]
