Skip to content

Commit

Permalink
[fix](inverted index) Error parsing NULL_LITERAL (#37842)
Browse files Browse the repository at this point in the history
## Proposed changes

1. NULL_LITERAL and other LITERAL will enter the else process
incorrectly
2. SELECT * FROM table_name WHERE column_name NOT IN (1, 2, NULL); The
NOT IN operator returns an empty result set when the collection contains
NULL.
  • Loading branch information
zzzxl1993 authored Jul 16, 2024
1 parent e478570 commit 21e5374
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 13 deletions.
6 changes: 4 additions & 2 deletions be/src/olap/rowset/segment_v2/segment_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ 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;
Expand Down Expand Up @@ -2811,7 +2812,8 @@ void SegmentIterator::_calculate_pred_in_remaining_conjunct_root(
} else if (_is_literal_node(node_type)) {
auto v_literal_expr = static_cast<const doris::vectorized::VLiteral*>(expr.get());
_column_predicate_info->query_values.insert(v_literal_expr->value());
} else {
} else if (node_type == TExprNodeType::BINARY_PRED || node_type == TExprNodeType::MATCH_PRED ||
node_type == TExprNodeType::IN_PRED) {
if (node_type == TExprNodeType::MATCH_PRED) {
_column_predicate_info->query_op = "match";
} else if (node_type == TExprNodeType::IN_PRED) {
Expand All @@ -2820,7 +2822,7 @@ void SegmentIterator::_calculate_pred_in_remaining_conjunct_root(
} else {
_column_predicate_info->query_op = "not_in";
}
} else if (node_type != TExprNodeType::COMPOUND_PRED) {
} else {
_column_predicate_info->query_op = expr->fn().name.function_name;
}

Expand Down
19 changes: 9 additions & 10 deletions be/src/pipeline/exec/scan_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,18 +1100,12 @@ Status ScanLocalState<Derived>::_normalize_in_and_not_in_compound_predicate(
auto hybrid_set = expr->get_set_func();

if (hybrid_set != nullptr) {
if (hybrid_set->size() <=
_parent->cast<typename Derived::Parent>()._max_pushdown_conditions_per_column) {
iter = hybrid_set->begin();
} else {
_filter_predicates.in_filters.emplace_back(slot->col_name(), expr->get_set_func());
*pdt = PushDownType::ACCEPTABLE;
return Status::OK();
}
*pdt = PushDownType::UNACCEPTABLE;
return Status::OK();
} else {
vectorized::VInPredicate* pred = static_cast<vectorized::VInPredicate*>(expr);
auto* pred = static_cast<vectorized::VInPredicate*>(expr);

vectorized::InState* state = reinterpret_cast<vectorized::InState*>(
auto* state = reinterpret_cast<vectorized::InState*>(
expr_ctx->fn_context(pred->fn_context_index())
->get_function_state(FunctionContext::FRAGMENT_LOCAL));

Expand All @@ -1120,6 +1114,11 @@ Status ScanLocalState<Derived>::_normalize_in_and_not_in_compound_predicate(
}

iter = state->hybrid_set->begin();

if (state->hybrid_set->contain_null()) {
*pdt = PushDownType::UNACCEPTABLE;
return Status::OK();
}
}

while (iter->has_next()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,39 @@
-- !sql --
208

-- !sql --
30

-- !sql --
0

-- !sql --
0

-- !sql --
34

-- !sql --
2

-- !sql --
2

-- !sql --
30

-- !sql --
0

-- !sql --
0

-- !sql --
34

-- !sql --
2

-- !sql --
2

18 changes: 18 additions & 0 deletions regression-test/data/inverted_index_p0/test_index_rqg_bug4.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
\N
a
b
f
h
i
j
k
l
o
p
q
v
y
z

Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,29 @@ suite("test_index_inlist_fault_injection", "nonConcurrent") {
} finally {
GetDebugPoint().disableDebugPointForAllBEs("segment_iterator._rowid_result_for_index")
}

try {
sql """ set enable_common_expr_pushdown = true; """

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')); """
qt_sql """ select count() from ${indexTbName} where (clientip not in ('40.135.0.0', '232.0.0.0', NULL, '26.1.0.0', '247.37.0.0')); """
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') and 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') or clientip match '120.1.0.0'); """
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'); """

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')); """
qt_sql """ select count() from ${indexTbName} where (clientip not in ('40.135.0.0', '232.0.0.0', NULL, '26.1.0.0', '247.37.0.0')); """
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') and 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') or clientip match '120.1.0.0'); """
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'); """

sql """ set enable_common_expr_pushdown = true; """
} finally {
}
} finally {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
suite("test_index_rqg_bug2", "test_index_rqg_bug2"){
suite("test_index_rqg_bug2", "test_index_rqg_bug"){
def table1 = "test_index_rqg_bug2"

sql "drop table if exists ${table1}"
Expand Down
162 changes: 162 additions & 0 deletions regression-test/suites/inverted_index_p0/test_index_rqg_bug4.groovy

Large diffs are not rendered by default.

0 comments on commit 21e5374

Please sign in to comment.