Expand description
Two-pass optimizer pipeline that pushes cheap expressions (like struct field
access user['status']) closer to data sources, enabling early data reduction
and source-level optimizations (e.g., Parquet column pruning). See
ExtractLeafExpressions (pass 1) and PushDownLeafProjections (pass 2).
§Precedence over PushDownFilter
PushDownLeafProjections and PushDownFilter both move nodes towards
the leaves, and for an adjacent filter and pure extraction projection (a
projection whose expressions are only __datafusion_extracted_N aliases and
pass-through columns) they want the opposite order:
Filter: t.date = '2025-01-03' <-- (A)
Projection: get_field(t.ids, 'id1') AS __datafusion_extracted_1, t.date <-- (B)
TableScan: tPushDownFilter wants (A) below (B). PushDownLeafProjections wants (B)
below (A). Before https://github.com/apache/datafusion/issues/14540 was
decided the two rules undid each other on every optimizer pass, and the rule
that runs later in the list won.
Invariant: pure extraction projections win. PushDownFilter does not
move a filter below a pure extraction projection, so the plan above is the
final plan. PushDownLeafProjections keeps moving such a projection through
a filter, which is how the projection reaches the scan.
The reason is that the extraction projection is the node a source absorbs.
A Parquet scan merges it into the file projection and reads only the struct
leaf. With the opposite precedence the scan reads the whole struct whenever
datafusion.execution.parquet.pushdown_filters is false, which is the
default. The filter loses nothing by staying one node higher, because
PushDownFilter records the predicate in
TableScan::filters in the pass
that runs before the extraction projection exists, so row group pruning and
source level filtering still happen.
§Yields to OptimizeProjections
When the extraction projection cannot move below the input of a projection
(for example a TableScan or an Aggregate), PushDownLeafProjections
leaves the projection unchanged. Splitting it in place would give a
recovery projection over an extraction projection on the same input, and
OptimizeProjections merges those two back into the original projection.
The two rules would then undo each other on every optimizer pass. The split
has no use there: the source absorbs the leaf expressions of the original
projection just as well.
Structs§
- Extract
Leaf Expressions - Extracts
MoveTowardsLeafNodessub-expressions from non-projection nodes into extraction projections (pass 1 of 2). - Push
Down Leaf Projections - Pushes extraction projections down through schema-preserving nodes towards
leaf nodes (pass 2 of 2, after
ExtractLeafExpressions).