This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 0f8bd33077b [fix](scan) fix predicate contains cast that results in
null, the pr… (#39809)
0f8bd33077b is described below
commit 0f8bd33077b93d0e9bec7cb1da77bea1930f4666
Author: Mryange <[email protected]>
AuthorDate: Fri Aug 23 01:46:22 2024 +0800
[fix](scan) fix predicate contains cast that results in null, the pr…
(#39809)
…edicate will be miss. (#39550)
https://github.com/apache/doris/pull/39550
```
drop table datetest;
create table datetest (
id int,
dt date
)
DUPLICATE key (id)
distributed by hash(id) buckets 1
properties(
"replication_num" = "1"
);
insert into datetest values (1, '2024-01-01');
mysql [test10]>select dt from datetest WHERE dt = 1 ;
+------------+
| dt |
+------------+
| 2024-01-01 |
+------------+
```
now
```
mysql [test10]>select dt from datetest WHERE dt = 1 ;
Empty set (0.16 sec)
```
<!--Describe your changes.-->
## Proposed changes
Issue Number: close #xxx
<!--Describe your changes.-->
---
be/src/pipeline/exec/scan_operator.cpp | 12 +++-
.../correctness/test_scan_with_cast_null_value.out | 33 +++++++++++
.../test_scan_with_cast_null_value.groovy | 64 ++++++++++++++++++++++
3 files changed, 108 insertions(+), 1 deletion(-)
diff --git a/be/src/pipeline/exec/scan_operator.cpp
b/be/src/pipeline/exec/scan_operator.cpp
index d88b778b45c..feb10a618da 100644
--- a/be/src/pipeline/exec/scan_operator.cpp
+++ b/be/src/pipeline/exec/scan_operator.cpp
@@ -580,6 +580,7 @@ template <typename Derived>
Status ScanLocalState<Derived>::_eval_const_conjuncts(vectorized::VExpr* vexpr,
vectorized::VExprContext* expr_ctx,
vectorized::VScanNode::PushDownType* pdt) {
+ // Used to handle constant expressions, such as '1 = 1'
_eval_const_conjuncts does not handle cases like 'colA = 1'
char* constant_val = nullptr;
if (vexpr->is_constant()) {
std::shared_ptr<ColumnPtrWrapper> const_col_wrapper;
@@ -720,6 +721,9 @@ Status
ScanLocalState<Derived>::_normalize_in_and_eq_predicate(
ColumnValueRange<T>::add_fixed_value_range, fn_name));
}
range.intersection(temp_range);
+ } else {
+ _eos = true;
+ _scan_dependency->set_ready();
}
*pdt = temp_pdt;
}
@@ -737,7 +741,7 @@ Status
ScanLocalState<Derived>::_should_push_down_binary_predicate(
pdt = vectorized::VScanNode::PushDownType::UNACCEPTABLE;
return Status::OK();
}
-
+ DCHECK(constant_val->data == nullptr) << "constant_val should not have a
value";
const auto& children = fn_call->children();
DCHECK(children.size() == 2);
for (size_t i = 0; i < children.size(); i++) {
@@ -873,6 +877,9 @@ Status
ScanLocalState<Derived>::_normalize_not_in_and_not_eq_predicate(
ColumnValueRange<T>::add_fixed_value_range,
fn_name));
}
}
+ } else {
+ _eos = true;
+ _scan_dependency->set_ready();
}
} else {
return Status::OK();
@@ -1014,6 +1021,9 @@ Status
ScanLocalState<Derived>::_normalize_noneq_binary_predicate(
ColumnValueRange<T>::add_value_range, fn_name,
slot_ref_child));
}
*pdt = temp_pdt;
+ } else {
+ _eos = true;
+ _scan_dependency->set_ready();
}
}
}
diff --git
a/regression-test/data/correctness/test_scan_with_cast_null_value.out
b/regression-test/data/correctness/test_scan_with_cast_null_value.out
new file mode 100644
index 00000000000..83f65bf10ad
--- /dev/null
+++ b/regression-test/data/correctness/test_scan_with_cast_null_value.out
@@ -0,0 +1,33 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !select_empty --
+
+-- !select_empty --
+
+-- !select_empty --
+
+-- !select_empty --
+
+-- !select_empty --
+
+-- !select_empty --
+
+-- !select_empty --
+
+-- !select_empty --
+
+-- !select_empty_fold_constant --
+
+-- !select_empty_fold_constant --
+
+-- !select_empty_fold_constant --
+
+-- !select_empty_fold_constant --
+
+-- !select_empty_fold_constant --
+
+-- !select_empty_fold_constant --
+
+-- !select_empty_fold_constant --
+
+-- !select_empty_fold_constant --
+
diff --git
a/regression-test/suites/correctness/test_scan_with_cast_null_value.groovy
b/regression-test/suites/correctness/test_scan_with_cast_null_value.groovy
new file mode 100644
index 00000000000..2523444bdfc
--- /dev/null
+++ b/regression-test/suites/correctness/test_scan_with_cast_null_value.groovy
@@ -0,0 +1,64 @@
+// 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_scan_with_cast_null_value") {
+
+ sql """
+ DROP TABLE IF EXISTS datetest
+ """
+ sql """
+ create table datetest (
+ id int,
+ dt date
+ )
+ DUPLICATE key (id)
+ distributed by hash(id) buckets 1
+ properties(
+ "replication_num" = "1"
+ );
+ """
+ sql """
+ insert into datetest values (1, '2024-01-01');
+ """
+ def expressions = ["=", "<>", "<", ">", "<=", ">="]
+ expressions.each { expr ->
+ qt_select_empty """
+ select dt from datetest WHERE dt ${expr} 1;
+ """
+ }
+ qt_select_empty """
+ select dt from datetest WHERE dt in (1);
+ """
+ qt_select_empty """
+ select dt from datetest WHERE dt not in (1);
+ """
+
+ sql """
+ set enable_fold_constant_by_be = true;
+ """
+ expressions.each { expr ->
+ qt_select_empty_fold_constant"""
+ select dt from datetest WHERE dt ${expr} 1;
+ """
+ }
+ qt_select_empty_fold_constant """
+ select dt from datetest WHERE dt in (1);
+ """
+ qt_select_empty_fold_constant """
+ select dt from datetest WHERE dt not in (1);
+ """
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]