This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit 8ac2304b6bb85074cd57a34efd14a02dfa72ca2f Author: Jerry Hu <mrh...@gmail.com> AuthorDate: Fri Mar 10 08:51:06 2023 +0800 [fix](olap) The 'scan key' generated by the 'is null' expression causes incorrect query results (#17569) --- be/src/exec/olap_common.h | 16 ++++++++++- .../data/correctness_p0/test_null_predicate.out | 4 +++ .../correctness_p0/test_null_predicate.groovy | 32 ++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/be/src/exec/olap_common.h b/be/src/exec/olap_common.h index 605ab9dda0..6ac6559996 100644 --- a/be/src/exec/olap_common.h +++ b/be/src/exec/olap_common.h @@ -1053,7 +1053,21 @@ Status OlapScanKeys::extend_scan_key(ColumnValueRange<primitive_type>& range, else { _has_range_value = true; - if (_begin_scan_keys.empty()) { + /// if max < min, this range should only contains a null value. + if (range.get_range_max_value() < range.get_range_min_value()) { + CHECK(range.contain_null()); + if (_begin_scan_keys.empty()) { + _begin_scan_keys.emplace_back(); + _begin_scan_keys.back().add_null(); + _end_scan_keys.emplace_back(); + _end_scan_keys.back().add_null(); + } else { + for (int i = 0; i < _begin_scan_keys.size(); ++i) { + _begin_scan_keys[i].add_null(); + _end_scan_keys[i].add_null(); + } + } + } else if (_begin_scan_keys.empty()) { _begin_scan_keys.emplace_back(); _begin_scan_keys.back().add_value(cast_to_string<primitive_type, CppType>( range.get_range_min_value(), range.scale()), diff --git a/regression-test/data/correctness_p0/test_null_predicate.out b/regression-test/data/correctness_p0/test_null_predicate.out index 8de8224c73..d6eb5270b1 100644 --- a/regression-test/data/correctness_p0/test_null_predicate.out +++ b/regression-test/data/correctness_p0/test_null_predicate.out @@ -174,3 +174,7 @@ -- !select14 -- 13 +-- !select16 -- +\N 99 +\N 101 + diff --git a/regression-test/suites/correctness_p0/test_null_predicate.groovy b/regression-test/suites/correctness_p0/test_null_predicate.groovy index ee925f3c99..b0134f91bf 100644 --- a/regression-test/suites/correctness_p0/test_null_predicate.groovy +++ b/regression-test/suites/correctness_p0/test_null_predicate.groovy @@ -87,4 +87,36 @@ suite("test_null_predicate") { qt_select12 """ select id, name from ${tableName} where id < 110 or name is not null order by id, name; """ qt_select13 """ select id, name from ${tableName} where id > 109 or name is not null order by id, name; """ qt_select14 """ select count(1) from ${tableName} where name is not null; """ + + sql """ DROP TABLE IF EXISTS test_null_predicate""" + sql """ + create table test_null_predicate ( + id boolean null, + value int null + ) duplicate key(id) + DISTRIBUTED BY HASH(id) buckets 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "disable_auto_compaction" = "true" + ); + """ + sql """ + insert into test_null_predicate values(1, null), (1,1), (null, 2), (1,2), (0, 3), (0, 4); + """ + + sql """ + insert into test_null_predicate values(1, null), (1,1), (null, 2), (1,2), (0, 3), (0, 4); + """ + + sql """ + delete from test_null_predicate where id is null; + """ + + sql """ + insert into test_null_predicate values (null, 99), (null, 101); + """ + + qt_select16 """ + select * from test_null_predicate where id is null order by id, value; + """ } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org