Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opt](compound) Optimize by deleting the compound expr after obtaining the final result #28934

Merged
merged 1 commit into from
Dec 26, 2023
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
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 @@ -489,11 +489,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,
Copy link
Member

Choose a reason for hiding this comment

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

if pred1 ok, pred 2 not ok, is there any side effect by erasing it from remaining roots?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only if all the preds in the COMPOUND expr are correctly evaluated and the overall result is obtained, can this expr be deleted.

[&it](const auto& iter) { return iter->root() == *it; });
it = _remaining_conjunct_roots.erase(it);
}
} else {
++it;
}
}
}
Expand All @@ -504,7 +513,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');"
}
Loading