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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java:
##########
@@ -734,6 +744,18 @@ private boolean 
isScanAppendOnlyTableStream(OlapTableStream table) {
 
     private LogicalPlan getLogicalPlan(TableIf table, UnboundRelation 
unboundRelation,
                                        List<String> qualifiedTableName, 
CascadesContext cascadesContext) {
+        if (unboundRelation.isMaxVisiblePartition()) {
+            TableIf.TableType type = table.getType();
+            if (type != TableIf.TableType.OLAP && type != 
TableIf.TableType.MATERIALIZED_VIEW) {
+                throw new AnalysisException("max_visible_partition() is only 
supported on OLAP table "
+                        + "or materialized view, but table " + table.getName() 
+ " is " + type);
+            }
+            if (unboundRelation.getTableSnapshot().isPresent()) {
+                throw new AnalysisException("max_visible_partition() cannot be 
used with FOR VERSION/TIME AS OF");
+            }
+            
cascadesContext.getStatementContext().setHasMaxVisiblePartition(true);

Review Comment:
   [P1] Exclude max-partition queries from the SQL result cache
   
   This flag only blocks prepared short-circuit reuse. In cloud mode the 
selection at `getPartitionIds()` can still use non-expired partition-version 
entries, while `addUsedTable()` later records a separately refreshed table 
version. For example, with a positive partition TTL and table TTL 0, prime an 
empty table, load the higher partition through another FE, then rerun: binding 
still folds from stale partition entries, but `PhysicalEmptyRelation` caches 
that result under the current table version. After the partition TTL expires, 
`tryParseSql()` runs before binding and accepts the cached result because it 
validates only the unchanged table version, so the new rows stay hidden until 
another write or cache eviction. The existing cloud thread covers the selection 
snapshot itself, not persisting it beyond its TTL. Please mark SQL cache 
unsupported for this modifier, or cache and revalidate the exact 
partition-version snapshot used for selection.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java:
##########
@@ -302,6 +309,9 @@ private LogicalPlan makeOlapScan(TableIf table, 
UnboundRelation unboundRelation,
             // This tabletIds is set manually, so need to set 
specifiedTabletIds
             scan = scan.withManuallySpecifiedTabletIds(tabletIds);
         }
+        if (unboundRelation.isMaxVisiblePartition() && 
CollectionUtils.isEmpty(partIds)) {
+            return new LogicalEmptyRelation(unboundRelation.getRelationId(), 
scan.getOutput());

Review Comment:
   [P1] Preserve the catalog relation until privilege checks run
   
   This branch runs before `CHECK_PRIVILEGES` and removes the only 
`LogicalCatalogRelation`. A user without `SELECT` can prepare/execute `SELECT * 
FROM secret max_visible_partition()` while `secret` is empty; that execution 
performs no `UserAuthentication.checkPermission()` but still sets the reused 
`StatementContext.privChecked` flag. After another user loads a partition, the 
next EXECUTE rebinds to that partition, yet `CheckPrivileges` returns 
immediately on the stale flag and the restricted user can read the rows. The 
existing empty-return thread covers modifier validation/output shape, not this 
authorization loss. Please preserve/check table authorization before erasing 
the scan (and add an empty-to-populated prepared-statement RBAC regression), or 
defer empty folding until after privilege checking.



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