From dae13844d05443166b7ff2ac9aca0612af1085c6 Mon Sep 17 00:00:00 2001 From: minghong Date: Mon, 14 Oct 2024 16:18:38 +0800 Subject: [PATCH] update --- .../org/apache/doris/nereids/stats/StatsCalculator.java | 8 +++++--- .../apache/doris/nereids/rules/rewrite/OrToInTest.java | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) 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 e3bc2ac58de915c..572cc7c71834bc2 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 || !calculator.checkNdvValidation(scan)) && 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: " @@ -404,11 +406,11 @@ private double getOlapTableRowCount(OlapScan olapScan) { } // check validation of ndv. - private boolean checkNdvValidation(OlapScan olapScan) { + 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.count != cache.numNulls) { + if (!cache.isUnKnown && cache.ndv == 0 && rowCount != cache.numNulls) { return false; } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/OrToInTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/OrToInTest.java index f5615d59fe81818..6f4103af9506b65 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/OrToInTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/OrToInTest.java @@ -205,4 +205,12 @@ void test16() { Assertions.assertEquals("(a = 1)", rewritten.toSql()); } + + @Test + void test17() { + String expr = "(a=1 and b=2) or (a in (2, 3) and ((a=2 and c=3) or (a=3 or d=4)))"; + Expression expression = PARSER.parseExpression(expr); + Expression rewritten = OrToIn.INSTANCE.rewriteTree(expression, context); + System.out.println(rewritten); + } }