Skip to content

Commit

Permalink
[fix](planner)should bind expr using no slot to correct tuple (apache…
Browse files Browse the repository at this point in the history
  • Loading branch information
starocean999 authored and stephen committed Dec 28, 2023
1 parent 5422589 commit 7a87f37
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,14 @@ public void registerConjuncts(Expr e, boolean fromHavingClause) throws AnalysisE
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);
Expand Down
9 changes: 9 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ public boolean apply(Expr arg) {
protected boolean printSqlInParens = false;
protected Optional<String> exprName = Optional.empty();

protected List<TupleId> boundTupleIds = null;

protected Expr() {
super();
type = Type.INVALID;
Expand Down Expand Up @@ -1293,6 +1295,9 @@ public boolean isBound(TupleId tid) {
* 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;
Expand All @@ -1301,6 +1306,10 @@ public boolean isBoundByTupleIds(List<TupleId> tids) {
return true;
}

public void setBoundTupleIds(List<TupleId> tids) {
boundTupleIds = tids;
}


/**
* Returns true if expr have child bound by tids, otherwise false.
Expand Down
36 changes: 36 additions & 0 deletions regression-test/suites/correctness_p0/test_rand_filter.groovy
Original file line number Diff line number Diff line change
@@ -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 """
}

0 comments on commit 7a87f37

Please sign in to comment.