Skip to content

[SPARK-43376][SQL][FOLLOWUP] lazy construct subquery to improve reuse subquery - #41454

Closed
ulysses-you wants to merge 5 commits into
apache:masterfrom
ulysses-you:SPARK-43376-2
Closed

[SPARK-43376][SQL][FOLLOWUP] lazy construct subquery to improve reuse subquery#41454
ulysses-you wants to merge 5 commits into
apache:masterfrom
ulysses-you:SPARK-43376-2

Conversation

@ulysses-you

@ulysses-youulysses-you commented Jun 5, 2023

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

#41046 make ReuseAdaptiveSubquery become not idempotent. This pr reverts the change in ReuseAdaptiveSubquery.

To solve the same instance issue when planning and reusing subquery in AQE, this pr makes subqueryMap hold the executed plan in subquery. Then in PlanAdaptiveSubqueries, each logical subquery plan can build their own instance of physical subquery.

Why are the changes needed?

To improve reuse subquery in AQE.

Does this PR introduce any user-facing change?

no

How was this patch tested?

Pass CI

@ulysses-you

Copy link
Copy Markdown
ContributorAuthor

cc @cloud-fan@maryannxue

val subquery = SubqueryExec.createForScalarSubquery(
s"subquery#${exprId.id}", executedPlan)
subqueryMap.put(exprId.id, subquery)
subqueryMap.put(exprId.id, executedPlan)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

seems now all subqueries have the same handling code, can we just match the logical subqueries here and build the map?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

yeas, cleaned up these code

name, broadcastKeyIndex, onlyInBroadcast,
buildPlan, buildKeys, executedPlan)
subqueryMap.put(exprId.id, subquery)
case subquery: SubqueryExpression if !subqueryMap.contains(subquery.exprId.id) =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

to be conservative, how about case subquery @ (_: ScalarSubquery | _: InSubquery | _: DynamicPruningSubquery) => ...

@ulysses-you

Copy link
Copy Markdown
ContributorAuthor

@cloud-fan the failed test seems irrelevant

@cloud-fan

Copy link
Copy Markdown
Contributor

thanks, merging to master!

@ulysses-you
ulysses-you deleted the SPARK-43376-2 branch June 8, 2023 01:35
czxm pushed a commit to czxm/spark that referenced this pull request Jun 12, 2023
… subquery
### What changes were proposed in this pull request?
apache#41046 make `ReuseAdaptiveSubquery` become not idempotent. This pr reverts the change in `ReuseAdaptiveSubquery`.
To solve the same instance issue when planning and reusing subquery in AQE, this pr makes `subqueryMap` hold the executed plan in subquery. Then in `PlanAdaptiveSubqueries`, each logical subquery plan can build their own instance of physical subquery.
### Why are the changes needed?
To improve reuse subquery in AQE.
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
Pass CI
Closesapache#41454 from ulysses-you/SPARK-43376-2.
Authored-by: ulysses-you <ulyssesyou18@gmail.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.

2 participants

@ulysses-you@cloud-fan