-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[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
Closed
Changes from all 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 |
---|---|---|
|
@@ -92,10 +92,14 @@ object FakeV2SessionCatalog extends TableCatalog { | |
* views. | ||
* @param nestedViewDepth The nested depth in the view resolution, this enables us to limit the | ||
* depth of nested views. | ||
* @param relationCache A mapping from qualified table names to resolved relations. This can ensure | ||
* that the table is resolved only once if a table is used multiple times | ||
* in a query. | ||
*/ | ||
case class AnalysisContext( | ||
catalogAndNamespace: Seq[String] = Nil, | ||
nestedViewDepth: Int = 0) | ||
nestedViewDepth: Int = 0, | ||
relationCache: mutable.Map[Seq[String], LogicalPlan] = mutable.Map.empty) | ||
|
||
object AnalysisContext { | ||
cloud-fan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private val value = new ThreadLocal[AnalysisContext]() { | ||
|
@@ -110,7 +114,7 @@ object AnalysisContext { | |
def withAnalysisContext[A](catalogAndNamespace: Seq[String])(f: => A): A = { | ||
val originContext = value.get() | ||
val context = AnalysisContext( | ||
catalogAndNamespace, nestedViewDepth = originContext.nestedViewDepth + 1) | ||
catalogAndNamespace, originContext.nestedViewDepth + 1, originContext.relationCache) | ||
set(context) | ||
try f finally { set(originContext) } | ||
} | ||
|
@@ -870,7 +874,9 @@ class Analyzer( | |
case SessionCatalogAndIdentifier(catalog, ident) => | ||
CatalogV2Util.loadTable(catalog, ident).map { | ||
case v1Table: V1Table => | ||
v1SessionCatalog.getRelation(v1Table.v1Table) | ||
val key = catalog.name +: ident.namespace :+ ident.name | ||
AnalysisContext.get.relationCache.getOrElseUpdate( | ||
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. This doesn't work. The table is already loaded and it's too late to use the cache. I've sent #27341 to fix it. |
||
key, v1SessionCatalog.getRelation(v1Table.v1Table)) | ||
case table => | ||
DataSourceV2Relation.create(table) | ||
} | ||
|
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.
This is the anti-pattern from the style guide ... https://github.com/databricks/scala-style-guide#case-classes-and-immutability