Skip to content

[SPARK-36183][SQL] Push down limit 1 through Aggregate if it is group only - #33397

Closed
wangyum wants to merge 4 commits into
apache:masterfrom
wangyum:SPARK-36183
Closed

[SPARK-36183][SQL] Push down limit 1 through Aggregate if it is group only#33397
wangyum wants to merge 4 commits into
apache:masterfrom
wangyum:SPARK-36183

Conversation

@wangyum

@wangyumwangyum commented Jul 16, 2021

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

Push down limit 1 and turn Aggregate into Project through Aggregate if it is group only. For example:

createtablet1 using parquet asselect id from range(100000000L);
createtablet2 using parquet asselect id from range(100000000L);
createviewv1asselect*from t1 unionselect*from t2;
select*from v1 limit1;
Before this PRAfter this PR
imageimage

Why are the changes needed?

Improve query performance. This is a real case from the cluster:
image

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Unit test.

@SparkQA

Copy link
Copy Markdown

Kubernetes integration test unable to build dist.

exiting with code: 1
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45676/

@SparkQA

Copy link
Copy Markdown

Test build #141165 has finished for PR 33397 at commit 11c266b.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@wangyum
wangyum requested a review from cloud-fanJuly 19, 2021 01:12
@SparkQA

Copy link
Copy Markdown

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45772/

@SparkQA

Copy link
Copy Markdown

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45772/

@SparkQA

Copy link
Copy Markdown

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45780/

@SparkQA

Copy link
Copy Markdown

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45780/

@SparkQA

Copy link
Copy Markdown

Test build #141258 has finished for PR 33397 at commit c630a63.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA

Copy link
Copy Markdown

Test build #141266 has finished for PR 33397 at commit ec3df29.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

…mizer/Optimizer.scala
Co-authored-by: Wenchen Fan <cloud0fan@gmail.com>
@SparkQA

Copy link
Copy Markdown

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45825/

@SparkQA

Copy link
Copy Markdown

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45825/

@wangyum

Copy link
Copy Markdown
MemberAuthor

Merged to master.

@wangyum
wangyum deleted the SPARK-36183 branch July 20, 2021 12:25
@SparkQA

Copy link
Copy Markdown

Test build #141311 has finished for PR 33397 at commit 1d60d64.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@wangyum

Copy link
Copy Markdown
MemberAuthor

The benchmark result:

Before this PRAfter this PR
imageimage

cloud-fan added a commit that referenced this pull request Dec 12, 2023
…oject
### What changes were proposed in this pull request?
This is a follow-up of #33397 to avoid sub-optimal plans. After converting `Aggregate` to `Project`, there is information lost: `Aggregate` doesn't care about the data order of inputs, but `Project` cares. `EliminateSorts` can remove `Sort` below `Aggregate`, but it doesn't work anymore if we convert `Aggregate` to `Project`.
This PR fixes this issue by tagging the `Project` to be order-irrelevant if it's converted from `Aggregate`. Then `EliminateSorts` optimizes the tagged `Project`.
### Why are the changes needed?
avoid sub-optimal plans
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
new test
### Was this patch authored or co-authored using generative AI tooling?
No
Closes#44310 from cloud-fan/sort.
Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
szehon-ho pushed a commit to szehon-ho/spark that referenced this pull request Feb 7, 2024
…oject
### What changes were proposed in this pull request?
This is a follow-up of apache#33397 to avoid sub-optimal plans. After converting `Aggregate` to `Project`, there is information lost: `Aggregate` doesn't care about the data order of inputs, but `Project` cares. `EliminateSorts` can remove `Sort` below `Aggregate`, but it doesn't work anymore if we convert `Aggregate` to `Project`.
This PR fixes this issue by tagging the `Project` to be order-irrelevant if it's converted from `Aggregate`. Then `EliminateSorts` optimizes the tagged `Project`.
### Why are the changes needed?
avoid sub-optimal plans
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
new test
### Was this patch authored or co-authored using generative AI tooling?
No
Closesapache#44310 from cloud-fan/sort.
Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@wangyum@SparkQA@cloud-fan