From 505f25c5808d74a8a593042cf6eba36b4e13ea0f Mon Sep 17 00:00:00 2001 From: starocean999 <40539150+starocean999@users.noreply.github.com> Date: Fri, 7 Apr 2023 09:15:00 +0800 Subject: [PATCH] [fix](planner)use base index if the where clause is a constant value (#18367) sql : select bitmap_empty() from d_table where true; should always use base index instead of any mv, because the conjuncts is constant (true) and use none of the column from any mv --- .../main/java/org/apache/doris/planner/OlapScanNode.java | 4 +++- regression-test/data/mv_p0/where/k123/k123.out | 8 ++++++++ regression-test/suites/mv_p0/where/k123/k123.groovy | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java index 7ece5b09e3..6688d5c1ef 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java @@ -474,7 +474,9 @@ public class OlapScanNode extends ScanNode { if (mvColumn == null) { boolean isBound = false; for (Expr conjunct : conjuncts) { - if (conjunct.isBound(slotDescriptor.getId())) { + List tids = Lists.newArrayList(); + conjunct.getIds(tids, null); + if (!tids.isEmpty() && conjunct.isBound(slotDescriptor.getId())) { isBound = true; break; } diff --git a/regression-test/data/mv_p0/where/k123/k123.out b/regression-test/data/mv_p0/where/k123/k123.out index 55bd6c538c..faeb23fbb6 100644 --- a/regression-test/data/mv_p0/where/k123/k123.out +++ b/regression-test/data/mv_p0/where/k123/k123.out @@ -39,3 +39,11 @@ 2 4 2 4 +-- !select_mv_constant -- +\N +\N +\N +\N +\N +\N + diff --git a/regression-test/suites/mv_p0/where/k123/k123.groovy b/regression-test/suites/mv_p0/where/k123/k123.groovy index 09201fe31c..29da7d05af 100644 --- a/regression-test/suites/mv_p0/where/k123/k123.groovy +++ b/regression-test/suites/mv_p0/where/k123/k123.groovy @@ -86,4 +86,6 @@ suite ("k123p") { contains "(k123p4w)" } qt_select_mv """select k1,k2+k3 from d_table where k1 = 2 and k4 = "b" order by k1;""" + + qt_select_mv_constant """select bitmap_empty() from d_table where true;""" }