Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-31206][SQL] AQE should not use the same SubqueryExec when reuse is off #27971

Closed

Conversation

Ngone51
Copy link
Member

@Ngone51 Ngone51 commented Mar 20, 2020

What changes were proposed in this pull request?

Make it always compile a Subquery(even with the same exprId) in InsertAdaptiveSparkPlan. buildSubqueryMap when reuse subquery is off.

Why are the changes needed?

Currently, in InsertAdaptiveSparkPlan. buildSubqueryMap, it will skip compiling a subquery when it has same exprId with a compiled subquery. And this leads to use the same SubqueryExec for the SubqueryExpression with the same exprId. Thus, the behavior here is not consistent compare to PlanSubqueries without AQE.

Here's an example for the issue(please note the difference of subquery plan #id):

spark.sql("set spark.sql.adaptive.enabled=true")
spark.sql("set spark.sql.execution.reuseSubquery=false")
spark.sql( "select b as b1, b as b2 from (select a, (select b from t2 where b = 51) b from t1)").queryExecution.executedPlan

/** Before **/
AdaptiveSparkPlan(isFinalPlan=false)
+- Project [Subquery subquery34, [id=#57] AS b1#36L, Subquery subquery34, [id=#57] AS b2#37L]
   :  :- Subquery subquery34, [id=#57]
   :  :  +- AdaptiveSparkPlan(isFinalPlan=false)
   :  :     +- Project [id#4L AS b#6L]
   :  :        +- Filter (id#4L = 51)
   :  :           +- Range (0, 10, step=1, splits=16)
   :  +- Subquery subquery34, [id=#57]
   :     +- AdaptiveSparkPlan(isFinalPlan=false)
   :        +- Project [id#4L AS b#6L]
   :           +- Filter (id#4L = 51)
   :              +- Range (0, 10, step=1, splits=16)
   +- Range (0, 10, step=1, splits=16)

/** After **/
AdaptiveSparkPlan(isFinalPlan=false)
+- Project [Subquery subquery28, [id=#28] AS b1#30L, Subquery subquery28, [id=#38] AS b2#31L]
   :  :- Subquery subquery28, [id=#28]
   :  :  +- AdaptiveSparkPlan(isFinalPlan=false)
   :  :     +- Project [id#20L AS b#22L]
   :  :        +- Filter (id#20L = 51)
   :  :           +- Range (0, 10, step=1, splits=16)
   :  +- Subquery subquery28, [id=#38]
   :     +- AdaptiveSparkPlan(isFinalPlan=false)
   :        +- Project [id#20L AS b#22L]
   :           +- Filter (id#20L = 51)
   :              +- Range (0, 10, step=1, splits=16)
   +- Range (0, 10, step=1, splits=16)

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Added a test.

@Ngone51
Copy link
Member Author

Ngone51 commented Mar 20, 2020

ping @cloud-fan @maryannxue @JkSelf Please take a look!

val executedPlan = compileSubquery(query)
verifyAdaptivePlan(executedPlan, query)
val subquery = SubqueryExec(s"subquery#${exprId.id}", executedPlan)
subqueryMap.put(exprId.id, subquery)
val subqueries = subqueryMap.getOrElseUpdate(exprId.id, mutable.Queue())
Copy link
Contributor

Choose a reason for hiding this comment

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

Not that I think it actually matters... but just for the argument itself, how can we guarantee it's the same de-queue order?
It's just some sort of waste to add duplicates for the mere sake of consistency...

@maryannxue
Copy link
Contributor

Strictly speaking it's not reuse. It's the same subquery expression.
Let's fix the non-aqe subquery planning to avoid compiling the same subquery expression twice.

@SparkQA
Copy link

SparkQA commented Mar 20, 2020

Test build #120103 has finished for PR 27971 at commit 294b62a.

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

@github-actions
Copy link

We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!

@github-actions github-actions bot added the Stale label Jun 29, 2020
@github-actions github-actions bot closed this Jun 30, 2020
Sign up for free to 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