pub fn ensure_sorting(
requirements: PlanContext<bool>,
) -> Result<Transformed<PlanContext<bool>>, DataFusionError>Expand description
This function enforces sorting requirements and makes optimizations without violating these requirements whenever possible. Requires a bottom-up traversal.
Steps
- Analyze if there are any immediate removals of
SortExecs. If so, removes them (seeanalyze_immediate_sort_removal). - For each child of the plan, if the plan requires an input ordering:
- Checks if ordering is satisfied with the child. If not:
- If the child has an output ordering, removes the unnecessary
SortExec. - Adds sort above the child plan.
- If the child has an output ordering, removes the unnecessary
- (Plan not requires input ordering)
- Checks if the
SortExecis neutralized in the plan. If so, removes it.
- Checks if the
- Checks if ordering is satisfied with the child. If not:
- Check and modify window operator:
- Checks if the plan is a window operator, and connected with a sort.
If so, either tries to update the window definition or removes
unnecessary
SortExecs (seeadjust_window_sort_removal).
- Checks if the plan is a window operator, and connected with a sort.
If so, either tries to update the window definition or removes
unnecessary
- Check and remove possibly unnecessary SPM:
- Checks if the plan is SPM and child 1 output partitions, if so decides this SPM is unnecessary and removes it from the plan.