From a60f2ee639518bd408b2de49d9feb0d019af3429 Mon Sep 17 00:00:00 2001 From: zzzxl1993 <474696115@qq.com> Date: Tue, 16 Jul 2024 17:19:53 +0800 Subject: [PATCH] [fix](inverted index) Incorrect handling of NULL literal --- be/src/olap/rowset/segment_v2/segment_iterator.cpp | 11 +++++++---- .../test_index_inlist_fault_injection.out | 12 ++++++++++++ .../test_index_inlist_fault_injection.groovy | 6 ++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/be/src/olap/rowset/segment_v2/segment_iterator.cpp b/be/src/olap/rowset/segment_v2/segment_iterator.cpp index 23f531a0c09792..db1d2e9e67610e 100644 --- a/be/src/olap/rowset/segment_v2/segment_iterator.cpp +++ b/be/src/olap/rowset/segment_v2/segment_iterator.cpp @@ -753,7 +753,6 @@ bool SegmentIterator::_is_literal_node(const TExprNodeType::type& node_type) { case TExprNodeType::DECIMAL_LITERAL: case TExprNodeType::STRING_LITERAL: case TExprNodeType::DATE_LITERAL: - case TExprNodeType::NULL_LITERAL: return true; default: return false; @@ -2838,8 +2837,12 @@ void SegmentIterator::_calculate_pred_in_remaining_conjunct_root( } else if (_is_literal_node(node_type)) { auto v_literal_expr = static_cast(expr.get()); _column_predicate_info->query_values.insert(v_literal_expr->value()); - } else if (node_type == TExprNodeType::BINARY_PRED || node_type == TExprNodeType::MATCH_PRED || - node_type == TExprNodeType::IN_PRED) { + } else if (node_type == TExprNodeType::NULL_LITERAL) { + if (!_column_predicate_info->column_name.empty()) { + auto v_literal_expr = static_cast(expr.get()); + _column_predicate_info->query_values.insert(v_literal_expr->value()); + } + } else { if (node_type == TExprNodeType::MATCH_PRED) { _column_predicate_info->query_op = "match"; } else if (node_type == TExprNodeType::IN_PRED) { @@ -2848,7 +2851,7 @@ void SegmentIterator::_calculate_pred_in_remaining_conjunct_root( } else { _column_predicate_info->query_op = "not_in"; } - } else { + } else if (node_type != TExprNodeType::COMPOUND_PRED) { _column_predicate_info->query_op = expr->fn().name.function_name; } diff --git a/regression-test/data/fault_injection_p0/test_index_inlist_fault_injection.out b/regression-test/data/fault_injection_p0/test_index_inlist_fault_injection.out index 7e9336a12c9139..528b4008084f7e 100644 --- a/regression-test/data/fault_injection_p0/test_index_inlist_fault_injection.out +++ b/regression-test/data/fault_injection_p0/test_index_inlist_fault_injection.out @@ -35,6 +35,12 @@ -- !sql -- 2 +-- !sql -- +3 + +-- !sql -- +2 + -- !sql -- 30 @@ -53,3 +59,9 @@ -- !sql -- 2 +-- !sql -- +3 + +-- !sql -- +2 + diff --git a/regression-test/suites/fault_injection_p0/test_index_inlist_fault_injection.groovy b/regression-test/suites/fault_injection_p0/test_index_inlist_fault_injection.groovy index 57ec94d9f999ce..8d22c001ed0692 100644 --- a/regression-test/suites/fault_injection_p0/test_index_inlist_fault_injection.groovy +++ b/regression-test/suites/fault_injection_p0/test_index_inlist_fault_injection.groovy @@ -101,6 +101,9 @@ suite("test_index_inlist_fault_injection", "nonConcurrent") { qt_sql """ select count() from ${indexTbName} where (clientip match '2.1.0.0' and clientip in ('40.135.0.0', '232.0.0.0', NULL, '26.1.0.0', '247.37.0.0') or clientip match '120.1.0.0'); """ qt_sql """ select count() from ${indexTbName} where (clientip match '2.1.0.0' or clientip in ('40.135.0.0', '232.0.0.0', NULL, '26.1.0.0', '247.37.0.0') and clientip match '120.1.0.0'); """ + qt_sql """ select count() from ${indexTbName} where (clientip = '2.1.0.0' and clientip = NULL or clientip = '40.135.0.0'); """ + qt_sql """ select count() from ${indexTbName} where (clientip = '2.1.0.0' or clientip = NULL and clientip = '40.135.0.0'); """ + sql """ set enable_common_expr_pushdown = false; """ qt_sql """ select count() from ${indexTbName} where (clientip in ('40.135.0.0', '232.0.0.0', NULL, '26.1.0.0', '247.37.0.0')); """ @@ -110,6 +113,9 @@ suite("test_index_inlist_fault_injection", "nonConcurrent") { qt_sql """ select count() from ${indexTbName} where (clientip match '2.1.0.0' and clientip in ('40.135.0.0', '232.0.0.0', NULL, '26.1.0.0', '247.37.0.0') or clientip match '120.1.0.0'); """ qt_sql """ select count() from ${indexTbName} where (clientip match '2.1.0.0' or clientip in ('40.135.0.0', '232.0.0.0', NULL, '26.1.0.0', '247.37.0.0') and clientip match '120.1.0.0'); """ + qt_sql """ select count() from ${indexTbName} where (clientip = '2.1.0.0' and clientip = NULL or clientip = '40.135.0.0'); """ + qt_sql """ select count() from ${indexTbName} where (clientip = '2.1.0.0' or clientip = NULL and clientip = '40.135.0.0'); """ + sql """ set enable_common_expr_pushdown = true; """ } finally { }