One SQL Query, Fully Traced
Consider SELECT city, count(*) FROM trips WHERE fare > 20 GROUP BY city.
SessionContext::sqlsnapshots session state and asks it to create a logical plan. Parsing yields a SQL AST;SqlToRelresolves tables, columns, functions, and types into DataFusion expressions and plan nodes.- The analyzer checks and coerces the plan. Logical optimizer rules can push the filter toward the scan, prune columns, and simplify expressions without choosing threads or file partitions.
- The query planner maps logical nodes to
Arc<dyn ExecutionPlan>nodes. A physical optimizer then enforces distribution and ordering requirements and may introduce repartition or coalesce operators. - Execution asks the root for an output stream. For several root partitions, callers can keep separate streams or place a coalescing node above them.
- Polling the root recursively polls its children. The scan obtains a batch; the filter computes a selection mask; the partial aggregate updates per-partition state; a repartition boundary redistributes rows; the final aggregate emits grouped batches.
collectdrains the stream intoVec<RecordBatch>. A streaming caller can instead process each batch and release it before requesting the next.
Nothing “runs the whole plan” when it is constructed. Plan creation describes the graph; polling an output stream drives the graph.