This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/doris.git
commit b0d58d68ccdf067a72df9550d7f6c27435fc28af Author: Mryange <[email protected]> AuthorDate: Thu Aug 22 22:26:05 2024 +0800 [fix](scan) fix predicate contains cast that results in null, the predicate will be miss. (#39550) ## Proposed changes ``` 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.--> --- 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 381f18e1728..73d237af7e9 100644 --- a/be/src/pipeline/exec/scan_operator.cpp +++ b/be/src/pipeline/exec/scan_operator.cpp @@ -534,6 +534,7 @@ template <typename Derived> Status ScanLocalState<Derived>::_eval_const_conjuncts(vectorized::VExpr* vexpr, vectorized::VExprContext* expr_ctx, 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; @@ -675,6 +676,9 @@ Status ScanLocalState<Derived>::_normalize_in_and_eq_predicate(vectorized::VExpr ColumnValueRange<T>::add_fixed_value_range, fn_name)); } range.intersection(temp_range); + } else { + _eos = true; + _scan_dependency->set_ready(); } *pdt = temp_pdt; } @@ -691,7 +695,7 @@ Status ScanLocalState<Derived>::_should_push_down_binary_predicate( pdt = 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++) { @@ -826,6 +830,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(); @@ -969,6 +976,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]
