github-actions[bot] commented on code in PR #62265:
URL: https://github.com/apache/doris/pull/62265#discussion_r3091025868
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java:
##########
@@ -639,7 +630,10 @@ public Statistics computeOlapScan(OlapScan olapScan) {
}
ColumnStatisticBuilder colStatsBuilder = new
ColumnStatisticBuilder(cache,
selectedPartitionsRowCount);
- colStatsBuilder.normalizeAvgSizeByte(slot);
+ colStatsBuilder.normalizeAvgSizeByte(slot.getDataType());
+ //scale null_num
+ double scale = tableRowCount == 0 ? 1 :
selectedPartitionsRowCount / tableRowCount;
+ colStatsBuilder.setNumNulls(colStatsBuilder.getNumNulls() *
scale);
Review Comment:
When `enable_partition_analyze` is on and every selected partition has
cached stats, `getColumnStatistic(..., selectedPartitionNames)` already returns
the merged stats for exactly those partitions. Scaling `numNulls` again by
`selectedPartitionsRowCount / tableRowCount` undercounts nulls by the prune
ratio. For example, selecting two 4-row partitions that each contain one null
produces a merged `numNulls = 2`, but this code changes it to `8 / 12 * 2 =
1.333...`. That regresses scan stats for `IS NULL` filters and downstream
selectivity that depends on null counts. The scaling needs to happen only on
the table-level fallback path, not when merged partition stats are available.
##########
regression-test/suites/statistics/test_scale_num_nulls.groovy:
##########
@@ -0,0 +1,61 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_scale_num_nulls") {
+ // For an OlapTable, when only a subset of partitions is selected,
+ // the num_nulls value in column statistics needs to be scaled
proportionally.
+ sql """
+ drop table if exists ptable;
+ CREATE TABLE `ptable` (
+ `id` int NULL,
+ `val` int NULL,
+ `d` date NULL
+ ) ENGINE=OLAP
+ DUPLICATE KEY(`id`)
+ PARTITION BY RANGE(`d`)
+ (PARTITION p201701 VALUES [('2017-01-01'), ('2017-02-01')),
+ PARTITION p201702 VALUES [('2017-02-01'), ('2017-03-01')),
+ PARTITION p201703 VALUES [('2017-03-01'), ('2017-04-01')))
+ DISTRIBUTED BY HASH(`id`) BUCKETS 16
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1",
+ "min_load_replica_num" = "-1",
+ "is_being_synced" = "false",
+ "storage_medium" = "hdd",
+ "storage_format" = "V2",
+ "inverted_index_storage_format" = "V3",
+ "light_schema_change" = "true",
+ "disable_auto_compaction" = "false",
+ "enable_single_replica_compaction" = "false",
+ "group_commit_interval_ms" = "10000",
+ "group_commit_data_bytes" = "134217728"
+ );
+
+ insert into ptable values
+ (1, null, '2017-01-01'), (11,2, '2017-01-01'), (111,2, '2017-01-01'),
(1111,2, '2017-01-01'),
+ (2, null, '2017-02-01'), (22,2, '2017-02-01'), (222,2, '2017-02-01'),
(2222,2, '2017-02-01'),
+ (3, null, '2017-03-01'), (33,2, '2017-03-01'), (333,2, '2017-03-01'),
(333,2, '2017-03-01');
+
+ analyze table ptable with sync;
+ """
+ def colStats = sql "show column stats ptable";
+ def memo = sql "explain memo plan select * from ptable where
d='2017-01-01'"
+ // check numNulls=1.0000 for column val, which is scaled from 3 to 1
according to the partition pruning result.
+ assertTrue(memo.toString().contains("val#1 -> ndv=1.0000,
min=2.000000(2), max=2.000000(2), count=4.0000, numNulls=1.0000"),
Review Comment:
This regression only covers the default `enable_partition_analyze = false`
path, so it never exercises the merged partition-stats branch that this PR also
changes. With `enable_partition_analyze = true`, the new unconditional scaling
above turns an exact merged `numNulls` into a smaller value. Please add a case
that enables partition analyze (and restores it in `finally`, like
`query_p0/stats/partition_col_stats.groovy`) and verifies the
selected-partition `numNulls` stays exact instead of being rescaled.
--
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]