wangshuo128 commented on code in PR #17853:
URL: https://github.com/apache/doris/pull/17853#discussion_r1138297316


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java:
##########
@@ -302,23 +306,42 @@ public List<Slot> computeOutput() {
 
     @Override
     public List<Slot> computeNonUserVisibleOutput() {
-        // if (getTable().getIndexIdToMeta().size() == 1) {
-        //     return ImmutableList.of();
-        // }
-        Set<String> baseSchemaColNames = table.getBaseSchema().stream()
-                .map(Column::getName)
-                .collect(Collectors.toSet());
-
         OlapTable olapTable = (OlapTable) table;
-        // extra columns in materialized index, such as `mv_bitmap_union_xxx`
         return olapTable.getVisibleIndexIdToMeta().values()
                 .stream()
                 .filter(index -> index.getIndexId() != ((OlapTable) 
table).getBaseIndexId())
-                .flatMap(index -> index.getSchema()
-                        .stream()
-                        .filter(col -> 
!baseSchemaColNames.contains(col.getName()))
-                )
-                .map(col -> SlotReference.fromColumn(col, qualified()))
+                .flatMap(index -> index.getSchema().stream())
+                .map(col -> {
+                    if (mvNameToSlot.containsKey(col.getName())) {
+                        return mvNameToSlot.get(col.getName());
+                    }
+                    Slot slot = SlotReference.fromColumn(col, qualified());
+                    mvNameToSlot.put(col.getName(), slot);
+                    return slot;
+                })
+                .collect(ImmutableList.toImmutableList());
+    }
+
+    /**
+     * Get the slot under the index,
+     * and create a new slotReference for the slot that has not appeared in 
the materialized view.
+     */
+    public List<Slot> getOutputWithIndex(long mvIndex) {
+        if (mvIndex == ((OlapTable) table).getBaseIndexId()) {
+            return getOutput();
+        }
+
+        OlapTable olapTable = (OlapTable) table;
+        return olapTable.getVisibleIndexIdToMeta().get(mvIndex).getSchema()
+                .stream()
+                .map(col -> {
+                    if (mvNameToSlot.containsKey(col.getName())) {
+                        return mvNameToSlot.get(col.getName());
+                    }
+                    Slot slot = SlotReference.fromColumn(col, qualified());
+                    mvNameToSlot.put(col.getName(), slot);
+                    return slot;

Review Comment:
   generateUniqueSlot



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