This is an automated email from the ASF dual-hosted git repository. starocean999 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 23784787b16 [fix](planner)should bind expr using no slot to correct tuple (#28656) 23784787b16 is described below commit 23784787b16121f70ff25bad213594a9cfc4c942 Author: starocean999 <40539150+starocean...@users.noreply.github.com> AuthorDate: Wed Dec 20 10:29:59 2023 +0800 [fix](planner)should bind expr using no slot to correct tuple (#28656) --- .../java/org/apache/doris/analysis/Analyzer.java | 8 +++++ .../main/java/org/apache/doris/analysis/Expr.java | 9 ++++++ .../suites/correctness_p0/test_rand_filter.groovy | 36 ++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java index 7931705cc31..3737093d023 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java @@ -1335,6 +1335,14 @@ public class Analyzer { public void registerConjuncts(Expr e, boolean fromHavingClause, List<TupleId> ids) throws AnalysisException { for (Expr conjunct : e.getConjuncts()) { registerConjunct(conjunct); + if (!e.isConstant()) { + ArrayList<TupleId> tupleIds = Lists.newArrayList(); + ArrayList<SlotId> slotIds = Lists.newArrayList(); + e.getIds(tupleIds, slotIds); + if (tupleIds.isEmpty() && slotIds.isEmpty()) { + e.setBoundTupleIds(ids); + } + } if (ids != null) { for (TupleId id : ids) { registerConstantConjunct(id, conjunct); diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java index 6c614db71ca..c087107e5e0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java @@ -298,6 +298,8 @@ public abstract class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl protected boolean printSqlInParens = false; protected Optional<String> exprName = Optional.empty(); + protected List<TupleId> boundTupleIds = null; + protected Expr() { super(); type = Type.INVALID; @@ -1293,6 +1295,9 @@ public abstract class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl * Returns true if expr is fully bound by tids, otherwise false. */ public boolean isBoundByTupleIds(List<TupleId> tids) { + if (boundTupleIds != null && !boundTupleIds.isEmpty()) { + return boundTupleIds.stream().anyMatch(id -> tids.contains(id)); + } for (Expr child : children) { if (!child.isBoundByTupleIds(tids)) { return false; @@ -1301,6 +1306,10 @@ public abstract class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl return true; } + public void setBoundTupleIds(List<TupleId> tids) { + boundTupleIds = tids; + } + /** * Returns true if expr have child bound by tids, otherwise false. diff --git a/regression-test/suites/correctness_p0/test_rand_filter.groovy b/regression-test/suites/correctness_p0/test_rand_filter.groovy new file mode 100644 index 00000000000..ccad3161caf --- /dev/null +++ b/regression-test/suites/correctness_p0/test_rand_filter.groovy @@ -0,0 +1,36 @@ +// 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("test_rand_filter") { + sql"""set enable_nereids_planner=false;""" + sql """ DROP TABLE IF EXISTS test_rand_filter_t """ + sql """ + CREATE TABLE test_rand_filter_t ( + a int + ) + DUPLICATE KEY(a) + DISTRIBUTED BY HASH(a) BUCKETS 1 + PROPERTIES ( + "replication_num" = "1" + ) + """ + explain { + sql("""select * from test_rand_filter_t where rand() < 0.5 union all select * from test_rand_filter_t where rand() > 0.3;""") + notContains("AND") + } + sql """ DROP TABLE IF EXISTS test_rand_filter_t """ +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org