AhmedSoliman commented on issue #19905: URL: https://github.com/apache/datafusion/issues/19905#issuecomment-7276129451
A data point for the "independent reuse" row, from a slightly different direction: **many reset copies of one plan running at the same time, inside a single task.** In [Restate](https://github.com/restatedev/restate), a partition read runs one copy of a template plan per storage partition, several at a time, each made with `reset_plan_states(template)`. The template can hold a `CollectLeft` `HashJoinExec`, a TopK `SortExec` or a MIN/MAX `AggregateExec`, with our scan below it. The scan is our own `ExecutionPlan`, not `DataSourceExec`, and reads the dynamic filter like `DataSourceExec` does. With DataFusion 56: - `HashJoinExec` (and `AggregateExec`) copies share one filter, because `reset_state` resets it in place, so one partition's build keys can filter another partition's probe rows. Our test of a shard-local join page (a TopK and a `CollectLeft` join in the template, several copies in flight) returned wrong rows in 3 runs out of 3 before each copy got its own filters. - `SortExec` copies get a new filter, but the copy's scan still reads the template's, so the TopK prunes nothing in the copy (the same gap as #26642). What we do today, after `reset_plan_states`: 1. Pair each producer in the copy with the template's, by position. 2. Keep the new filter where `reset_state` created one (`SortExec`), and otherwise give the producer a fresh filter through `HashJoinExec::with_dynamic_filter_expr` / `AggregateExec::with_dynamic_filter_expr`. 3. Rebind our scans to the copy's filters by expression id. That is the "rebind the producer and its consumers by expression id when we instantiate the plan" idea from #26669, done outside DataFusion. It is also the use case #24610 asked about before deprecating those setters. Two things would let us delete this: 1. **A supported way to get independent copies**: fresh filters per copy, with producers and consumers rebound, as a separate entry point from the recursive-iteration reset, which wants the opposite. 2. **Consumers outside DataFusion can take part.** A rebinding that only knows `DataSourceExec` wouldn't reach our scans. Something like a `map_expressions` counterpart to `apply_expressions`, or a dedicated hook that takes old expression id → new filter (no-op by default), would cover custom nodes. `datafusion-distributed` deep-copies each task's plan through protobuf to keep tasks' filters apart, for a related reason; a supported way to rebind would probably let it avoid that round trip too. Happy to help test a design against our case. -- 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]
