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

This commit is contained in:
zzzxl
2023-12-26 14:10:53 +08:00
committed by GitHub
parent f7a624de38
commit 52eeee347f
3 changed files with 82 additions and 3 deletions

View File

@ -490,11 +490,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;
}
}
}
@ -505,7 +514,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();
}

View File

@ -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

View File

@ -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');"
}