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

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


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new 4528fc6e8cc [Fix](inverted index) Fix wrong need read data opt when 
enable_common_expr_pushdown is disabled #40689 (#40703)
4528fc6e8cc is described below

commit 4528fc6e8cc9badc6ebe04aa569de1d1f54f767d
Author: airborne12 <airborn...@gmail.com>
AuthorDate: Thu Sep 12 14:38:25 2024 +0800

    [Fix](inverted index) Fix wrong need read data opt when 
enable_common_expr_pushdown is disabled #40689 (#40703)
    
    cherry pick from #40689
---
 be/src/olap/rowset/segment_v2/segment_iterator.cpp |  6 ++++++
 .../data/inverted_index_p0/test_need_read_data.out |  6 ++++++
 .../inverted_index_p0/test_need_read_data.groovy   | 25 ++++++++++++++++++++++
 3 files changed, 37 insertions(+)

diff --git a/be/src/olap/rowset/segment_v2/segment_iterator.cpp 
b/be/src/olap/rowset/segment_v2/segment_iterator.cpp
index 520d3232cda..15ecfd707e4 100644
--- a/be/src/olap/rowset/segment_v2/segment_iterator.cpp
+++ b/be/src/olap/rowset/segment_v2/segment_iterator.cpp
@@ -993,6 +993,12 @@ Status SegmentIterator::_apply_inverted_index() {
  */
 bool 
SegmentIterator::_check_all_conditions_passed_inverted_index_for_column(ColumnId
 cid,
                                                                              
bool default_return) {
+    // If common_expr_pushdown is disabled, we cannot guarantee that all 
conditions are processed by the inverted index.
+    // Consider a scenario where there is a column predicate and an expression 
involving the same column in the SQL query,
+    // such as 'a < 0' and 'abs(a) > 1'. This could potentially lead to errors.
+    if (_opts.runtime_state && 
!_opts.runtime_state->query_options().enable_common_expr_pushdown) {
+        return false;
+    }
     auto pred_it = _column_predicate_inverted_index_status.find(cid);
     if (pred_it != _column_predicate_inverted_index_status.end()) {
         const auto& pred_map = pred_it->second;
diff --git a/regression-test/data/inverted_index_p0/test_need_read_data.out 
b/regression-test/data/inverted_index_p0/test_need_read_data.out
index 7298254f838..782d5e5ab0b 100644
--- a/regression-test/data/inverted_index_p0/test_need_read_data.out
+++ b/regression-test/data/inverted_index_p0/test_need_read_data.out
@@ -25,3 +25,9 @@
 -- !sql4 --
 2024-06-17T15:16:49    tengxun2
 
+-- !sql --
+1
+
+-- !sql --
+1
+
diff --git 
a/regression-test/suites/inverted_index_p0/test_need_read_data.groovy 
b/regression-test/suites/inverted_index_p0/test_need_read_data.groovy
index f66b92ae66c..e1251d207f8 100644
--- a/regression-test/suites/inverted_index_p0/test_need_read_data.groovy
+++ b/regression-test/suites/inverted_index_p0/test_need_read_data.groovy
@@ -113,4 +113,29 @@ suite("test_need_read_data", "p0"){
     qt_sql2 """ select  *  from  ${indexTbName2}  WHERE  a  >=  '2024-06-15  
00:00:00'  AND  b  =  'tengxun2'  and    `b`  match  'tengxun2'  ; """
     qt_sql3 """ select  COUNT(1)  from  ${indexTbName2}  WHERE  a  >=  
'2024-06-15  00:00:00'  AND  b  like  '%tengxun%'  and    `b`  match  
'tengxun2'  ; """
     qt_sql4 """ select  *  from  ${indexTbName2}  WHERE  a  >=  '2024-06-15  
00:00:00'  AND  b  like  '%tengxun%'  and    `b`  match  'tengxun2'  ; """
+
+    def indexTblName3 = "test_need_read_data_3"
+
+    sql "DROP TABLE IF EXISTS ${indexTblName3}"
+    // create 1 replica table
+    sql """
+       CREATE TABLE IF NOT EXISTS ${indexTblName3}(
+           `id` int(11) NOT NULL,
+        `value` int(11) NULL,
+           INDEX c_value_idx(`value`) USING INVERTED COMMENT ''
+       ) ENGINE=OLAP
+       DUPLICATE KEY(`id`)
+       COMMENT 'OLAP'
+       DISTRIBUTED BY HASH(`id`) BUCKETS 1
+       PROPERTIES(
+           "replication_allocation" = "tag.location.default: 1"
+       );
+    """
+
+    def var_result = sql "show variables"
+    logger.info("show variales result: " + var_result )
+
+    sql "INSERT INTO ${indexTblName3} VALUES (1, 1),(1, -2),(1, -1);"
+    qt_sql "SELECT /*+SET_VAR(enable_common_expr_pushdown=false) */ id FROM 
${indexTblName3} WHERE value<0 and abs(value)>1;"
+    qt_sql "SELECT /*+SET_VAR(enable_common_expr_pushdown=true) */ id FROM 
${indexTblName3} WHERE value<0 and abs(value)>1;"
 }


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

Reply via email to