linhongliu-db opened a new pull request, #60412:
URL: https://github.com/apache/spark/pull/60412

   ### What changes were proposed in this pull request?
   
   A cached query (`CACHE TABLE`, `Dataset.cache()`) that calls a 
session-context function such as
   `current_timezone()`, `current_catalog()`, 
`current_schema()`/`current_database()` or
   `current_user()` could be answered from a cache entry created under a 
*different* session context,
   returning that context's values. These functions carry no fields, so they 
canonicalize identically
   in every session and the normalized cache-key plan matches; the optimizer 
binds them
   (`ReplaceCurrentLike`) only after the cache lookup, so the lookup cannot 
tell the contexts apart.
   
   `CacheManager` now records the session values the plan's session-context 
functions read when the
   entry is cached (`sessionContextOf`), and reuses an entry only when the 
looking-up session's values
   match. A new conf 
`spark.sql.legacy.cache.ignoreSessionContextInPlanMatching` (default `false`)
   restores the previous behavior.
   
   ### Why are the changes needed?
   
   A cached query can return another session's time zone, catalog, schema or 
user.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, documented in `docs/sql-migration-guide.md`. A cached query that calls 
a session-context
   function is reused only under a matching session context. Set
   `spark.sql.legacy.cache.ignoreSessionContextInPlanMatching=true` to restore 
the old behavior.
   
   ### How was this patch tested?
   
   New `CachedTableSuite` regression: a `current_timezone()` query cached under 
`UTC` is not reused for
   an `Asia/Tokyo` session (and a gate-on case reproduces the stale reuse). 
Locally `CachedTableSuite`
   (110/110) passes and scalastyle is clean on JDK 21.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Isaac)
   
   This pull request and its description were written by Isaac.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to