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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 2d52a5d2cbbf3362e57828f0d7d68abba58e99d1
Author: Jerry Hu <[email protected]>
AuthorDate: Tue Mar 28 16:20:05 2023 +0800

    [fix](nested_loop_join)got incorrect result from nested loop join without 
condition (#18139)
---
 be/src/vec/exec/join/vnested_loop_join_node.cpp    | 20 ++++++
 .../correctness_p0/test_join_without_condition.out | 12 ++++
 .../test_join_without_condition.groovy             | 73 ++++++++++++++++++++++
 3 files changed, 105 insertions(+)

diff --git a/be/src/vec/exec/join/vnested_loop_join_node.cpp 
b/be/src/vec/exec/join/vnested_loop_join_node.cpp
index a83ef25e70..fb8816bbaa 100644
--- a/be/src/vec/exec/join/vnested_loop_join_node.cpp
+++ b/be/src/vec/exec/join/vnested_loop_join_node.cpp
@@ -700,6 +700,26 @@ Status 
VNestedLoopJoinNode::_do_filtering_and_update_visited_flags(
                 CLEAR_BLOCK
             }
         }
+    } else if (block->rows() > 0) {
+        if constexpr (SetBuildSideFlag) {
+            for (size_t i = 0; i < processed_blocks_num; i++) {
+                auto& build_side_flag =
+                        
assert_cast<ColumnUInt8*>(_build_side_visited_flags[build_block_idx].get())
+                                ->get_data();
+                auto* __restrict build_side_flag_data = build_side_flag.data();
+                auto cur_sz = build_side_flag.size();
+                offset_stack.pop();
+                memset(reinterpret_cast<void*>(build_side_flag_data), 1, 
cur_sz);
+                build_block_idx =
+                        build_block_idx == 0 ? _build_blocks.size() - 1 : 
build_block_idx - 1;
+            }
+        }
+        if constexpr (SetProbeSideFlag) {
+            _cur_probe_row_visited_flags = true;
+        }
+        if (!materialize) {
+            CLEAR_BLOCK
+        }
     }
 #undef CLEAR_BLOCK
     Block::erase_useless_column(block, column_to_keep);
diff --git 
a/regression-test/data/correctness_p0/test_join_without_condition.out 
b/regression-test/data/correctness_p0/test_join_without_condition.out
new file mode 100644
index 0000000000..6a9fdf3abf
--- /dev/null
+++ b/regression-test/data/correctness_p0/test_join_without_condition.out
@@ -0,0 +1,12 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select --
+1      4
+1      5
+1      6
+2      4
+2      5
+2      6
+3      4
+3      5
+3      6
+
diff --git 
a/regression-test/suites/correctness_p0/test_join_without_condition.groovy 
b/regression-test/suites/correctness_p0/test_join_without_condition.groovy
new file mode 100644
index 0000000000..c56144757a
--- /dev/null
+++ b/regression-test/suites/correctness_p0/test_join_without_condition.groovy
@@ -0,0 +1,73 @@
+// 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_join_without_condition") {
+    sql """
+        drop table if exists test_join_without_condition_a;
+    """
+
+    sql """
+        drop table if exists test_join_without_condition_b;
+    """
+
+    sql """
+        create table if not exists test_join_without_condition_a ( a int not 
null )
+        ENGINE=OLAP
+        DISTRIBUTED BY HASH(a) BUCKETS 1
+        PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1",
+        "in_memory" = "false",
+        "storage_format" = "V2"
+        );
+    """
+
+    sql """
+        create table if not exists test_join_without_condition_b ( a int not 
null )
+        ENGINE=OLAP
+        DISTRIBUTED BY HASH(a) BUCKETS 1
+        PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1",
+        "in_memory" = "false",
+        "storage_format" = "V2"
+        );
+    """
+
+    sql """
+        insert into test_join_without_condition_a values(1), (2), (3);
+    """
+
+    sql """
+        insert into test_join_without_condition_b values(4), (5), (6);
+    """
+
+    // here condition 'b.a > 1' will be pushed down to scan node.
+    qt_select """
+        select a.a, b.a
+        from
+            test_join_without_condition_a a
+            left join test_join_without_condition_b b on b.a > 1
+        order by a.a, b.a;
+    """
+
+    sql """
+        drop table if exists test_join_without_condition_a;
+    """
+
+    sql """
+        drop table if exists test_join_without_condition_b;
+    """
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to