Skip to content

Conversation

@Jefffrey
Copy link
Contributor

@Jefffrey Jefffrey commented Jan 8, 2023

Which issue does this PR close?

Closes #4667

Rationale for this change

During PushDownProjection optimization, it does not properly account for distinct, as it will attempt to push directly through the distinct, from input plan:

Projection: data.id
  Distinct:
    Projection: data.id, data.data
      TableScan: data

Will generate output plan:

Projection: data.id
  Distinct:
    TableScan: data projection=[id]

Where it has inadvertently removed the data.data projection during the push down and hence leading to incorrect distinct behaviour.

What changes are included in this PR?

Properly handle distincts during recursion in PushDownProjection, to 'restart' the traversal with all required columns (derived from schema of the distinct) rather than using the input required columns.

After fix, the above plan output will instead be:

Projection: data.id
  Distinct:
    TableScan: data projection=[id, data]

Are these changes tested?

New unit test in push_down_projection

Are there any user-facing changes?

@github-actions github-actions bot added the optimizer Optimizer rules label Jan 8, 2023
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- thank you @Jefffrey

)?;
from_plan(plan, &plan.expressions(), &[child])
}
// at a distinct, all columns are required
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

let table_scan = test_table_scan()?;

let plan = LogicalPlanBuilder::from(table_scan)
.project(vec![col("a"), col("b")])?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@alamb
Copy link
Contributor

alamb commented Jan 8, 2023

cc @jackwener

Copy link
Member

@jackwener jackwener left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense to me, thanks @Jefffrey

@alamb alamb merged commit c4f4dff into apache:master Jan 9, 2023
@ursabot
Copy link

ursabot commented Jan 9, 2023

Benchmark runs are scheduled for baseline = ceff6cb and contender = c4f4dff. c4f4dff is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SELECT ... FROM (tbl1 UNION tbl2) wrongly works like SELECT DISTINCT ... FROM (tbl1 UNION tbl2)

4 participants