github-actions[bot] commented on code in PR #66297:
URL: https://github.com/apache/doris/pull/66297#discussion_r3687655737


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java:
##########
@@ -967,8 +980,74 @@ public Optional<MvccSnapshot> getSnapshot(TableIf tableIf) 
{
         if (!(tableIf instanceof MvccTable)) {
             return Optional.empty();
         }
-        MvccTableInfo mvccTableInfo = new MvccTableInfo(tableIf);
-        return Optional.ofNullable(snapshots.get(mvccTableInfo));
+        MvccTableInfo defaultKey = new MvccTableInfo(tableIf);
+        MvccSnapshot defaultSnapshot = snapshots.get(defaultKey);
+        if (defaultSnapshot != null) {
+            return Optional.of(defaultSnapshot);
+        }
+        MvccSnapshot only = null;
+        for (Map.Entry<MvccTableInfo, MvccSnapshot> entry : 
snapshots.entrySet()) {
+            if (defaultKey.isSameTable(entry.getKey())) {
+                if (only != null) {
+                    return Optional.empty();
+                }
+                only = entry.getValue();
+            }
+        }
+        return Optional.ofNullable(only);
+    }
+
+    public Optional<MvccSnapshot> getSnapshot(TableIf tableIf, 
Optional<TableSnapshot> tableSnapshot,
+            Optional<TableScanParams> scanParams) {
+        if (!(tableIf instanceof MvccTable)) {
+            return Optional.empty();
+        }
+        return Optional.ofNullable(snapshots.get(
+                new MvccTableInfo(tableIf, versionKeyOf(tableSnapshot, 
scanParams))));
+    }
+
+    /**
+     * Return a validated statement projection for metadata consumers without 
relation identity.
+     */
+    public Optional<MvccSnapshot> getSnapshotForTableMetadata(TableIf tableIf) 
{
+        Optional<MvccSnapshot> unambiguous = getSnapshot(tableIf);
+        if (unambiguous.isPresent() || !(tableIf instanceof MvccTable)) {
+            return unambiguous;
+        }
+        // Descriptor serialization has no relation key. Reuse a validated 
statement projection
+        // instead of reopening a neutral handle after multiple OPTIONS 
aliases were bound.
+        return Optional.ofNullable(tableMetadataSnapshots.get(new 
MvccTableInfo(tableIf)));
+    }
+
+    private static String versionKeyOf(Optional<TableSnapshot> tableSnapshot,
+            Optional<TableScanParams> scanParams) {
+        // Limit the backport to relation-scoped OPTIONS: branch-4.1's older 
Iceberg/Paimon
+        // time-travel paths still resolve their handles outside this map, 
while OPTIONS needs an
+        // exact content key shared by analysis and scan planning.
+        if (scanParams != null && scanParams.isPresent() && 
scanParams.get().isOptions()) {
+            TableScanParams params = scanParams.get();
+            StringBuilder key = new StringBuilder("p");
+            appendVersionKeyPart(key, params.getParamType());
+            Map<String, String> sortedParams = new 
TreeMap<>(params.getMapParams());

Review Comment:
   [P1] Keep the latest-snapshot fence common when only planning options 
differ. This key includes the complete raw `OPTIONS` map, so aliases with 
`scan.manifest.parallelism=1` and `=2` get different entries. Since that option 
is neither a startup selector nor metadata-neutral, each entry takes the new 
uncached projection path and calls `latestSnapshot()` independently; a commit 
between the two bindings can therefore pin S and S+1 even though neither alias 
requests a different logical snapshot. The base path used the memoized latest 
cache. Please separate snapshot-selector identity from relation-projection 
identity: pin latest once per table/statement, then build each option-specific 
projection from that ID, and test two differently tuned aliases while latest 
advances. This is distinct from the existing projection-leakage thread—the 
projections must stay isolated, but their latest fence must not.



-- 
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