From 1fb424950de6d3e81ea3859c94bf0305595dbc26 Mon Sep 17 00:00:00 2001 From: minghong Date: Mon, 14 Oct 2024 15:54:49 +0800 Subject: [PATCH] if ndv is invalid, disable join reorder --- .../doris/nereids/stats/StatsCalculator.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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 3c70d4cd51868fe..633d0cc8542b0dc 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 @@ -219,7 +219,9 @@ public static void disableJoinReorderIfTableRowCountNotAvailable( StatsCalculator calculator = new StatsCalculator(context); for (LogicalOlapScan scan : scans) { double rowCount = calculator.getOlapTableRowCount(scan); - if (rowCount == -1 && ConnectContext.get() != null) { + // analyzed rowCount may be zero, but BE-reported rowCount could be positive. + // check ndv validation when reported rowCount > 0 + if ((rowCount == -1 || !calculator.checkNdvValidation(scan, rowCount)) && ConnectContext.get() != null) { try { ConnectContext.get().getSessionVariable().disableNereidsJoinReorderOnce(); LOG.info("disable join reorder since row count not available: " @@ -403,6 +405,21 @@ private double getOlapTableRowCount(OlapScan olapScan) { return rowCount; } + // check validation of ndv. + private boolean checkNdvValidation(OlapScan olapScan, double rowCount) { + for (Slot slot : ((Plan) olapScan).getOutput()) { + if (isVisibleSlotReference(slot)) { + ColumnStatistic cache = getColumnStatsFromTableCache((CatalogRelation) olapScan, (SlotReference) slot); + if (!cache.isUnKnown + && cache.ndv == 0 + && (cache.minExpr != null || cache.maxExpr != null)) { + return false; + } + } + } + return true; + } + private Statistics computeOlapScan(OlapScan olapScan) { OlapTable olapTable = olapScan.getTable(); double tableRowCount = getOlapTableRowCount(olapScan);