924060929 commented on code in PR #70016:
URL: https://github.com/apache/doris/pull/70016#discussion_r4706589428


##########
fe/fe-connector/pom.xml:
##########
@@ -55,7 +55,7 @@ under the License.
           of the latter two means bumping this property as well (and 
fe-extension-spi means bumping
           all five families).
         -->
-        <connector.plugin.api.version>37.0</connector.plugin.api.version>
+        <connector.plugin.api.version>38.0</connector.plugin.api.version>

Review Comment:
   Please update the PR description and release note to match the connector API 
version here. The release note currently tells plugin authors to target `31.0`, 
while this build declares `38.0`.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModel.java:
##########
@@ -221,7 +222,14 @@ public Cost visitPhysicalStorageLayerAggregate(
     @Override
     public Cost visitPhysicalFileScan(PhysicalFileScan physicalFileScan, 
PlanContext context) {
         Statistics statistics = context.getStatisticsWithCheck();
-        return Cost.ofCpu(context.getCostWeight(), statistics.getRowCount() * 
EXTERNAL_TABLE_SCAN_FACTOR);
+        double scanRowCount = statistics.getRowCount();
+        OptionalLong selectedRows = 
ScanRowCountUpperBound.forScan(physicalFileScan);
+        if (selectedRows.isPresent()) {
+            // Partition metadata measures scan work. Keep the table-level 
cardinality and column
+            // statistics together so retained filters do not apply pruning 
selectivity twice.
+            scanRowCount = selectedRows.getAsLong();

Review Comment:
   Could we use the selected partition rows for FileScan CPU only when the 
connector can enforce that selection during file planning? I tested three daily 
DATE partitions (Jan 1–3, 2024) containing 1, 1,000 and 1,000 rows. For `WHERE 
DAYOFWEEK(dt) = 2`, Nereids selected Jan 1 and costed the scan at 5 CPU units 
(one row). Iceberg drops this function predicate during conversion and ignores 
`requiredPartitions`, so the SDK planned all three files, whose record counts 
sum to 2,001. The residual filter still returns the right rows, but the low 
scan cost can favor a plan that reads all three files. Please keep the existing 
scan estimate when file pruning cannot be established, and cover this 
residual-predicate case in the tests.



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/mvcc/PluginDrivenMvccSnapshot.java:
##########
@@ -269,6 +278,24 @@ public boolean isPartitionViewUnavailable() {
         return partitionViewState == PartitionViewState.UNAVAILABLE;
     }
 
+    /** Sum already-loaded partition estimates without materializing a 
deferred view or resolving latest. */
+    public OptionalLong getSelectedPartitionRowCount(Set<String> 
partitionNames) {
+        PluginDrivenMvccSnapshot pin = hasDeferredPartitions() ? 
materializedPartitions : this;
+        if (pin == null || pin.partitionViewState != 
PartitionViewState.MATERIALIZED
+                || pin.partitionType != PartitionType.RANGE) {
+            return OptionalLong.empty();
+        }
+        long rowCount = 0;
+        for (String name : partitionNames) {

Review Comment:
   Could we compute this sum once for an immutable partition selection on its 
pinned snapshot and reuse it across cost calculations? Both FileScan and each 
candidate Exchange reach this loop. In a focused test with 10,000 selected 
partitions, costing one scan, one Gather and one Broadcast visited 30,000 
partition entries for the same selection. On a wide date range, the planner 
pays for the same metadata traversal each time it compares distribution 
alternatives.



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