From fe2f547dabc1264e50cdd3db725f6737e45790d8 Mon Sep 17 00:00:00 2001 From: minghong Date: Thu, 17 Oct 2024 16:58:19 +0800 Subject: [PATCH] pick --- .../doris/nereids/stats/StatsCalculator.java | 10 +--- .../nereids_p0/delta_row/delta_row.groovy | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 regression-test/suites/nereids_p0/delta_row/delta_row.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java index 8c597b75137413..1a983532a94dac 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java @@ -834,14 +834,6 @@ private Statistics computeCatalogRelation(CatalogRelation catalogRelation) { hasUnknownCol = true; } if (ConnectContext.get() != null && ConnectContext.get().getSessionVariable().enableStats) { - if (deltaRowCount > 0) { - // clear min-max to avoid error estimation - // for example, after yesterday data loaded, user send query about yesterday immediately. - // since yesterday data are not analyzed, the max date is before yesterday, and hence optimizer - // estimates the filter result is zero - colStatsBuilder.setMinExpr(null).setMinValue(Double.NEGATIVE_INFINITY) - .setMaxExpr(null).setMaxValue(Double.POSITIVE_INFINITY); - } columnStatisticBuilderMap.put(slotReference, colStatsBuilder); } else { columnStatisticBuilderMap.put(slotReference, new ColumnStatisticBuilder(ColumnStatistic.UNKNOWN)); @@ -862,7 +854,7 @@ private Statistics normalizeCatalogRelationColumnStatsRowCount(double rowCount, columnStatisticMap.put(slot, columnStatisticBuilderMap.get(slot).setCount(rowCount).build()); } - return new Statistics(rowCount, columnStatisticMap); + return new Statistics(rowCount, 1, columnStatisticMap, deltaRowCount); } private Statistics computeTopN(TopN topN) { diff --git a/regression-test/suites/nereids_p0/delta_row/delta_row.groovy b/regression-test/suites/nereids_p0/delta_row/delta_row.groovy new file mode 100644 index 00000000000000..c6f40f5363f453 --- /dev/null +++ b/regression-test/suites/nereids_p0/delta_row/delta_row.groovy @@ -0,0 +1,55 @@ +// 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("delta_row") { + String database = context.config.getDbNameByFile(context.file) + sql """ + drop database if exists ${database}; + create database ${database}; + use ${database}; + CREATE TABLE IF NOT EXISTS t ( + k int(11) null comment "", + v string replace null comment "", + ) engine=olap + DISTRIBUTED BY HASH(k) BUCKETS 5 properties("replication_num" = "1"); + + insert into t values (1, "a"),(2, "b"),(3, 'c'),(4,'d'); + analyze table t with sync; + """ + explain { + sql "physical plan select * from t where k > 6" + contains("stats=0,") + contains("stats=4 ") + // PhysicalResultSink[75] ( outputExprs=[k#0, v#1] ) + // +--PhysicalFilter[72]@1 ( stats=0, predicates=(k#0 > 6) ) + // +--PhysicalOlapScan[t]@0 ( stats=4 ) + } + + sql "set global enable_auto_analyze=false;" + + sql "insert into t values (10, 'c');" + explain { + sql "physical plan select * from t where k > 6" + contains("stats=0.5,") + contains("stats=5(1)") + notContains("stats=0,") + notContains("stats=4 ") +// PhysicalResultSink[75] ( outputExprs=[k#0, v#1] ) +// +--PhysicalFilter[72]@1 ( stats=0.5, predicates=(k#0 > 6) ) +// +--PhysicalOlapScan[t]@0 ( stats=5(1) ) + } +} \ No newline at end of file