dataroaring commented on code in PR #41362:
URL: https://github.com/apache/doris/pull/41362#discussion_r1778655188


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneEmptyPartition.java:
##########
@@ -18,30 +18,59 @@
 package org.apache.doris.nereids.rules.rewrite;
 
 import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Partition;
 import org.apache.doris.nereids.rules.Rule;
 import org.apache.doris.nereids.rules.RuleType;
 import org.apache.doris.nereids.trees.plans.logical.LogicalEmptyRelation;
 import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
 import org.apache.doris.qe.ConnectContext;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
 import java.util.List;
 
 /**
  * Used to prune empty partition.
  */
 public class PruneEmptyPartition extends OneRewriteRuleFactory {
+    public static final Logger LOG = 
LogManager.getLogger(PruneEmptyPartition.class);
 
     @Override
     public Rule build() {
         return logicalOlapScan().thenApply(ctx -> {
             LogicalOlapScan scan = ctx.root;
             OlapTable table = scan.getTable();
             List<Long> ids = 
table.selectNonEmptyPartitionIds(scan.getSelectedPartitionIds());
+            addPartitionsForTxnLoad(scan.getSelectedPartitionIds(), ids, 
table, scan.getSelectedIndexId());
             if (ids.isEmpty()) {
                 return new 
LogicalEmptyRelation(ConnectContext.get().getStatementContext().getNextRelationId(),
                         scan.getOutput());
             }
             return scan.withSelectedPartitionIds(ids);
         }).toRule(RuleType.PRUNE_EMPTY_PARTITION);
     }
+
+    private void addPartitionsForTxnLoad(List<Long> selectedPartitions, 
List<Long> nonEmptyPartitions,
+            OlapTable table, long indexId) {
+        if (!ConnectContext.get().isTxnModel()) {
+            return;
+        }
+        for (Long selectedPartitionId : selectedPartitions) {
+            if (nonEmptyPartitions.contains(selectedPartitionId)) {
+                continue;
+            }
+            Partition partition = table.getPartition(selectedPartitionId);
+            if (partition == null) {
+                continue;
+            }
+            // TODO if partition version is -1 and the operatiob is delete, 
can skip this partition
+            if 
(!ConnectContext.get().getTxnEntry().getPartitionSubTxnIds(table.getId(), 
partition, indexId)
+                    .isEmpty()) {
+                nonEmptyPartitions.add(selectedPartitionId);
+            }
+        }
+        LOG.info("add partition for txn load, table: {}, selected partitions: 
{}, non empty partitions: {}",
+                table.getId(), selectedPartitions, nonEmptyPartitions);
+    }

Review Comment:
   Make sure there is a case to test the logic.



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