Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](planner)should bind expr using no slot to correct tuple #28656

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 """
}
Loading