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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ForeignKeyContext.java:
##########
@@ -142,21 +143,27 @@ public boolean isForeignKey(Set<Slot> key) {
     }
 
     public boolean isPrimaryKey(Set<Slot> key) {
-        return primaryKeys.containsAll(
-                key.stream().map(s -> 
slotToColumn.get(s)).collect(Collectors.toSet()));
+        return !key.isEmpty() && activePrimaryKeySlots.containsAll(key);
     }
 
     void putSlot(SlotReference slot, TableIf table) {
         if (!slot.getOriginalColumn().isPresent()) {
             return;
         }
         Column c = slot.getOriginalColumn().get();
-        slotToColumn.put(slot, new QualifiedColumn(table, c));
+        QualifiedColumn qualifiedColumn = new QualifiedColumn(table, c);
+        slotToColumn.put(slot, qualifiedColumn);
+        if (declaredPrimaryKeys.contains(qualifiedColumn)) {
+            activePrimaryKeySlots.add(slot);

Review Comment:
   [P1] Validate scan semantics before activating PK slots
   
   This treats every catalog scan as both complete and unique, but two 
independent reachable cases violate those assumptions. First, `PARTITION`, 
`TABLET`, `TABLESAMPLE`, and filtered direct-index restrictions live on 
`LogicalOlapScan` rather than in a `LogicalFilter`; for a self-FK table with 
rows `(1,1),(2,2)`, selecting a primary partition containing only `id=1` makes 
the join return `1`, while eliminating that branch returns `1,2`. Second, 
raw-version modes (`skip_delete_bitmap`, `skip_storage_engine_merge`, 
`read_mor_as_dup_tables`) and a bare `@incr` MIN_DELTA scan can expose 
duplicate versions of a declared key, so the join can emit one retained foreign 
row twice while elimination emits it once. `LogicalOlapScan.computeUnique` 
already suppresses uniqueness for those modes, but this direct constraint 
activation bypasses that trait. Please activate PK slots only when the concrete 
scan covers the full base relation and preserves declared-key uniqueness, and 
add subset plus duplic
 ate-version regressions.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ForeignKeyContext.java:
##########
@@ -142,21 +143,27 @@ public boolean isForeignKey(Set<Slot> key) {
     }
 
     public boolean isPrimaryKey(Set<Slot> key) {
-        return primaryKeys.containsAll(
-                key.stream().map(s -> 
slotToColumn.get(s)).collect(Collectors.toSet()));
+        return !key.isEmpty() && activePrimaryKeySlots.containsAll(key);
     }
 
     void putSlot(SlotReference slot, TableIf table) {
         if (!slot.getOriginalColumn().isPresent()) {
             return;
         }
         Column c = slot.getOriginalColumn().get();
-        slotToColumn.put(slot, new QualifiedColumn(table, c));
+        QualifiedColumn qualifiedColumn = new QualifiedColumn(table, c);
+        slotToColumn.put(slot, qualifiedColumn);
+        if (declaredPrimaryKeys.contains(qualifiedColumn)) {
+            activePrimaryKeySlots.add(slot);
+        }
     }
 
     void putAlias(Slot newSlot, Slot originSlot) {
         if (slotToColumn.containsKey(originSlot)) {
             slotToColumn.put(newSlot, slotToColumn.get(originSlot));
+            if (activePrimaryKeySlots.contains(originSlot)) {
+                activePrimaryKeySlots.add(newSlot);

Review Comment:
   [P1] Preserve predicate state across active aliases
   
   Consider `Project(id#1 AS pk#3) -> Filter(parent_id#2 = 1) -> 
Scan(self_ref)` joined to another `self_ref` scan on `pk#3 = f.parent_id#5`. 
`addFilter` records the non-key restriction under `id#1`, while this branch 
activates `pk#3` without creating a `slotWithPredicates` entry. Since the 
project drops `parent_id#2`, predicate pull-up cannot expose the restriction at 
the join, and `isPredicateCompatible` treats `pk#3` as unfiltered. With rows 
`(1,1),(2,2)`, eliminating the primary branch changes the correct output `1` to 
`1,2`. Please propagate and rewrite the complete origin predicate set through 
every alias hop, or conservatively keep an alias inactive when its predicate 
proof cannot be preserved; add the combined alias-plus-hidden-filter regression.



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