Repository navigation
Conversation
| let new_properties = new_projection.equivalence_properties(); | ||
| for ordering in plan.equivalence_properties().oeq_class().iter() { | ||
| if !new_properties.ordering_satisfy(ordering.iter().cloned())? { | ||
| return Ok(None); |
There was a problem hiding this comment.
Is giving up entirely the right move here? Are there scenarios where soime projection pruning just not the columns that order depends on would be the right move?
| let new_child = new_child | ||
| .transform_down(remove_unnecessary_projections) | ||
| .data()?; | ||
| if leaves.is_empty() && count_projections(&new_child)? > count_projections(child)? { |
There was a problem hiding this comment.
Could we add a comment explaining what this condition is suppossed to do?
| let child = repartition.input(); | ||
| let child_schema = child.schema(); | ||
| let passthrough_indices = collect_outer_columns(projection.expr(), &leaves)?; | ||
| if leaves.is_empty() && passthrough_indices.len() == child_schema.fields().len() { |
There was a problem hiding this comment.
Same here, a comment explaining what the condition is / why we need it would be great.
|
Found one regression with a model here: SET datafusion.execution.target_partitions = 4;
SET datafusion.execution.batch_size = 2;
SET datafusion.execution.parquet.pushdown_filters = true;
COPY (
SELECT column1 AS c, column2 AS a, column3 AS b
FROM VALUES (6, 5, 1), (6, 4, 2), (6, -1, 7), (6, 9, -3)
) TO 'constant-input.parquet' STORED AS PARQUET;
CREATE EXTERNAL TABLE t STORED AS PARQUET
LOCATION 'constant-input.parquet';
SELECT a + b + 1 AS k, a
FROM t
WHERE c = a + b AND c + 1 = 7
ORDER BY k, a;Pre-PR optimizer returnins |
|
Thank you, this is a real bug. 72e7b57 fixes it, and your query is now an SLT case. If you cherry-picked this PR before that commit, please also take 72e7b57 and c43952d. |
A check of the split needs to build one before the lower half moves down. No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three of these queries fail to plan. The split drops a column that gives the output its order, or makes it constant, and an ancestor relies on that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The split compares the output with that of a trial split. If the trial loses a constant, an equality or an ordering, the lower half also passes through the columns that it came from. It checks again after the lower half has moved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…them Otherwise the split reads a sort column, and builds a trial split, for an ordering that nothing needs. A sort replaces the ordering of its input, and `OutputRequirementExec` declares the one that the query needs. An operator that is not known to declare every ordering it relies on keeps the check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mechanical. The next commits also split a projection that has no leaf. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The plans are those without pruning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A scan outputs the columns that its predicate reads, and a round robin repartition keeps them alive. Split a projection also if that only drops a column, so that the scan absorbs the lower half. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A sort or a window declines a projection that drops its key. The key is dead above it, so a `ProjectionExec` drops it before the repartition. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
c43952d to
29b3d10
Compare
Which issue does this PR close?
Stacked on #27925. The first four commits here belong to it. Please review only the last four.
This is an alternative to #27777. The diagnosis in the issue is by ivan-kiselev.
Rationale for this change
A scan emits columns that only its pushed-down predicate reads. They cross a round robin repartition before a computed projection drops them. A struct is not necessary:
What changes are included in this PR?
#27152 splits a projection across a round robin repartition, but only if the projection has a leaf expression. This PR also splits it if that prunes a column.
ProjectionExecbelow the repartition drops it there.Trade-offs
A pruning
ProjectionExeccan stay in the plan even if the column it drops is narrow.If the scan absorbs only part of a filter, the
FilterExecthat stays takes the projection, and the split does not see it. A column that only the absorbed part reads still crosses the repartition. An SLT case pins this plan.The ordering check also applies to leaf splits. Below an operator that is not on the list it can keep a sort column that nothing needs.
Building a smaller plan costs planning time. The cost is in
ProjectionExec::try_new, which computes the equivalence properties again. Median of 15 interleaved runs on an M-series laptop,release-nonlto, physical planning only:Benchmarks
Median of 15 interleaved runs on an idle
c4a-standard-16VM. Profilerelease-nonlto,target_partitions = 4,pushdown_filters = true,repartition_file_scans = false.thas 10M rows.ehas 3M rows with a 97 byteurl.mainis bb1dad1. "PR 27777" is the Rust diff of 858edef applied to thatmain. "This PR" in this table and the next is b163aed.output_bytes(main / both PRs)turlurlpredicate belowLIMIT 2000000ORDER BY url LIMIT 300000urlGROUP BY, plan not affectedA
ProjectionExecthat nothing absorbs shows no clear time difference, but it lowers the memory that the query needs. This isORDER BY url LIMIT 300000with a slow expression above it:On
mainthe allocation that fails is that ofSortPreservingMergeExec, which shares the pool with the repartition.output_bytescounts a string buffer again for each batch that shares it, so the GB values are not memory use. A checksum of the answers agrees for every query that completes, except the bareLIMIT, which returns an arbitrary set of rows.AI assistance
Claude Code wrote the code, the tests and this description at the request of the PR author.
What is the testing strategy for this PR?
Review the last four commits one by one: a mechanical rename, the tests with the plans without pruning, the pruning, and the
ProjectionExecthat stays if nothing absorbs it. No expectation that exists onmainchanges.CoalescePartitionsExecover a scan, and the case from fix: prune unused inputs beneath computed repartition projections #27777.get_fieldmust stay above the repartition.mainand on this PR. The results agree wherevermainplans the query. None newly fails to plan. Before the fix, 428 did.CoalescePartitionsExecwhose input absorbs nothing, and a hash repartition.Are there any user-facing changes?
No public API changes.
EXPLAINcan show fewer columns in a scan.🤖 Generated with Claude Code