This is an automated email from the ASF dual-hosted git repository.
airborne pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new cb0613e2494 [fix] (inverted index) fix error result in compound query
(#40425)
cb0613e2494 is described below
commit cb0613e2494595916df1eab6b55b621647ec0e2c
Author: Sun Chenyang <[email protected]>
AuthorDate: Fri Sep 6 10:27:59 2024 +0800
[fix] (inverted index) fix error result in compound query (#40425)
## Proposed changes
`select count() from table where a + b > 0 or b > 0`

- When _execute_predicates_except_leafnode_of_andnode is executed, an
Expr tree is traversed from bottom to top. When it reaches the leaf node
b, the information of this column b is placed into new_predicate_info.
- However, this step is skipped directly at an ADD node, which leads to
the GT node at the upper level generating a sign equivalent to b > 0,
the same as the sign on the right side b > 0.
- This causes the compound OR calculation to assume that both GT
conditions below have been evaluated, thus prematurely computing this
EXPR, when in fact, the ADD node has not been evaluated.
- If the SQL is written as SELECT COUNT(*) FROM table WHERE b + a > 0 OR
b > 0, the calculation would be correct because the sign generated by
this > node would be equivalent to a > 0, which is different from b > 0
on the right side.
---
be/src/olap/rowset/segment_v2/segment_iterator.cpp | 4 +++
.../data/inverted_index_p0/test_index_rqg_bug5.out | 4 +++
.../inverted_index_p0/test_index_rqg_bug5.groovy | 38 ++++++++++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/be/src/olap/rowset/segment_v2/segment_iterator.cpp
b/be/src/olap/rowset/segment_v2/segment_iterator.cpp
index b9f9615f008..5d6d5657b89 100644
--- a/be/src/olap/rowset/segment_v2/segment_iterator.cpp
+++ b/be/src/olap/rowset/segment_v2/segment_iterator.cpp
@@ -842,6 +842,10 @@ Status
SegmentIterator::_execute_predicates_except_leafnode_of_andnode(
auto function_name = expr->fn().name.function_name;
// execute logic function
RETURN_IF_ERROR(_execute_compound_fn(function_name));
+ } else {
+ return Status::InvalidArgument(
+ "_execute_predicates_except_leafnode_of_andnode not supported
for TExprNodeType:{}",
+ node_type);
}
return Status::OK();
diff --git a/regression-test/data/inverted_index_p0/test_index_rqg_bug5.out
b/regression-test/data/inverted_index_p0/test_index_rqg_bug5.out
new file mode 100644
index 00000000000..095c7b20356
--- /dev/null
+++ b/regression-test/data/inverted_index_p0/test_index_rqg_bug5.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sql --
+1
+
diff --git
a/regression-test/suites/inverted_index_p0/test_index_rqg_bug5.groovy
b/regression-test/suites/inverted_index_p0/test_index_rqg_bug5.groovy
new file mode 100644
index 00000000000..c0181b17715
--- /dev/null
+++ b/regression-test/suites/inverted_index_p0/test_index_rqg_bug5.groovy
@@ -0,0 +1,38 @@
+// 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_index_rqg_bug5", "test_index_rqg_bug"){
+ def table = "test_index_rqg_bug5"
+ sql "drop table if exists ${table}"
+
+ sql """
+ create table ${table} (
+ pk int,
+ col1 int not null,
+ col2 bigint not null,
+ INDEX col1_idx (`col1`) USING INVERTED,
+ INDEX col2_idx (`col2`) USING INVERTED
+ ) engine=olap
+ DUPLICATE KEY(pk, col1)
+ distributed by hash(pk)
+ properties("replication_num" = "1");;
+ """
+
+ sql """ insert into ${table} values (10, 20, 30); """
+
+ qt_sql """ select count() from ${table} where col2 + col1 > 20 or col1 >
20; """
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]