[SPARK-58389][SQL][FOLLOWUP] Pin DSv2 table instances by state options during analysis - #57799
Open
yyanyy wants to merge 2 commits into
Open
[SPARK-58389][SQL][FOLLOWUP] Pin DSv2 table instances by state options during analysis#57799yyanyy wants to merge 2 commits into
yyanyy wants to merge 2 commits into
Conversation
Add a catalog capability for identifying table-state options and a query-scoped table cache keyed by those options. Preserve complete option matching for finalized relations and shared CACHE TABLE reuse while pinning one concrete Table per state within an analysis context.
yyanyy
force-pushed
the
yan-yan_data/spark-dsv2-table-state-cache-20260804
branch
4 times, most recently
from
August 6, 2026 02:03
fe24fdc to
e2cf3a0
Compare
yyanyy
commented
Aug 6, 2026
| getOrLoadRelation(ref) | ||
| val useSharedRelationCache = | ||
| ref.context.isInstanceOf[V2TableReference.TemporaryViewContext] | ||
| getOrLoadRelation(ref, useSharedRelationCache) |
Contributor
Author
There was a problem hiding this comment.
The other case here for now is TransactionContext that shouldn't use shared relation cache to avoid replacing the table earlier than the appropriate transaction check to decide if a cache reuse is safe (txn.registerScans?)
yyanyy
force-pushed
the
yan-yan_data/spark-dsv2-table-state-cache-20260804
branch
from
August 6, 2026 03:41
e2cf3a0 to
b42dda9
Compare
yyanyy
marked this pull request as ready for review
August 6, 2026 03:51
uros-b
reviewed
Aug 6, 2026
uros-b
left a comment
Member
There was a problem hiding this comment.
@szehon-ho Could you PTAL at these changes?
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changes were proposed in this pull request?
SPARK-58389 changed DSv2 relation caching to include all read options. This is required
to preserve each reference's complete option bag, but it also means references that differ
only in scan-specific options can independently call
loadTableand receive differentconcrete table versions within one query.
This PR separates relation reuse from table-state pinning:
relationCacheremains keyed by all read options and reuses a finalized relationonly when the complete option bags match.
tableCacheis keyed by catalog, identifier, time travel, and table-stateoptions. References with the same table-state key reuse one concrete
Table, while retainingtheir own complete options in their relations.
sharedRelationCacheand CacheManager reuse continue to require complete option matching.This PR adds the evolving
SupportsTableStateOptionscatalog capability so a catalog can declarewhich raw options may affect the table state selected by
loadTable, such as a branch, tag,snapshot, or version. Catalogs that do not implement the capability are handled conservatively:
all raw options are considered table-state-affecting.
While applying the same table-pinning model to cacheable
V2TableReferenceresolution, this PRalso fixes two existing gaps in
getOrLoadRelation:loadTable(identifier)without passing the options captured in the tablereference. A table-cache miss now uses the options-aware catalog API with the reference's
complete option bag.
sharedRelationCache. Temporary-view re-resolution now consultssharedRelationCachewhile establishing the initial table pin, allowing it to preserve aTablealready pinned through CacheManager.Transaction references still use the
Tableloaded through the transaction catalog and do notconsult
sharedRelationCache. Write targets remain non-cacheable and bypass the query-scoped readcaches.
The resulting resolution flow is:
relationCacheusing the full-option relation key.tableCacheusing the table-state key.tableCachehit, construct a relation from the pinnedTableand the current reference'scomplete options. Do not call
loadTableor consultsharedRelationCache.tableCachemiss, load the currentTablethrough the applicable options-aware path.sharedRelationCachelookup applies, reuse its relation only when table identity and alloptions match. The shared cached
Tableestablishes the initial pin on a match; otherwise, thenewly loaded
Tableestablishes it.TableintableCacheand the finalized relation inrelationCache.Execution-time table refresh uses the same table-state option projection to preserve this
first-resolution-wins behavior.
Why are the changes needed?
A catalog may accept both table-state options and scan-specific options. Using the complete option
bag for relation reuse is necessary, but using it as the only level of caching can cause references
in the same table-state domain to load different concrete table versions during one query.
The new
tableCachepins one concreteTableper state key without weakening full-option matchingfor finalized relations,
sharedRelationCache, or CacheManager.Forwarding options from
V2TableReferenceis also necessary because those options may select thetable state being reloaded. Temporary views additionally need the
sharedRelationCachebridge topreserve a CacheManager-pinned
Table.Different state domains, including different parsed time-travel specifications, continue to
resolve and pin independently.
Does this PR introduce any user-facing change?
Yes, for catalog implementors only.
This adds the evolving
SupportsTableStateOptionscatalog capability. There is no new SQL syntaxor configuration, and catalogs that do not implement it retain the conservative behavior where all
raw options are considered table-state-affecting.
The table-consistency fix otherwise addresses behavior introduced on the unreleased master branch
by SPARK-58389.
How was this patch tested?
Added regression coverage for table-state projection and pinning, conservative fallback,
sharedRelationCacheand CacheManager matching, nested analysis, execution refresh, andtemporary-view, transaction, and write-target
V2TableReferencebehavior.Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex