XieJiann commented on code in PR #35898:
URL: https://github.com/apache/doris/pull/35898#discussion_r1628717517


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java:
##########
@@ -455,4 +457,51 @@ public JSONObject toJson() {
         olapScan.put("Properties", properties);
         return olapScan;
     }
+
+    @Override
+    public void computeUnique(DataTrait.Builder builder) {
+        super.computeUnique(builder);
+        if (this.selectedIndexId != getTable().getBaseIndexId()) {
+            /*
+                computing unique doesn't work for mv, because mv's key may be 
different from base table
+                and the key can be any expression which is difficult to deduce 
if it's unique. for example
+                base table:
+                CREATE TABLE IF NOT EXISTS base(
+                    siteid INT(11) NOT NULL,
+                    citycode SMALLINT(6) NOT NULL,
+                    username VARCHAR(32) NOT NULL,
+                    pv BIGINT(20) SUM NOT NULL DEFAULT '0'
+                )
+                AGGREGATE KEY (siteid,citycode,username)
+                DISTRIBUTED BY HASH(siteid) BUCKETS 5 
properties("replication_num" = "1");
+
+                case1:
+                create mv1:
+                create materialized view mv1 as select siteid, sum(pv) from 
base group by siteid;
+                the base table siteid + citycode + username is unique but the 
mv1's agg key siteid is not unique
+
+                case2:
+                create mv2:
+                create materialized view mv2 as select citycode * citycode, 
siteid, username from base;
+                the mv2's agg key citycode * citycode is not unique
+
+                for simplicity, we disable unique compute for mv
+             */
+            return;
+        }
+        Set<Slot> outputSet = Utils.fastToImmutableSet(getOutputSet());
+        if (getTable().getKeysType().isAggregationFamily()) {
+            ImmutableSet.Builder<Slot> uniqSlots = 
ImmutableSet.builderWithExpectedSize(outputSet.size());
+            for (Slot slot : outputSet) {
+                if (!(slot instanceof SlotReference)) {
+                    continue;
+                }
+                SlotReference slotRef = (SlotReference) slot;
+                if (slotRef.getColumn().isPresent() && 
slotRef.getColumn().get().isKey()) {
+                    uniqSlots.add(slot);
+                }
+            }
+            builder.addUniqueSlot(uniqSlots.build());
+        }
+    }

Review Comment:
   You should add the constraint code here, too



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to