adriangb commented on code in PR #26270:
URL: https://github.com/apache/datafusion/pull/26270#discussion_r4776222678
##########
datafusion/execution/src/task.rs:
##########
@@ -53,6 +69,71 @@ pub struct TaskContext {
window_functions: HashMap<String, Arc<WindowUDF>>,
/// Runtime environment associated with this task context
runtime: Arc<RuntimeEnv>,
+ /// State that operators keep for one run of a plan
+ run_state: Arc<RunState>,
+}
+
+/// State that the operators of a plan keep for one run of that plan.
Review Comment:
Yes, I think this is close to what @askalt proposed in
https://github.com/apache/datafusion/issues/19351: keep per-execution state in
the `TaskContext` instead of in the plan. That stalled mostly because it tried
to cover every operator at once (hash tables, metrics, dynamic filters), keyed
by plan node pointer, which changes whenever the plan is rewritten.
This PR does the same thing for just one operator. The CTE has a stable id
from the planner, so it can look up its buffered output like this:
```rust
let outputs = context.run_state().get_or_init::<MaterializedCteOutputs>();
```
The rule is "one `TaskContext` = one execution". That fits both modes from
your comment in https://github.com/apache/datafusion/issues/19905:
- Run the plan again with a new `TaskContext`: the CTE is recomputed, no
`reset_state` needed.
- Run it concurrently with separate `TaskContext`s: each run has its own
buffer, no deep copy needed.
The one sharp edge is reusing the *same* `TaskContext` for two executions:
the second run would replay the first run's buffered output.
It does not help dynamic filters, since those are wired into the scan at
planning time. The same pattern could work there eventually, but I think that
discussion belongs in #19905. To avoid committing to anything here, I cam make
`RunState` crate-private and document the one-context-per-execution rule. Would
that make this change more palatable?
--
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]