This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 64533269903 [opt](compound) Optimize by deleting the compound expr 
after obtaining the final result #28934 (#29008)
64533269903 is described below

commit 64533269903c57de627fd6b2171cf428ff78acdf
Author: zzzxl <33418555+zzzxl1...@users.noreply.github.com>
AuthorDate: Mon Dec 25 21:56:59 2023 +0800

    [opt](compound) Optimize by deleting the compound expr after obtaining the 
final result #28934 (#29008)
---
 be/src/olap/rowset/segment_v2/segment_iterator.cpp | 15 ++++--
 .../data/inverted_index_p0/test_compound.out       |  7 +++
 .../suites/inverted_index_p0/test_compound.groovy  | 63 ++++++++++++++++++++++
 3 files changed, 82 insertions(+), 3 deletions(-)

diff --git a/be/src/olap/rowset/segment_v2/segment_iterator.cpp 
b/be/src/olap/rowset/segment_v2/segment_iterator.cpp
index 1cd088c0e3c..4e3d6cfae9c 100644
--- a/be/src/olap/rowset/segment_v2/segment_iterator.cpp
+++ b/be/src/olap/rowset/segment_v2/segment_iterator.cpp
@@ -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;
                 }
             }
         }
@@ -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();
     }
 
diff --git a/regression-test/data/inverted_index_p0/test_compound.out 
b/regression-test/data/inverted_index_p0/test_compound.out
new file mode 100644
index 00000000000..4da9bf65689
--- /dev/null
+++ b/regression-test/data/inverted_index_p0/test_compound.out
@@ -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
+
diff --git a/regression-test/suites/inverted_index_p0/test_compound.groovy 
b/regression-test/suites/inverted_index_p0/test_compound.groovy
new file mode 100644
index 00000000000..9b1b8c7dde0
--- /dev/null
+++ b/regression-test/suites/inverted_index_p0/test_compound.groovy
@@ -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');"
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to