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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java:
##########
@@ -990,6 +994,34 @@ && getTable().isMorTable()
             }
             builder.addUniqueSlot(uniqSlots.build());
         }
+        // Add unique slots from primary key constraints
+        addUniqueFromPk(builder);
+    }
+
+    private void addUniqueFromPk(DataTrait.Builder builder) {
+        TableIf table = getTable();
+        if (!(table instanceof Table)) {
+            return;
+        }
+        Table t = (Table) table;
+        ImmutableList<PrimaryKeyConstraint> pks = 
Env.getCurrentEnv().getConstraintManager()
+                .getPrimaryKeyConstraints(new 
TableNameInfo(t.getQualifiedDbName(), t.getName()));

Review Comment:
   This lookup can throw before it ever checks whether the table has PK 
constraints. `Table.qualifiedDbName` is nullable, and several in-memory planner 
tests build `LogicalOlapScan`s through 
`PlanConstructor.newOlapTable/newLogicalOlapScan` without calling 
`setQualifiedDbName`; as soon as one of those plans asks for 
`getLogicalProperties().getTrait()`, `computeUnique()` reaches this added `new 
TableNameInfo(t.getQualifiedDbName(), t.getName())`, whose two-argument 
constructor requires a non-null db. The superclass constraint path already 
handles this with `TableNameInfoUtils.fromTableOrNull(table)` and returns when 
metadata is unavailable, so please reuse that path/helper or remove this 
duplicate helper.



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