BiteTheDDDDt commented on code in PR #64413:
URL: https://github.com/apache/doris/pull/64413#discussion_r3491457017


##########
fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java:
##########
@@ -187,6 +187,7 @@ public class OlapScanNode extends ScanNode {
 
     private SortInfo sortInfo = null;
     private Set<Integer> outputColumnUniqueIds = new HashSet<>();
+    private Set<Integer> extraKeyColumnSlotIds = new HashSet<>();

Review Comment:
   已补到 explain 里,输出为 `EXTRA KEY COLUMNS: ...`;同时在 
`PhysicalPlanTranslatorTest#testOlapPrune` 里增加了 explain 断言。



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java:
##########
@@ -2870,6 +2971,15 @@ public PlanFragment 
visitPhysicalLazyMaterializeOlapScan(PhysicalLazyMaterialize
 
         translateRuntimeFilter(lazyScan, olapScanNode, context);
 
+        if (!olapScanNode.getExtraKeyColumnSlotIds().isEmpty()) {
+            List<Expr> projectionExprs = lazyScan.getOutput().stream()
+                    .map(slot -> context.findSlotRef(slot.getExprId()))
+                    .collect(Collectors.toList());
+            TupleDescriptor projectionTuple = 
generateTupleDesc(lazyScan.getOutput(), lazyScan.getTable(), context);
+            olapScanNode.setProjectList(projectionExprs);
+            olapScanNode.setOutputTupleDesc(projectionTuple);

Review Comment:
   这里我保留了 projection,并把普通 scan 的 storage-aligned projection 删掉了。lazy scan 
这里不一样:extra key slot 需要继续留在 `OlapScanNode` 的 tuple 里保证存储 key 语义,但 
`lazyScan.getOutput()` 不能把这些 storage-only slot 暴露给父节点;不设置 
`projectList/outputTupleDesc` 时父节点会看到额外列。所以这里保留 projection,并补了注释。



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java:
##########
@@ -2851,14 +2951,15 @@ public PlanFragment 
visitPhysicalLazyMaterializeTVFScan(PhysicalLazyMaterializeT
     @Override
     public PlanFragment 
visitPhysicalLazyMaterializeOlapScan(PhysicalLazyMaterializeOlapScan lazyScan,
             PlanTranslatorContext context) {
-        PlanFragment planFragment = 
computePhysicalOlapScan(lazyScan.getScan(), context);
+        PlanFragment planFragment = 
computePhysicalOlapScan(lazyScan.getScan(), context, false);
         OlapScanNode olapScanNode = (OlapScanNode) planFragment.getPlanRoot();
         // set lazy materialized context
         olapScanNode.setIsTopnLazyMaterialize(true);
         
olapScanNode.setGlobalRowIdColumn(lazyScan.getRowId().getOriginalColumn().get());
         Set<SlotId> scanIds = 
lazyScan.getOutput().stream().map(NamedExpression::getExprId)
                 
.map(context::findSlotRef).filter(Objects::nonNull).map(SlotRef::getSlotId)
                 .collect(Collectors.toSet());
+        preserveExtraStorageKeySlots(olapScanNode, scanIds);
 
         olapScanNode.getTupleDesc().getSlots().removeIf(slot -> 
!scanIds.contains(slot.getId()));

Review Comment:
   这里的 id 是 `OlapScanNode` tuple desc 里的 `SlotDescriptor` id,不要求还存在于 
`lazyScan.getOutput()` 中。`preserveExtraStorageKeySlots` 会把 key prefix 保留在 scan 
tuple 并记录到 `extraKeyColumnSlotIds`,后面的 projection 只是把这些 storage-only slot 
从父节点输出中隐藏。`testOlapPrune` 现在也同时断言了 thrift extra key ids 和 explain 输出。



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