Skip to content

Commit

Permalink
[opt](compound) Optimize by deleting the compound expr after obtainin…
Browse files Browse the repository at this point in the history
…g the final result apache#28934 (apache#29008)
  • Loading branch information
zzzxl1993 authored Dec 25, 2023
1 parent de95e76 commit 6453326
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
15 changes: 12 additions & 3 deletions be/src/olap/rowset/segment_v2/segment_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,20 @@ Status SegmentIterator::_get_row_ranges_by_column_conditions() {
if (config::enable_index_apply_preds_except_leafnode_of_andnode) {
RETURN_IF_ERROR(_apply_index_except_leafnode_of_andnode());
if (_can_filter_by_preds_except_leafnode_of_andnode()) {
for (auto& expr : _remaining_conjunct_roots) {
for (auto it = _remaining_conjunct_roots.begin();
it != _remaining_conjunct_roots.end();) {
_pred_except_leafnode_of_andnode_evaluate_result.clear();
auto res = _execute_predicates_except_leafnode_of_andnode(expr);
auto res = _execute_predicates_except_leafnode_of_andnode(*it);
if (res.ok() && _pred_except_leafnode_of_andnode_evaluate_result.size() == 1) {
_row_bitmap &= _pred_except_leafnode_of_andnode_evaluate_result[0];
// Delete expr after it obtains the final result.
{
std::erase_if(_common_expr_ctxs_push_down,
[&it](const auto& iter) { return iter->root() == *it; });
it = _remaining_conjunct_roots.erase(it);
}
} else {
++it;
}
}
}
Expand All @@ -472,7 +481,7 @@ Status SegmentIterator::_get_row_ranges_by_column_conditions() {

std::shared_ptr<doris::ColumnPredicate> runtime_predicate = nullptr;
if (_opts.use_topn_opt) {
auto query_ctx = _opts.runtime_state->get_query_ctx();
auto* query_ctx = _opts.runtime_state->get_query_ctx();
runtime_predicate = query_ctx->get_runtime_predicate().get_predictate();
}

Expand Down
7 changes: 7 additions & 0 deletions regression-test/data/inverted_index_p0/test_compound.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
2

-- !sql --
3

63 changes: 63 additions & 0 deletions regression-test/suites/inverted_index_p0/test_compound.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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_compound", "p0"){
def timeout = 60000
def delta_time = 1000
def alter_res = "null"
def useTime = 0

def indexTblName = "test_compound"

sql "DROP TABLE IF EXISTS ${indexTblName}"

sql """
CREATE TABLE IF NOT EXISTS ${indexTblName}(
`id` int(11) NOT NULL,
`a` text NULL DEFAULT "",
`b` text NULL DEFAULT "",
`c` text NULL DEFAULT "",
INDEX a_idx(`a`) USING INVERTED COMMENT '',
INDEX b_idx(`b`) USING INVERTED COMMENT '',
INDEX c_idx(`c`) USING INVERTED COMMENT ''
) ENGINE=OLAP
DUPLICATE KEY(`id`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`id`) BUCKETS 1
PROPERTIES(
"replication_allocation" = "tag.location.default: 1"
);
"""

sql """
INSERT INTO $indexTblName VALUES
(1, '1', '1', '1'),
(2, '2', '2', '2'),
(3, '3', '3', '3'),
(4, '4', '4', '4'),
(5, '5', '5', '5'),
(6, '6', '6', '6'),
(7, '7', '7', '7'),
(8, '8', '8', '8'),
(9, '9', '9', '9'),
(10, '10', '10', '10');
"""

qt_sql "SELECT count() FROM $indexTblName WHERE (id >= 2 AND id < 9) and (a match '2' or b match '5' and c match '5');"
qt_sql "SELECT count() FROM $indexTblName WHERE (id >= 2 AND id < 9) and (a match '2' or b match '5' or c match '6');"
}

0 comments on commit 6453326

Please sign in to comment.