Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions be/src/exec/olap_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ inline SQLFilterOp to_olap_filter_type(const std::string& function_name, bool op
return opposite ? FILTER_NOT_IN : FILTER_IN;
} else if (function_name == "ne") {
return opposite ? FILTER_IN : FILTER_NOT_IN;
} else if (function_name == "in_list") {
} else if (function_name == "in") {
return opposite ? FILTER_NOT_IN : FILTER_IN;
} else if (function_name == "not_in_list") {
} else if (function_name == "not_in") {
return opposite ? FILTER_IN : FILTER_NOT_IN;
} else {
DCHECK(false) << "Function Name: " << function_name;
Expand Down
9 changes: 9 additions & 0 deletions be/src/olap/rowset/segment_v2/segment_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,15 @@ Status SegmentIterator::_next_batch_internal(vectorized::Block* block) {
return Status::EndOfFile("no more data in segment");
}

DBUG_EXECUTE_IF("segment_iterator._rowid_result_for_index", {
for (auto& iter : _rowid_result_for_index) {
if (iter.second.first) {
return Status::Error<ErrorCode::INTERNAL_ERROR>(
"_rowid_result_for_index exists true");
}
}
})

if (!_is_need_vec_eval && !_is_need_short_eval && !_is_need_expr_eval) {
if (_non_predicate_columns.empty()) {
return Status::InternalError("_non_predicate_columns is empty");
Expand Down
93 changes: 65 additions & 28 deletions be/src/pipeline/exec/scan_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,10 @@ void ScanLocalState<Derived>::_normalize_compound_predicate(
auto compound_fn_name = expr->fn().name.function_name;
auto children_num = expr->children().size();
for (auto i = 0; i < children_num; ++i) {
auto child_expr = expr->children()[i].get();
if (TExprNodeType::BINARY_PRED == child_expr->node_type()) {
auto* child_expr = expr->children()[i].get();
if (TExprNodeType::BINARY_PRED == child_expr->node_type() ||
TExprNodeType::IN_PRED == child_expr->node_type() ||
TExprNodeType::MATCH_PRED == child_expr->node_type()) {
SlotDescriptor* slot = nullptr;
ColumnValueRangeType* range_on_slot = nullptr;
if (_is_predicate_acting_on_slot(child_expr, in_predicate_checker, &slot,
Expand All @@ -1010,30 +1012,16 @@ void ScanLocalState<Derived>::_normalize_compound_predicate(
value_range.mark_runtime_filter_predicate(
_is_runtime_filter_predicate);
}};
static_cast<void>(_normalize_binary_in_compound_predicate(
child_expr, expr_ctx, slot, value_range, pdt));
},
active_range);

_compound_value_ranges.emplace_back(active_range);
}
} else if (TExprNodeType::MATCH_PRED == child_expr->node_type()) {
SlotDescriptor* slot = nullptr;
ColumnValueRangeType* range_on_slot = nullptr;
if (_is_predicate_acting_on_slot(child_expr, in_predicate_checker, &slot,
&range_on_slot) ||
_is_predicate_acting_on_slot(child_expr, eq_predicate_checker, &slot,
&range_on_slot)) {
ColumnValueRangeType active_range =
*range_on_slot; // copy, in order not to affect the range in the _colname_to_value_range
std::visit(
[&](auto& value_range) {
Defer mark_runtime_filter_flag {[&]() {
value_range.mark_runtime_filter_predicate(
_is_runtime_filter_predicate);
}};
static_cast<void>(_normalize_match_in_compound_predicate(
child_expr, expr_ctx, slot, value_range, pdt));
if (TExprNodeType::BINARY_PRED == child_expr->node_type()) {
static_cast<void>(_normalize_binary_compound_predicate(
child_expr, expr_ctx, slot, value_range, pdt));
} else if (TExprNodeType::IN_PRED == child_expr->node_type()) {
static_cast<void>(_normalize_in_and_not_in_compound_predicate(
child_expr, expr_ctx, slot, value_range, pdt));
} else {
static_cast<void>(_normalize_match_compound_predicate(
child_expr, expr_ctx, slot, value_range, pdt));
}
},
active_range);

Expand All @@ -1050,7 +1038,7 @@ void ScanLocalState<Derived>::_normalize_compound_predicate(

template <typename Derived>
template <PrimitiveType T>
Status ScanLocalState<Derived>::_normalize_binary_in_compound_predicate(
Status ScanLocalState<Derived>::_normalize_binary_compound_predicate(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function '_normalize_binary_compound_predicate' has cognitive complexity of 54 (threshold 50) [readability-function-cognitive-complexity]

Status ScanLocalState<Derived>::_normalize_binary_compound_predicate(
                                ^
Additional context

be/src/pipeline/exec/scan_operator.cpp:1044: +1, including nesting penalty of 0, nesting level increased to 1

    if (TExprNodeType::BINARY_PRED == expr->node_type()) {
    ^

be/src/pipeline/exec/scan_operator.cpp:1045: nesting level increased to 2

        auto eq_checker = [](const std::string& fn_name) { return fn_name == "eq"; };
                          ^

be/src/pipeline/exec/scan_operator.cpp:1046: nesting level increased to 2

        auto ne_checker = [](const std::string& fn_name) { return fn_name == "ne"; };
                          ^

be/src/pipeline/exec/scan_operator.cpp:1047: nesting level increased to 2

        auto noneq_checker = [](const std::string& fn_name) {
                             ^

be/src/pipeline/exec/scan_operator.cpp:1048: +1

            return fn_name != "ne" && fn_name != "eq" && fn_name != "eq_for_null";
                                                      ^

be/src/pipeline/exec/scan_operator.cpp:1056: +2, including nesting penalty of 1, nesting level increased to 2

        RETURN_IF_ERROR(_should_push_down_binary_predicate(
        ^

be/src/common/status.h:626: expanded from macro 'RETURN_IF_ERROR'

    do {                                \
    ^

be/src/pipeline/exec/scan_operator.cpp:1056: +3, including nesting penalty of 2, nesting level increased to 3

        RETURN_IF_ERROR(_should_push_down_binary_predicate(
        ^

be/src/common/status.h:628: expanded from macro 'RETURN_IF_ERROR'

        if (UNLIKELY(!_status_.ok())) { \
        ^

be/src/pipeline/exec/scan_operator.cpp:1059: +2, including nesting penalty of 1, nesting level increased to 2

        RETURN_IF_ERROR(_should_push_down_binary_predicate(
        ^

be/src/common/status.h:626: expanded from macro 'RETURN_IF_ERROR'

    do {                                \
    ^

be/src/pipeline/exec/scan_operator.cpp:1059: +3, including nesting penalty of 2, nesting level increased to 3

        RETURN_IF_ERROR(_should_push_down_binary_predicate(
        ^

be/src/common/status.h:628: expanded from macro 'RETURN_IF_ERROR'

        if (UNLIKELY(!_status_.ok())) { \
        ^

be/src/pipeline/exec/scan_operator.cpp:1062: +2, including nesting penalty of 1, nesting level increased to 2

        RETURN_IF_ERROR(_should_push_down_binary_predicate(
        ^

be/src/common/status.h:626: expanded from macro 'RETURN_IF_ERROR'

    do {                                \
    ^

be/src/pipeline/exec/scan_operator.cpp:1062: +3, including nesting penalty of 2, nesting level increased to 3

        RETURN_IF_ERROR(_should_push_down_binary_predicate(
        ^

be/src/common/status.h:628: expanded from macro 'RETURN_IF_ERROR'

        if (UNLIKELY(!_status_.ok())) { \
        ^

be/src/pipeline/exec/scan_operator.cpp:1065: +2, including nesting penalty of 1, nesting level increased to 2

        if (eq_pdt == PushDownType::UNACCEPTABLE && ne_pdt == PushDownType::UNACCEPTABLE &&
        ^

be/src/pipeline/exec/scan_operator.cpp:1065: +1

        if (eq_pdt == PushDownType::UNACCEPTABLE && ne_pdt == PushDownType::UNACCEPTABLE &&
                                                                                         ^

be/src/pipeline/exec/scan_operator.cpp:1072: +2, including nesting penalty of 1, nesting level increased to 2

        if (eq_pdt == PushDownType::ACCEPTABLE || ne_pdt == PushDownType::ACCEPTABLE ||
        ^

be/src/pipeline/exec/scan_operator.cpp:1072: +1

        if (eq_pdt == PushDownType::ACCEPTABLE || ne_pdt == PushDownType::ACCEPTABLE ||
                                                                                     ^

be/src/pipeline/exec/scan_operator.cpp:1074: +3, including nesting penalty of 2, nesting level increased to 3

            if (value.data != nullptr) {
            ^

be/src/pipeline/exec/scan_operator.cpp:1075: +4, including nesting penalty of 3, nesting level increased to 4

                if constexpr (T == TYPE_CHAR || T == TYPE_VARCHAR || T == TYPE_STRING ||
                ^

be/src/pipeline/exec/scan_operator.cpp:1075: +1

                if constexpr (T == TYPE_CHAR || T == TYPE_VARCHAR || T == TYPE_STRING ||
                                                                                      ^

be/src/pipeline/exec/scan_operator.cpp:1078: +5, including nesting penalty of 4, nesting level increased to 5

                    RETURN_IF_ERROR(_change_value_range<false>(
                    ^

be/src/common/status.h:626: expanded from macro 'RETURN_IF_ERROR'

    do {                                \
    ^

be/src/pipeline/exec/scan_operator.cpp:1078: +6, including nesting penalty of 5, nesting level increased to 6

                    RETURN_IF_ERROR(_change_value_range<false>(
                    ^

be/src/common/status.h:628: expanded from macro 'RETURN_IF_ERROR'

        if (UNLIKELY(!_status_.ok())) { \
        ^

be/src/pipeline/exec/scan_operator.cpp:1082: +1, nesting level increased to 4

                } else {
                  ^

be/src/pipeline/exec/scan_operator.cpp:1083: +5, including nesting penalty of 4, nesting level increased to 5

                    RETURN_IF_ERROR(_change_value_range<false>(
                    ^

be/src/common/status.h:626: expanded from macro 'RETURN_IF_ERROR'

    do {                                \
    ^

be/src/pipeline/exec/scan_operator.cpp:1083: +6, including nesting penalty of 5, nesting level increased to 6

                    RETURN_IF_ERROR(_change_value_range<false>(
                    ^

be/src/common/status.h:628: expanded from macro 'RETURN_IF_ERROR'

        if (UNLIKELY(!_status_.ok())) { \
        ^

vectorized::VExpr* expr, vectorized::VExprContext* expr_ctx, SlotDescriptor* slot,
ColumnValueRange<T>& range, PushDownType* pdt) {
DCHECK(expr->children().size() == 2);
Expand Down Expand Up @@ -1107,7 +1095,56 @@ Status ScanLocalState<Derived>::_normalize_binary_in_compound_predicate(

template <typename Derived>
template <PrimitiveType T>
Status ScanLocalState<Derived>::_normalize_match_in_compound_predicate(
Status ScanLocalState<Derived>::_normalize_in_and_not_in_compound_predicate(
vectorized::VExpr* expr, vectorized::VExprContext* expr_ctx, SlotDescriptor* slot,
ColumnValueRange<T>& range, PushDownType* pdt) {
if (TExprNodeType::IN_PRED == expr->node_type()) {
std::string fn_name = expr->op() == TExprOpcode::type::FILTER_IN ? "in" : "not_in";

HybridSetBase::IteratorBase* iter = nullptr;
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();
}
} else {
vectorized::VInPredicate* pred = static_cast<vectorized::VInPredicate*>(expr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]

Suggested change
vectorized::VInPredicate* pred = static_cast<vectorized::VInPredicate*>(expr);
auto* pred = static_cast<vectorized::VInPredicate*>(expr);


vectorized::InState* state = reinterpret_cast<vectorized::InState*>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]

Suggested change
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));

if (!state->use_set) {
return Status::OK();
}

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

while (iter->has_next()) {
if (nullptr == iter->get_value()) {
iter->next();
continue;
}
auto* value = const_cast<void*>(iter->get_value());
RETURN_IF_ERROR(_change_value_range<false>(
range, value, ColumnValueRange<T>::add_compound_value_range, fn_name, 0));
iter->next();
}
*pdt = PushDownType::ACCEPTABLE;
}
return Status::OK();
}

template <typename Derived>
template <PrimitiveType T>
Status ScanLocalState<Derived>::_normalize_match_compound_predicate(
vectorized::VExpr* expr, vectorized::VExprContext* expr_ctx, SlotDescriptor* slot,
ColumnValueRange<T>& range, PushDownType* pdt) {
DCHECK(expr->children().size() == 2);
Expand Down
23 changes: 15 additions & 8 deletions be/src/pipeline/exec/scan_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,23 @@ class ScanLocalState : public ScanLocalStateBase {
vectorized::VExprSPtr&)>& eq_predicate_checker);

template <PrimitiveType T>
Status _normalize_binary_in_compound_predicate(vectorized::VExpr* expr,
vectorized::VExprContext* expr_ctx,
SlotDescriptor* slot, ColumnValueRange<T>& range,
PushDownType* pdt);
Status _normalize_binary_compound_predicate(vectorized::VExpr* expr,
vectorized::VExprContext* expr_ctx,
SlotDescriptor* slot, ColumnValueRange<T>& range,
PushDownType* pdt);

template <PrimitiveType T>
Status _normalize_match_in_compound_predicate(vectorized::VExpr* expr,
vectorized::VExprContext* expr_ctx,
SlotDescriptor* slot, ColumnValueRange<T>& range,
PushDownType* pdt);
Status _normalize_in_and_not_in_compound_predicate(vectorized::VExpr* expr,
vectorized::VExprContext* expr_ctx,
SlotDescriptor* slot,
ColumnValueRange<T>& range,
PushDownType* pdt);

template <PrimitiveType T>
Status _normalize_match_compound_predicate(vectorized::VExpr* expr,
vectorized::VExprContext* expr_ctx,
SlotDescriptor* slot, ColumnValueRange<T>& range,
PushDownType* pdt);

template <PrimitiveType T>
Status _normalize_is_null_predicate(vectorized::VExpr* expr, vectorized::VExprContext* expr_ctx,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
8

-- !sql --
996

-- !sql --
210

-- !sql --
8

-- !sql --
998

-- !sql --
208

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// 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_index_inlist_fault_injection", "nonConcurrent") {
// define a sql table
def indexTbName = "test_index_inlist_fault_injection"

sql "DROP TABLE IF EXISTS ${indexTbName}"
sql """
CREATE TABLE ${indexTbName} (
`@timestamp` int(11) NULL COMMENT "",
`clientip` varchar(20) NULL COMMENT "",
`request` text NULL COMMENT "",
`status` int(11) NULL COMMENT "",
`size` int(11) NULL COMMENT "",
INDEX clientip_idx (`clientip`) USING INVERTED COMMENT '',
INDEX request_idx (`request`) USING INVERTED PROPERTIES("parser" = "english", "support_phrase" = "true") COMMENT '',
INDEX status_idx (`status`) USING INVERTED COMMENT ''
) ENGINE=OLAP
DUPLICATE KEY(`@timestamp`)
COMMENT "OLAP"
DISTRIBUTED BY RANDOM BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"disable_auto_compaction" = "true"
);
"""

def load_httplogs_data = {table_name, label, read_flag, format_flag, file_name, ignore_failure=false,
expected_succ_rows = -1, load_to_single_tablet = 'true' ->

// load the json data
streamLoad {
table "${table_name}"

// set http request header params
set 'label', label + "_" + UUID.randomUUID().toString()
set 'read_json_by_line', read_flag
set 'format', format_flag
file file_name // import json file
time 10000 // limit inflight 10s
if (expected_succ_rows >= 0) {
set 'max_filter_ratio', '1'
}

// if declared a check callback, the default check condition will ignore.
// So you must check all condition
check { result, exception, startTime, endTime ->
if (ignore_failure && expected_succ_rows < 0) { return }
if (exception != null) {
throw exception
}
log.info("Stream load result: ${result}".toString())
def json = parseJson(result)
}
}
}

try {
load_httplogs_data.call(indexTbName, 'test_index_inlist_fault_injection', 'true', 'json', 'documents-1000.json')

sql "sync"

try {
GetDebugPoint().enableDebugPointForAllBEs("segment_iterator._rowid_result_for_index")

qt_sql """ select /*+ SET_VAR(inverted_index_skip_threshold = 0) */ count() from ${indexTbName} where clientip in ('40.135.0.0', '232.0.0.0', '26.1.0.0'); """
qt_sql """ select /*+ SET_VAR(inverted_index_skip_threshold = 0) */ count() from ${indexTbName} where status in (1, 304, 200); """
qt_sql """ select /*+ SET_VAR(inverted_index_skip_threshold = 0) */ count() from ${indexTbName} where (request match 'hm' or clientip in ('40.135.0.0', '232.0.0.0', '26.1.0.0')); """
qt_sql """ select /*+ SET_VAR(inverted_index_skip_threshold = 0) */ count() from ${indexTbName} where (request match 'hm' and clientip in ('40.135.0.0', '232.0.0.0', '26.1.0.0')); """
qt_sql """ select /*+ SET_VAR(inverted_index_skip_threshold = 0) */ count() from ${indexTbName} where (request match 'hm' or status in (1, 304, 200)); """
qt_sql """ select /*+ SET_VAR(inverted_index_skip_threshold = 0) */ count() from ${indexTbName} where (request match 'hm' and status in (1, 304, 200)); """

} finally {
GetDebugPoint().disableDebugPointForAllBEs("segment_iterator._rowid_result_for_index")
}
} finally {
}
}