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

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

commit 66336e59e6c78e8b1757123a32a8a15baa0a2e9c
Author: Jerry Hu <[email protected]>
AuthorDate: Fri Mar 22 09:35:26 2024 +0800

    [fix](join) the result of left semi join with empty right side should be 
false, not null (#32477)
---
 be/src/vec/common/hash_table/join_hash_table.h            | 15 ++++++++-------
 .../correctness_p0/test_null_aware_left_anti_join.out     |  5 +++++
 .../correctness_p0/test_null_aware_left_anti_join.groovy  | 11 +++++++++++
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/be/src/vec/common/hash_table/join_hash_table.h 
b/be/src/vec/common/hash_table/join_hash_table.h
index d2d6dfc2ed9..c83f8d17c27 100644
--- a/be/src/vec/common/hash_table/join_hash_table.h
+++ b/be/src/vec/common/hash_table/join_hash_table.h
@@ -90,11 +90,11 @@ public:
                     int probe_idx, uint32_t build_idx, int probe_rows,
                     uint32_t* __restrict probe_idxs, bool& probe_visited,
                     uint32_t* __restrict build_idxs) {
-        if constexpr (JoinOpType == TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN) {
+        if constexpr (JoinOpType == TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN ||
+                      JoinOpType == TJoinOp::NULL_AWARE_LEFT_SEMI_JOIN) {
             if (_empty_build_side) {
-                return _process_null_aware_left_anti_join_for_empty_build_side<
-                        JoinOpType, with_other_conjuncts, 
is_mark_join>(probe_idx, probe_rows,
-                                                                        
probe_idxs, build_idxs);
+                return 
_process_null_aware_left_half_join_for_empty_build_side<JoinOpType>(
+                        probe_idx, probe_rows, probe_idxs, build_idxs);
             }
         }
 
@@ -247,11 +247,12 @@ public:
     }
 
 private:
-    template <int JoinOpType, bool with_other_conjuncts, bool is_mark_join>
-    auto _process_null_aware_left_anti_join_for_empty_build_side(int 
probe_idx, int probe_rows,
+    template <int JoinOpType>
+    auto _process_null_aware_left_half_join_for_empty_build_side(int 
probe_idx, int probe_rows,
                                                                  uint32_t* 
__restrict probe_idxs,
                                                                  uint32_t* 
__restrict build_idxs) {
-        static_assert(JoinOpType == TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN);
+        static_assert(JoinOpType == TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN ||
+                      JoinOpType == TJoinOp::NULL_AWARE_LEFT_SEMI_JOIN);
         auto matched_cnt = 0;
         const auto batch_size = max_batch_size;
 
diff --git 
a/regression-test/data/correctness_p0/test_null_aware_left_anti_join.out 
b/regression-test/data/correctness_p0/test_null_aware_left_anti_join.out
index 895bd327f34..f6b5f3c5153 100644
--- a/regression-test/data/correctness_p0/test_null_aware_left_anti_join.out
+++ b/regression-test/data/correctness_p0/test_null_aware_left_anti_join.out
@@ -18,3 +18,8 @@
 
 -- !select_2 --
 
+-- !semi_emtpy_right_false --
+\N     false
+1      false
+3      false
+
diff --git 
a/regression-test/suites/correctness_p0/test_null_aware_left_anti_join.groovy 
b/regression-test/suites/correctness_p0/test_null_aware_left_anti_join.groovy
index a414e860f76..9260ff81ab6 100644
--- 
a/regression-test/suites/correctness_p0/test_null_aware_left_anti_join.groovy
+++ 
b/regression-test/suites/correctness_p0/test_null_aware_left_anti_join.groovy
@@ -85,4 +85,15 @@ suite("test_null_aware_left_anti_join") {
                             FROM test_null_aware_left_anti_join2 AS t2
                         )
                         AND t1.`k1` IN (1, 2, 3, 5, 7);"""
+
+    // In left semi join, if right side is empty, the result should not be 
null but false.
+    qt_semi_emtpy_right_false """
+        select
+            t1.k1,
+            t1.k1 in (
+                select k1 from ${tableName2} t2 where t2.k1 > 2
+            ) value
+        from ${tableName1} t1
+        order by 1, 2;
+    """
 }


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

Reply via email to