Skip to content

[SPARK-58767][SQL] Fixing the canonicalization of TableCacheQueryStageExec which otherwise prevents re-use of exchange for in memory cached plans - #58003

Open
ahshahid wants to merge 7 commits into
apache:masterfrom
ahshahid:SPARK-58767
Open

ahshahid wants to merge 7 commits into
apache:masterfrom
ahshahid:SPARK-58767

Conversation

@ahshahid

Copy link
Copy Markdown
Contributor

… which otherwise prevents re-use of exchange for in memory cached plans

What changes were proposed in this pull request?

The canonicalization of TableCacheQueryStageExec uses the default, instead of the original InMemoryTableScanExec, as result two TableCacheQueryStageExec which hold canonically same InMemoryTableScanExec , do not match

Why are the changes needed?

Affects performance as it prevents re-use of exchange.

Does this PR introduce any user-facing change?

No

How was this patch tested?

added bug test. will add some more tests.

Was this patch authored or co-authored using generative AI tooling?

No

… which otherwise prevents re-use of exchange for in memory cached plans
@ahshahid ahshahid changed the title [WIP][SQL] [SPARK-58767][SQL]. Fixing the canonicalization of TableCacheQueryStageExec,… [SPARK-58767][SQL]. Fixing the canonicalization of TableCacheQueryStageExec,… Aug 14, 2026
@ahshahid
ahshahid marked this pull request as draft August 14, 2026 23:33
@ahshahid
ahshahid marked this pull request as ready for review August 15, 2026 00:41

@ulysses-you ulysses-you left a comment

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.

thank you @ahshahid , this fix looks correct to me, some comments.

}
}

override def doCanonicalize(): SparkPlan = _canonicalized

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.

can we move the following code from ExchangeQueryStageExec to QueryStageExec ?

val _canonicalized: SparkPlan

override def doCanonicalize(): SparkPlan = _canonicalized

@ahshahid ahshahid Aug 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.. this required handling in ResultQueryStageExec too.. I have done the change , but test for ResultQueryStageExec not there.. Not sure if the canonicalized plan would ever be used in that class, as per my understanding , it represents a final evaluated stage.

@ahshahid

ahshahid commented Aug 26, 2026 via email

Copy link
Copy Markdown
Contributor Author

@ahshahid
ahshahid marked this pull request as draft August 27, 2026 19:14
@ahshahid
ahshahid marked this pull request as ready for review August 27, 2026 23:29
@ulysses-you ulysses-you changed the title [SPARK-58767][SQL]. Fixing the canonicalization of TableCacheQueryStageExec,… [SPARK-58767][SQL] Fixing the canonicalization of TableCacheQueryStageExec which otherwise prevents re-use of exchange for in memory cached plans Aug 28, 2026
postStageCreationRules(supportsColumnar),
"AQE Post Stage Creation")
val resultStage = ResultQueryStageExec(currentStageId, optimizedRootPlan, resultHandler)
val resultStage = ResultQueryStageExec(currentStageId, optimizedRootPlan, plan.canonicalized,

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.

For ResultQueryStageExec, we should not make canonicalized change , the semantics of ResultQueryStageExec is plan + resultHandler.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ResultQueryStageExec extends QueryStageExec. So if the abstract fields of _canonicalize is moved to QueryStageExec, what do you have in mind to override it in ResultQueryStageExec?

override def doCanonicalize(): SparkPlan = {
ResultQueryStageExec(-1, _canonicalized, _canonicalized, resultHandler)
}
?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ulysses-you ..I suppose the overriding doCanonicalize in ResultQueryStageExec as in the PR , should work as right canonicalized code. From what I understand of what you implied of "plan + resultHandler", looks like ResultQueryStageExec , also had an issue, which should be addressed by this PR...
Pls lmk your thoughts.

@ahshahid

ahshahid commented Aug 28, 2026 via email

Copy link
Copy Markdown
Contributor Author

@ahshahid
ahshahid marked this pull request as draft August 28, 2026 09:04
@ahshahid
ahshahid marked this pull request as ready for review August 28, 2026 15:51

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants