Skip to content

Commit 865e3cd

Browse files
viiryaIsaac
andcommitted
test: cover a nullable element made a scope key by a correlated filter
Also simplify the nullable element check. Co-authored-by: Isaac <[email protected]>
1 parent a60e1af commit 865e3cd

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎datafusion/optimizer/src/decorrelate_predicate_subquery.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ fn build_join(
967967
)
968968
})
969969
.collect::<Result<Vec<_>>>()?;
970-
let value_may_be_null = elements_may_be_null.iter().any(|may_be_null| *may_be_null);
970+
let value_may_be_null = elements_may_be_null.contains(&true);
971971

972972
// Whether this join needs null-aware (`NOT IN` three-valued) semantics.
973973
// Decided once: the constant projection below, the mark branch and the anti

‎datafusion/sqllogictest/test_files/null_aware_multi_column.slt‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,41 @@ r
707707
s
708708
u
709709

710+
# An element that can be NULL in the schema but not in scope: the correlated
711+
# filter `i.y >= o.b` rejects a NULL `y` or `b`, so `b = y` is a scope key, and
712+
# the rows with a NULL `b` reach the join with a NULL scope key. Such a row has
713+
# an empty subquery, so its NOT IN is TRUE.
714+
statement ok
715+
CREATE TABLE mc_scope_outer(k INT, a INT, b INT) AS VALUES
716+
(1, 1, 2), (2, NULL, 2), (3, NULL, NULL), (4, 5, NULL), (5, NULL, 7), (6, 1, 9), (7, 3, 3);
717+
718+
statement ok
719+
CREATE TABLE mc_scope_inner(x INT, y INT) AS VALUES
720+
(1, 2), (NULL, 2), (5, NULL), (NULL, NULL), (3, 1), (8, 4);
721+
722+
query IB
723+
SELECT k, (a, b) NOT IN (SELECT x, y FROM mc_scope_inner i WHERE i.y >= o.b)
724+
FROM mc_scope_outer o ORDER BY k;
725+
----
726+
1 false
727+
2 NULL
728+
3 true
729+
4 true
730+
5 true
731+
6 true
732+
7 true
733+
734+
query I
735+
SELECT k FROM mc_scope_outer o
736+
WHERE (a, b) NOT IN (SELECT x, y FROM mc_scope_inner i WHERE i.y >= o.b)
737+
ORDER BY k;
738+
----
739+
3
740+
4
741+
5
742+
6
743+
7
744+
710745
#############
711746
## Cleanup
712747
#############
@@ -788,3 +823,9 @@ DROP TABLE mc_nn_ree_outer;
788823

789824
statement ok
790825
DROP TABLE mc_nn_ree_inner;
826+
827+
statement ok
828+
DROP TABLE mc_scope_outer;
829+
830+
statement ok
831+
DROP TABLE mc_scope_inner;

0 commit comments

Comments
 (0)