Skip to content

Commit

Permalink
do not check invisible column stats
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Nov 17, 2023
1 parent e29d8cb commit 1670afc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,13 @@ public PlanFragment visitPhysicalOlapScan(PhysicalOlapScan olapScan, PlanTransla
olapScanNode.setCardinality((long) olapScan.getStats().getRowCount());
if (context.getSessionVariable() != null && context.getSessionVariable().forbidUnknownColStats) {
for (int i = 0; i < slots.size(); i++) {
Slot slot = slots.get(i);
SlotReference slot = (SlotReference) slots.get(i);
boolean inVisibleCol = slot.getColumn().isPresent()
&& StatisticConstants.shouldIgnoreCol(olapTable, slot.getColumn().get());
if (olapScan.getStats().findColumnStatistics(slot).isUnKnown()
&& !isComplexDataType(slot.getDataType())
&& !StatisticConstants.isSystemTable(olapTable)) {
&& !StatisticConstants.isSystemTable(olapTable)
&& !inVisibleCol) {
context.addUnknownStatsColumn(olapScanNode, tupleDescriptor.getSlots().get(i).getId());
}
}
Expand Down Expand Up @@ -2117,7 +2120,8 @@ private void updateScanSlotsMaterialization(ScanNode scanNode,
&& !StatisticConstants.isSystemTable(scanNode.getTupleDesc().getTable())) {
for (SlotId slotId : requiredByProjectSlotIdSet) {
if (context.isColumnStatsUnknown(scanNode, slotId)) {
throw new AnalysisException("meet unknown column stats on table " + scanNode);
String colName = scanNode.getTupleDesc().getSlot(slotId.asInt()).getColumn().getName();
throw new AnalysisException("meet unknown column stats: " + colName);
}
}
context.removeScanFromStatsUnknownColumnsMap(scanNode);
Expand Down
46 changes: 46 additions & 0 deletions regression-test/suites/nereids_p0/forbid_unknown_col_stats.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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("forbid_unknown_col_stats") {
String db = context.config.getDbNameByFile(context.file)
sql "use ${db}"
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "set forbid_unknown_col_stats=true;"
sql "drop table if exists region"
sql '''
CREATE TABLE region (
r_regionkey int NOT NULL,
r_name VARCHAR(25) NOT NULL,
r_comment VARCHAR(152)
)ENGINE=OLAP
unique KEY(`r_regionkey`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`r_regionkey`) BUCKETS 1
PROPERTIES (
"replication_num" = "1"
);
'''

test {
sql """select r_regionkey from region; """
exception "java.sql.SQLException: errCode = 2, detailMessage = meet unknown column stats: r_regionkey";
}

sql "alter table region modify column r_regionkey set stats ('ndv'='5', 'num_nulls'='0', 'min_value'='0', 'max_value'='4', 'row_count'='5');"
sql """select r_regionkey from region; """
}

0 comments on commit 1670afc

Please sign in to comment.