-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-29947][SQL] Improve ResolveRelations performance #26589
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
Closed
+9
−3
Closed
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3379cf3
Improve ResolveTables and ResolveRelations performance
wangyum a7ce2a7
Merge remote-tracking branch 'upstream/master' into SPARK-29947
wangyum 84967f5
Merge remote-tracking branch 'upstream/master' into SPARK-29947
wangyum 100ea1a
Merge remote-tracking branch 'upstream/master' into SPARK-29947
wangyum 07e6b7f
Add map to AnalysisContext
wangyum 77b739a
Fix test error
wangyum 2e1f87d
Change relationCache key from UnresolvedRelation to String
wangyum e88351a
Merge remote-tracking branch 'upstream/master' into SPARK-29947
wangyum 99a8557
Apply the cache in lookupRelation
wangyum 8e7b666
v1Table.v1Table.qualifiedName -> catalog.name +: ident.namespace :+ i…
wangyum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,10 +91,14 @@ object FakeV2SessionCatalog extends TableCatalog { | |
| * current catalog database. | ||
| * @param nestedViewDepth The nested depth in the view resolution, this enables us to limit the | ||
| * depth of nested views. | ||
| * @param relationToLogicalPlanMaps The UnresolvedRelation to LogicalPlan mapping, this can ensure | ||
| * that the table is resolved only once if a table is used | ||
| * multiple times in a query. | ||
| */ | ||
| case class AnalysisContext( | ||
| defaultDatabase: Option[String] = None, | ||
| nestedViewDepth: Int = 0) | ||
| nestedViewDepth: Int = 0, | ||
| relationToLogicalPlanMaps: mutable.Map[UnresolvedRelation, LogicalPlan] = mutable.Map.empty) | ||
|
|
||
| object AnalysisContext { | ||
|
cloud-fan marked this conversation as resolved.
|
||
| private val value = new ThreadLocal[AnalysisContext]() { | ||
|
|
@@ -861,7 +865,13 @@ class Analyzer( | |
| case other => i.copy(table = other) | ||
| } | ||
|
|
||
| case u: UnresolvedRelation => resolveRelation(u) | ||
| case u: UnresolvedRelation => | ||
| val relationToLogicalPlanMaps = AnalysisContext.get.relationToLogicalPlanMaps | ||
| relationToLogicalPlanMaps.getOrElse(u, { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's safer to use the qualified table name as the key, i.e. after calling |
||
| val relation = resolveRelation(u) | ||
| relationToLogicalPlanMaps.update(u, relation) | ||
| relation | ||
| }) | ||
| } | ||
|
|
||
| // Look up a relation from the given session catalog with the following logic: | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: how about just
relationCache?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and it's simpler to use
Seq[String]as key.