Skip to content

Commit

Permalink
pick
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Oct 17, 2024
1 parent e9e29a4 commit fe2f547
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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) {
Expand Down
55 changes: 55 additions & 0 deletions regression-test/suites/nereids_p0/delta_row/delta_row.groovy
Original file line number Diff line number Diff line change
@@ -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) )
}
}

0 comments on commit fe2f547

Please sign in to comment.