should be it

This commit is contained in:
2025-10-24 19:21:19 -05:00
parent a4b23fc57c
commit f09560c7b1
14047 changed files with 3161551 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
# name: test/sql/join/inner/empty_tinyint_column.test
# description: Internal error on join of empty tinyint column
# group: [inner]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE t1(c0 INT4, c1 VARCHAR);
statement ok
CREATE TABLE t2(c0 TINYINT, PRIMARY KEY(c0));
statement ok
INSERT INTO t1(c0) VALUES (14161972);
statement ok
INSERT INTO t1(c0, c1) VALUES (-1.438515327E9, 4.43806148E8);
query III
SELECT * FROM t1 INNER JOIN t2 ON t1.c0 = t2.c0;
----

View File

@@ -0,0 +1,231 @@
# name: test/sql/join/inner/equality_join_limits.test
# description: Test equality joins on numeric limits
# group: [inner]
statement ok
PRAGMA enable_verification
# TINYINT limits
statement ok
CREATE TABLE t(t_k0 TINYINT);
statement ok
INSERT INTO t VALUES (-128), (127);
statement ok
CREATE TABLE u(u_k0 TINYINT);
statement ok
INSERT INTO u VALUES (-128), (127);
query II rowsort
SELECT t_k0, u_k0 FROM t, u WHERE t_k0 = u_k0;
----
-128 -128
127 127
statement ok
DROP TABLE t;
statement ok
DROP TABLE u;
# SMALLINT limits
statement ok
CREATE TABLE t(t_k0 SMALLINT);
statement ok
INSERT INTO t VALUES (-32768), (32767);
statement ok
CREATE TABLE u(u_k0 SMALLINT);
statement ok
INSERT INTO u VALUES (-32768), (32767);
query II rowsort
SELECT t_k0, u_k0 FROM t, u WHERE t_k0 = u_k0;
----
-32768 -32768
32767 32767
statement ok
DROP TABLE t;
statement ok
DROP TABLE u;
# INTEGER limits
statement ok
CREATE TABLE t(t_k0 INTEGER);
statement ok
INSERT INTO t VALUES (-2147483648), (2147483647);
statement ok
CREATE TABLE u(u_k0 INTEGER);
statement ok
INSERT INTO u VALUES (-2147483648), (2147483647);
query II rowsort
SELECT t_k0, u_k0 FROM t, u WHERE t_k0 = u_k0;
----
-2147483648 -2147483648
2147483647 2147483647
statement ok
DROP TABLE t;
statement ok
DROP TABLE u;
# BIGINT limits
statement ok
CREATE TABLE t(t_k0 BIGINT);
statement ok
INSERT INTO t VALUES (-9223372036854775808), (9223372036854775807);
statement ok
CREATE TABLE u(u_k0 BIGINT);
statement ok
INSERT INTO u VALUES (-9223372036854775808), (9223372036854775807);
query II rowsort
SELECT t_k0, u_k0 FROM t, u WHERE t_k0 = u_k0;
----
-9223372036854775808 -9223372036854775808
9223372036854775807 9223372036854775807
statement ok
DROP TABLE t;
statement ok
DROP TABLE u;
# HUGEINT limits
statement ok
CREATE TABLE t(t_k0 HUGEINT);
statement ok
INSERT INTO t VALUES (-170141183460469231731687303715884105728), (170141183460469231731687303715884105727);
statement ok
CREATE TABLE u(u_k0 HUGEINT);
statement ok
INSERT INTO u VALUES (-170141183460469231731687303715884105728), (170141183460469231731687303715884105727);
query II rowsort
SELECT t_k0, u_k0 FROM t, u WHERE t_k0 = u_k0;
----
-170141183460469231731687303715884105728 -170141183460469231731687303715884105728
170141183460469231731687303715884105727 170141183460469231731687303715884105727
statement ok
DROP TABLE t;
statement ok
DROP TABLE u;
# UTINYINT limits
statement ok
CREATE TABLE t(t_k0 UTINYINT);
statement ok
INSERT INTO t VALUES (0), (255);
statement ok
CREATE TABLE u(u_k0 UTINYINT);
statement ok
INSERT INTO u VALUES (0), (255);
query II rowsort
SELECT t_k0, u_k0 FROM t, u WHERE t_k0 = u_k0;
----
0 0
255 255
statement ok
DROP TABLE t;
statement ok
DROP TABLE u;
# USMALLINT limits
statement ok
CREATE TABLE t(t_k0 USMALLINT);
statement ok
INSERT INTO t VALUES (0), (65535);
statement ok
CREATE TABLE u(u_k0 USMALLINT);
statement ok
INSERT INTO u VALUES (0), (65535);
query II rowsort
SELECT t_k0, u_k0 FROM t, u WHERE t_k0 = u_k0;
----
0 0
65535 65535
statement ok
DROP TABLE t;
statement ok
DROP TABLE u;
# UINTEGER limits
statement ok
CREATE TABLE t(t_k0 UINTEGER);
statement ok
INSERT INTO t VALUES (0), (4294967295);
statement ok
CREATE TABLE u(u_k0 UINTEGER);
statement ok
INSERT INTO u VALUES (0), (4294967295);
query II rowsort
SELECT t_k0, u_k0 FROM t, u WHERE t_k0 = u_k0;
----
0 0
4294967295 4294967295
statement ok
DROP TABLE t;
statement ok
DROP TABLE u;
# UBIGINT limits
statement ok
CREATE TABLE t(t_k0 UBIGINT);
statement ok
INSERT INTO t VALUES (0), (18446744073709551615);
statement ok
CREATE TABLE u(u_k0 UBIGINT);
statement ok
INSERT INTO u VALUES (0), (18446744073709551615);
query II rowsort
SELECT t_k0, u_k0 FROM t, u WHERE t_k0 = u_k0;
----
0 0
18446744073709551615 18446744073709551615
statement ok
DROP TABLE t;
statement ok
DROP TABLE u;

View File

@@ -0,0 +1,45 @@
# name: test/sql/join/inner/join_cache.test
# description: Test joins with few matches which should result in cache usage
# group: [inner]
statement ok
PRAGMA enable_verification
statement ok
pragma verify_external
statement ok
CREATE TABLE smalltable AS SELECT 1::INTEGER a;
# values 1...1024 10x
statement ok
CREATE TABLE bigtable AS SELECT a::INTEGER a FROM generate_series(0, 10000, 1) tbl(a), generate_series(0, 9, 1) tbl2(b);
query I
SELECT COUNT(*) FROM bigtable JOIN smalltable USING (a)
----
10
query I
SELECT COUNT(*) FROM bigtable JOIN smalltable USING (a) JOIN smalltable t3 USING (a)
----
10
query I
SELECT COUNT(*) FROM bigtable JOIN smalltable USING (a) JOIN smalltable t3 USING (a) JOIN smalltable t4 USING (a);
----
10
query I
SELECT * FROM bigtable JOIN smalltable USING (a)
----
1
1
1
1
1
1
1
1
1
1

View File

@@ -0,0 +1,52 @@
# name: test/sql/join/inner/join_cross_product.test
# description: Test column binding in cross product of multiple joins
# group: [inner]
statement ok
PRAGMA enable_verification
statement ok
create table t1(i integer);
statement ok
create table t2(j integer);
statement ok
create table t3(k integer);
statement ok
create table t4(l integer);
statement ok
insert into t1 values (1);
statement ok
insert into t2 values (1);
statement ok
insert into t3 values (2), (3);
statement ok
insert into t4 values (2), (3);
query IIII
select * from t1 join t2 on (i=j), t3 join t4 on (k=l) order by 1, 2, 3, 4;
----
1 1 2 2
1 1 3 3
mode skip
# lateral join
query IIII rowsort
select * from t1 join t2 on (i=j), t3 join t4 on (i+k=j+l)
----
1 1 2 2
1 1 3 3
# postgres syntax
query IIII rowsort
select * from t1 join t2 on (i=j), lateral (select * from t3 join t4 on (i+k=j+l)) t(x);
----
1 1 2 2
1 1 3 3

View File

@@ -0,0 +1,21 @@
# name: test/sql/join/inner/list_join.test
# description: Join on large lists
# group: [inner]
statement ok
PRAGMA enable_verification
statement ok
pragma verify_external
statement ok
CREATE TABLE test (id INTEGER, l VARCHAR[]);
statement ok
INSERT INTO test SELECT i, case when (i/1000)%2=0 then ARRAY[1::VARCHAR, 1::VARCHAR, 1::VARCHAR] else ARRAY[2::VARCHAR, 2::VARCHAR] end FROM generate_series(0, 1999, 1) tbl(i);
query IIII
SELECT * FROM test AS t1 LEFT JOIN test AS t2 ON t1.id=t2.id WHERE t1.l!=t2.l or t1.id!=t2.id;
----

View File

@@ -0,0 +1,22 @@
# name: test/sql/join/inner/not_between_is_null.test
# description: Test INNER JOIN with NOT BETWEEN and IS NULL conditions
# group: [inner]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE t1(c0 INT);
CREATE TABLE t2(c0 INT);
statement ok
INSERT INTO t1(c0) VALUES (-18), (NULL);
statement ok
INSERT INTO t2(c0) VALUES (NULL);
query II
SELECT * FROM t1 INNER JOIN t2 ON ((t1.c0 NOT BETWEEN t2.c0 AND t2.c0) IS NULL);
----
-18 NULL
NULL NULL

View File

@@ -0,0 +1,131 @@
# name: test/sql/join/inner/test_eq_ineq_join.test
# description: Equality + inequality joins
# group: [inner]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 1), (12, 2), (13, 3)
statement ok
CREATE TABLE test2 (a INTEGER, c INTEGER);
statement ok
INSERT INTO test2 VALUES (11, 1), (12, 1), (13, 4)
query III
SELECT test.a, b, c FROM test, test2 WHERE test.a = test2.a AND test.b <> test2.c ORDER BY test.a;
----
12 2 1
13 3 4
query III
SELECT test.a, b, c FROM test, test2 WHERE test.a = test2.a AND test.b < test2.c ORDER BY test.a;
----
13 3 4
query III
SELECT test.a, b, c FROM test, test2 WHERE test.a = test2.a AND test.b <= test2.c ORDER BY test.a;
----
11 1 1
13 3 4
query III
SELECT test.a, b, c FROM test, test2 WHERE test.a = test2.a AND test.b > test2.c ORDER BY test.a;
----
12 2 1
query III
SELECT test.a, b, c FROM test, test2 WHERE test.a = test2.a AND test.b >= test2.c ORDER BY test.a;
----
11 1 1
12 2 1
statement ok
DROP TABLE test;
statement ok
DROP TABLE test2;
# Equality + inequality anti and semi joins
statement ok
CREATE TABLE test (a INTEGER, b INTEGER, str VARCHAR);
statement ok
INSERT INTO test VALUES (11, 1, 'a'), (12, 2, 'b'), (13, 3, 'c')
statement ok
CREATE TABLE test2 (a INTEGER, c INTEGER, str2 VARCHAR);
statement ok
INSERT INTO test2 VALUES (11, 1, 'd'), (12, 1, 'e'), (13, 4, 'f')
query IIT
SELECT * FROM test WHERE EXISTS(SELECT * FROM test2 WHERE test.a=test2.a AND test.b<>test2.c) order by 2;
----
12 2 b
13 3 c
query IIT
SELECT * FROM test WHERE EXISTS(SELECT * FROM test2 WHERE test.a=test2.a AND test.b<>test2.c) AND NOT EXISTS(SELECT * FROM test2 WHERE test.a=test2.a AND test.b<test2.c);
----
12 2 b
query IIT
SELECT * FROM test WHERE NOT EXISTS(SELECT * FROM test2 WHERE test.a=test2.a AND test.b<test2.c) order by 1;
----
11 1 a
12 2 b
query IIT
SELECT * FROM test WHERE NOT EXISTS(SELECT * FROM test2 WHERE test.a=test2.a AND test.b<test2.c) AND NOT EXISTS(SELECT * FROM test2 WHERE test.a=test2.a AND test.b>test2.c);
----
11 1 a
query IIT
SELECT * FROM test WHERE EXISTS(SELECT * FROM test2 WHERE test.a=test2.a AND test.b<>test2.c) AND test.a > 11 order by b;
----
12 2 b
13 3 c
statement ok
DROP TABLE test;
statement ok
DROP TABLE test2;
# Equality + inequality anti and semi joins with selection vector
statement ok
CREATE TABLE test (a INTEGER, b INTEGER, str VARCHAR);
statement ok
INSERT INTO test VALUES (11, 1, 'a'), (12, 2, 'b'), (13, 3, 'c')
statement ok
CREATE TABLE test2 (a INTEGER, c INTEGER, str2 VARCHAR);
statement ok
INSERT INTO test2 VALUES (11, 1, 'd'), (12, 1, 'e'), (13, 4, 'f')
query IIT
SELECT * FROM test WHERE NOT EXISTS(SELECT * FROM test2 WHERE test.a=test2.a AND test.b<test2.c AND test2.a>14) AND NOT EXISTS(SELECT * FROM test2 WHERE test.a=test2.a AND test.b>test2.c AND test2.a<10) order by 1;
----
11 1 a
12 2 b
13 3 c
query IIT
SELECT * FROM test WHERE NOT EXISTS(SELECT * FROM test2 WHERE test.a=test2.a AND test.b<test2.c AND test2.a=12) AND NOT EXISTS(SELECT * FROM test2 WHERE test.a=test2.a AND test.b>test2.c AND test2.a=12) order by 1;
----
11 1 a
13 3 c
query IIT
SELECT * FROM test WHERE EXISTS(SELECT * FROM test2 WHERE test.a=test2.a AND test.b<>test2.c) AND test.a < 13;
----
12 2 b

View File

@@ -0,0 +1,104 @@
# name: test/sql/join/inner/test_join.test
# description: Test basic joins of tables
# group: [inner]
statement ok
PRAGMA enable_verification
statement ok
pragma verify_external
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 1), (12, 2), (13, 3)
statement ok
CREATE TABLE test2 (b INTEGER, c INTEGER);
statement ok
INSERT INTO test2 VALUES (1, 10), (1, 20), (2, 30)
# simple cross product + join condition
query III
SELECT a, test.b, c FROM test, test2 WHERE test.b = test2.b ORDER BY c;
----
11 1 10
11 1 20
12 2 30
# ambiguous reference to column
statement error
SELECT b FROM test, test2 WHERE test.b > test2.b;
----
# simple cross product + multiple join conditions
query III
SELECT a, test.b, c FROM test, test2 WHERE test.b=test2.b AND test.a-1=test2.c
----
11 1 10
# use join columns in subquery
query III
SELECT a, (SELECT test.a), c FROM test, test2 WHERE test.b = test2.b ORDER BY c;
----
11 11 10
11 11 20
12 12 30
# explicit join
query III
SELECT a, test.b, c FROM test INNER JOIN test2 ON test.b = test2.b ORDER BY c;
----
11 1 10
11 1 20
12 2 30
# explicit join with condition the wrong way around
query III
SELECT a, test.b, c FROM test INNER JOIN test2 ON test2.b = test.b ORDER BY c;
----
11 1 10
11 1 20
12 2 30
# explicit join with additional condition that is no left-right comparison
query III
SELECT a, test.b, c FROM test INNER JOIN test2 ON test2.b = test.b and test.b = 2;
----
12 2 30
# explicit join with additional condition that is constant
query III
SELECT a, test.b, c FROM test INNER JOIN test2 ON test2.b = test.b and 2 = 2 ORDER BY c;
----
11 1 10
11 1 20
12 2 30
# explicit join with only condition that is no left-right comparison
query III
SELECT a, test.b, c FROM test INNER JOIN test2 ON test.b = 2 ORDER BY c;
----
12 2 10
12 2 20
12 2 30
# explicit join with only condition that is constant
query III
SELECT a, test.b, c FROM test INNER JOIN test2 ON NULL = 2;
----
# equality join where both lhs and rhs keys are projected
query II
SELECT * FROM (VALUES (1)) tbl(i) JOIN (VALUES (1)) tbl2(j) ON (i=j);
----
1 1
# equality join where both lhs and rhs keys are projected with filter
query II
SELECT * FROM (VALUES (1), (2)) tbl(i) JOIN (VALUES (1), (2)) tbl2(j) ON (i=j) WHERE i+j=2;
----
1 1

View File

@@ -0,0 +1,32 @@
# name: test/sql/join/inner/test_join_duplicates.test
# description: Test join with > STANDARD_VECTOR_SIZE duplicates
# group: [inner]
statement ok
PRAGMA enable_verification
statement ok
pragma verify_external
statement ok
pragma verify_parallelism
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 1), (12, 2), (13, 3)
statement ok
CREATE TABLE test2 AS SELECT * FROM repeat(1, 10*1024) t1(b), (SELECT 10) t2(c);
query I
SELECT COUNT(*) FROM test2;
----
10240
query I
SELECT COUNT(*) FROM test INNER JOIN test2 ON test.b=test2.b
----
10240

View File

@@ -0,0 +1,39 @@
# name: test/sql/join/inner/test_join_invisible_probe.test_slow
# description: Test joins that would generate a perfect hashtable
# group: [inner]
statement ok
PRAGMA enable_verification
# create the table integers with the values 0..1000
statement ok
CREATE TABLE test3 AS SELECT range r FROM range(0, 1024, 1);
statement ok
CREATE TABLE test4 AS SELECT range r FROM range(0, 1024, 1);
# START LOOP 0..10
loop i 0 9
statement ok
INSERT INTO test4 SELECT * FROM test3;
endloop
query I
select test3.r, test4.r from test3,test4 where test3.r=test4.r order by test3.r, test4.r;
----
20480 values hashing to 35ba7ce9ff11516c6ab6793a3bf802e4
loop i 0 90
statement ok
INSERT INTO test4 SELECT * FROM test3;
endloop
query I
select test3.r, test4.r from test3,test4 where test3.r=test4.r order by test3.r, test4.r;
----
204800 values hashing to 77cdae057078ab7ba8339275f564fac1

View File

@@ -0,0 +1,404 @@
# name: test/sql/join/inner/test_join_is_distinct.test
# description: Test using two join predicates, of which one is IS DISTINCT
# group: [inner]
# issue #8328
statement ok
PRAGMA enable_verification;
statement ok
CREATE TABLE tbl (col0 INTEGER, col1 INTEGER);
statement ok
INSERT INTO tbl VALUES (1, 0), (1, 1);
query II
SELECT x.col1, y.col1 FROM tbl x JOIN tbl y
ON x.col0 = y.col0 AND (x.col1 IS DISTINCT FROM y.col1)
ORDER BY x.col1;
----
0 1
1 0
query II
SELECT x.col1, y.col1 FROM tbl x JOIN tbl y
ON x.col0 = y.col0 AND x.col1 != y.col1
ORDER BY x.col1;
----
0 1
1 0
statement ok
INSERT INTO tbl VALUES (1, 0), (1, 1);
query II
SELECT x.col1, y.col1 FROM tbl x JOIN tbl y
ON x.col0 = y.col0 AND (x.col1 IS DISTINCT FROM y.col1)
ORDER BY x.col1;
----
0 1
0 1
0 1
0 1
1 0
1 0
1 0
1 0
query II
SELECT x.col1, y.col1 FROM tbl x JOIN tbl y
ON x.col0 = y.col0 AND x.col1 != y.col1
ORDER BY x.col1;
----
0 1
0 1
0 1
0 1
1 0
1 0
1 0
1 0
# same but with structs
statement ok
CREATE TABLE tbl_s (col0 STRUCT(x INTEGER), col1 STRUCT(x INTEGER));
statement ok
INSERT INTO tbl_s VALUES ({x: 1}, {x: 0}), ({x: 1}, {x: 1});
query II
SELECT x.col1, y.col1 FROM tbl_s x JOIN tbl_s y
ON x.col0 = y.col0 AND (x.col1 IS DISTINCT FROM y.col1)
ORDER BY x.col1;
----
{'x': 0} {'x': 1}
{'x': 1} {'x': 0}
query II
SELECT x.col1, y.col1 FROM tbl_s x JOIN tbl_s y
ON x.col0 = y.col0 AND x.col1 != y.col1
ORDER BY x.col1;
----
{'x': 0} {'x': 1}
{'x': 1} {'x': 0}
statement ok
INSERT INTO tbl_s VALUES ({x: 1}, {x: 0}), ({x: 1}, {x: 1});
query II
SELECT x.col1, y.col1 FROM tbl_s x JOIN tbl_s y
ON x.col0 = y.col0 AND (x.col1 IS DISTINCT FROM y.col1)
ORDER BY x.col1;
----
{'x': 0} {'x': 1}
{'x': 0} {'x': 1}
{'x': 0} {'x': 1}
{'x': 0} {'x': 1}
{'x': 1} {'x': 0}
{'x': 1} {'x': 0}
{'x': 1} {'x': 0}
{'x': 1} {'x': 0}
query II
SELECT x.col1, y.col1 FROM tbl_s x JOIN tbl_s y
ON x.col0 = y.col0 AND x.col1 != y.col1
ORDER BY x.col1;
----
{'x': 0} {'x': 1}
{'x': 0} {'x': 1}
{'x': 0} {'x': 1}
{'x': 0} {'x': 1}
{'x': 1} {'x': 0}
{'x': 1} {'x': 0}
{'x': 1} {'x': 0}
{'x': 1} {'x': 0}
# same but with lists
statement ok
CREATE TABLE tbl_l (col0 INTEGER[], col1 INTEGER[]);
statement ok
INSERT INTO tbl_l VALUES ([1], [0]), ([1], [1]);
query II
SELECT x.col1, y.col1 FROM tbl_l x JOIN tbl_l y
ON x.col0 = y.col0 AND (x.col1 IS DISTINCT FROM y.col1)
ORDER BY x.col1;
----
[0] [1]
[1] [0]
query II
SELECT x.col1, y.col1 FROM tbl_l x JOIN tbl_l y
ON x.col0 = y.col0 AND x.col1 != y.col1
ORDER BY x.col1;
----
[0] [1]
[1] [0]
statement ok
INSERT INTO tbl_l VALUES ([1], [0]), ([1], [1]);
query II
SELECT x.col1, y.col1 FROM tbl_l x JOIN tbl_l y
ON x.col0 = y.col0 AND (x.col1 IS DISTINCT FROM y.col1)
ORDER BY x.col1;
----
[0] [1]
[0] [1]
[0] [1]
[0] [1]
[1] [0]
[1] [0]
[1] [0]
[1] [0]
query II
SELECT x.col1, y.col1 FROM tbl_l x JOIN tbl_l y
ON x.col0 = y.col0 AND x.col1 != y.col1
ORDER BY x.col1;
----
[0] [1]
[0] [1]
[0] [1]
[0] [1]
[1] [0]
[1] [0]
[1] [0]
[1] [0]
query IIII
WITH abc AS (
SELECT * FROM (
VALUES (1, 'x'), (1, 'x'), (1, '0'), (1, '0')
) AS tbl(col0, col1)
)
SELECT x.col0 AS c1, x.col1 AS c2, y.col0 AS c3, y.col1 AS c4
FROM abc x JOIN abc y ON x.col0 = y.col0
AND (x.col1 IS DISTINCT FROM y.col1)
ORDER BY c1, c2, c3, c4;
----
1 0 1 x
1 0 1 x
1 0 1 x
1 0 1 x
1 x 1 0
1 x 1 0
1 x 1 0
1 x 1 0
# tests with NULLs
statement ok
CREATE TABLE tbl_null (col0 INTEGER, col1 INTEGER);
statement ok
INSERT INTO tbl_null VALUES (1, 0), (1, 1), (1, NULL), (NULL, 1), (0, NULL), (NULL, 0), (NULL, NULL);
query II
SELECT x.col1, y.col1 FROM tbl_null x JOIN tbl_null y
ON x.col0 = y.col0 AND (x.col1 IS DISTINCT FROM y.col1)
ORDER BY x.col1, y.col1;
----
0 1
0 NULL
1 0
1 NULL
NULL 0
NULL 1
query II
SELECT x.col1, y.col1 FROM tbl_null x JOIN tbl_null y
ON x.col0 = y.col0 AND x.col1 != y.col1
ORDER BY x.col1;
----
0 1
1 0
query II
SELECT x.col1, y.col1 FROM tbl_null x JOIN tbl_null y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1;
----
0 0
1 1
NULL NULL
NULL NULL
query II
SELECT x.col1, y.col1 FROM tbl_null x JOIN tbl_null y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1;
----
0 0
1 1
# similar but with structs
statement ok
CREATE TABLE tbl_s_null (col0 STRUCT(x INTEGER), col1 STRUCT(x INTEGER));
statement ok
INSERT INTO tbl_s_null VALUES ({x: 1}, {x: 0}), ({x: 1}, {x: 1}), ({x: 1}, NULL), ({x: 1}, {x: NULL});
query II
SELECT x.col1, y.col1 FROM tbl_s_null x JOIN tbl_s_null y
ON x.col0 = y.col0 AND (x.col1 IS DISTINCT FROM y.col1)
ORDER BY x.col1, y.col1 NULLS LAST;
----
{'x': 0} {'x': 1}
{'x': 0} {'x': NULL}
{'x': 0} NULL
{'x': 1} {'x': 0}
{'x': 1} {'x': NULL}
{'x': 1} NULL
{'x': NULL} {'x': 0}
{'x': NULL} {'x': 1}
{'x': NULL} NULL
NULL {'x': 0}
NULL {'x': 1}
NULL {'x': NULL}
query II
SELECT x.col1, y.col1 FROM tbl_s_null x JOIN tbl_s_null y
ON x.col0 = y.col0 AND x.col1 != y.col1
ORDER BY x.col1.x, y.col1.x NULLS LAST;
----
{'x': 0} {'x': 1}
{'x': 0} {'x': NULL}
{'x': 1} {'x': 0}
{'x': 1} {'x': NULL}
{'x': NULL} {'x': 0}
{'x': NULL} {'x': 1}
query II
SELECT x.col1, y.col1 FROM tbl_s_null x JOIN tbl_s_null y
ON x.col0 = y.col0 AND x.col1 > y.col1
ORDER BY x.col1.x, y.col1.x NULLS LAST;
----
{'x': 1} {'x': 0}
{'x': NULL} {'x': 0}
{'x': NULL} {'x': 1}
query II
SELECT x.col1, y.col1 FROM tbl_s_null x JOIN tbl_s_null y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1;
----
{'x': 0} {'x': 0}
{'x': 1} {'x': 1}
{'x': NULL} {'x': NULL}
NULL NULL
query II
SELECT x.col1, y.col1 FROM tbl_s_null x JOIN tbl_s_null y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1;
----
{'x': 0} {'x': 0}
{'x': 1} {'x': 1}
{'x': NULL} {'x': NULL}
# same but with lists
statement ok
CREATE TABLE tbl_l_null (col0 INTEGER[], col1 INTEGER[]);
statement ok
INSERT INTO tbl_l_null VALUES ([1], [0]), ([1], [1]), ([1], NULL), ([1], [NULL]);
query II
SELECT x.col1, y.col1 FROM tbl_l_null x JOIN tbl_l_null y
ON x.col0 = y.col0 AND (x.col1 IS DISTINCT FROM y.col1)
ORDER BY x.col1, y.col1;
----
[0] [1]
[0] [NULL]
[0] NULL
[1] [0]
[1] [NULL]
[1] NULL
[NULL] [0]
[NULL] [1]
[NULL] NULL
NULL [0]
NULL [1]
NULL [NULL]
query II
SELECT x.col1, y.col1 FROM tbl_l_null x JOIN tbl_l_null y
ON x.col0 = y.col0 AND x.col1 != y.col1
ORDER BY x.col1, y.col1 NULLS LAST;
----
[0] [1]
[0] [NULL]
[1] [0]
[1] [NULL]
[NULL] [0]
[NULL] [1]
query II
SELECT x.col1, y.col1 FROM tbl_l_null x JOIN tbl_l_null y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1;
----
[0] [0]
[1] [1]
[NULL] [NULL]
NULL NULL
query II
SELECT x.col1, y.col1 FROM tbl_l_null x JOIN tbl_l_null y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1;
----
[0] [0]
[1] [1]
[NULL] [NULL]
# duckdb-r issue 8
statement ok
create table tb1 as select range*2 as a from range(100);
statement ok
create table tb2 as select range*4 as a from range(100);
statement ok
insert into tb2 (select NULL from range(20));
statement ok
insert into tb1 (select NULL from range(20));
query I
SELECT count(*) FROM tb1 AS lhs ANTI JOIN tb2 AS rhs ON (lhs.a IS DISTINCT FROM rhs.a);
----
0
# and some coverage
statement ok
create or replace table tb1 as select range*2 as a, range*50 as b from range(2);
statement ok
create or replace table tb2 as select range*4 as a, range*500 as b from range(2);
statement ok
insert into tb2 (select NULL, NULL from range(2));
statement ok
insert into tb1 (select NULL, NULL from range(2));
query II
SELECT lhs.a, rhs.a FROM tb1 AS lhs LEFT JOIN tb2 AS rhs ON (lhs.a IS DISTINCT FROM rhs.a) ORDER BY ALL;
----
0 4
0 NULL
0 NULL
2 0
2 4
2 NULL
2 NULL
NULL 0
NULL 0
NULL 4
NULL 4

View File

@@ -0,0 +1,375 @@
# name: test/sql/join/inner/test_join_is_not_distinct.test
# description: Test using two join predicates, of which one is IS NOT DISTINCT
# group: [inner]
# internal #5264
statement ok
PRAGMA enable_verification;
statement ok
CREATE TABLE tbl (col0 INTEGER, col1 INTEGER);
statement ok
INSERT INTO tbl VALUES (1, 0), (1, 1);
query II
SELECT x.col1, y.col1 FROM tbl x JOIN tbl y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1;
----
0 0
1 1
query II
SELECT x.col1, y.col1 FROM tbl x JOIN tbl y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1;
----
0 0
1 1
statement ok
INSERT INTO tbl VALUES (1, 0), (1, 1);
query II
SELECT x.col1, y.col1 FROM tbl x JOIN tbl y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1;
----
0 0
0 0
0 0
0 0
1 1
1 1
1 1
1 1
query II
SELECT x.col1, y.col1 FROM tbl x JOIN tbl y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1;
----
0 0
0 0
0 0
0 0
1 1
1 1
1 1
1 1
# same but with structs
statement ok
CREATE TABLE tbl_s (col0 STRUCT(x INTEGER), col1 STRUCT(x INTEGER));
statement ok
INSERT INTO tbl_s VALUES ({x: 1}, {x: 0}), ({x: 1}, {x: 1});
query II
SELECT x.col1, y.col1 FROM tbl_s x JOIN tbl_s y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1;
----
{'x': 0} {'x': 0}
{'x': 1} {'x': 1}
query II
SELECT x.col1, y.col1 FROM tbl_s x JOIN tbl_s y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1;
----
{'x': 0} {'x': 0}
{'x': 1} {'x': 1}
statement ok
INSERT INTO tbl_s VALUES ({x: 1}, {x: 0}), ({x: 1}, {x: 1});
query II
SELECT x.col1, y.col1 FROM tbl_s x JOIN tbl_s y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1;
----
{'x': 0} {'x': 0}
{'x': 0} {'x': 0}
{'x': 0} {'x': 0}
{'x': 0} {'x': 0}
{'x': 1} {'x': 1}
{'x': 1} {'x': 1}
{'x': 1} {'x': 1}
{'x': 1} {'x': 1}
query II
SELECT x.col1, y.col1 FROM tbl_s x JOIN tbl_s y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1;
----
{'x': 0} {'x': 0}
{'x': 0} {'x': 0}
{'x': 0} {'x': 0}
{'x': 0} {'x': 0}
{'x': 1} {'x': 1}
{'x': 1} {'x': 1}
{'x': 1} {'x': 1}
{'x': 1} {'x': 1}
# same but with lists
statement ok
CREATE TABLE tbl_l (col0 INTEGER[], col1 INTEGER[]);
statement ok
INSERT INTO tbl_l VALUES ([1], [0]), ([1], [1]);
query II
SELECT x.col1, y.col1 FROM tbl_l x JOIN tbl_l y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1;
----
[0] [0]
[1] [1]
query II
SELECT x.col1, y.col1 FROM tbl_l x JOIN tbl_l y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1;
----
[0] [0]
[1] [1]
statement ok
INSERT INTO tbl_l VALUES ([1], [0]), ([1], [1]);
query II
SELECT x.col1, y.col1 FROM tbl_l x JOIN tbl_l y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1;
----
[0] [0]
[0] [0]
[0] [0]
[0] [0]
[1] [1]
[1] [1]
[1] [1]
[1] [1]
query II
SELECT x.col1, y.col1 FROM tbl_l x JOIN tbl_l y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1;
----
[0] [0]
[0] [0]
[0] [0]
[0] [0]
[1] [1]
[1] [1]
[1] [1]
[1] [1]
query IIII
WITH abc AS (
SELECT * FROM (
VALUES (1, 'x'), (1, 'x'), (1, '0'), (1, '0')
) AS tbl(col0, col1)
)
SELECT x.col0 AS c1, x.col1 AS c2, y.col0 AS c3, y.col1 AS c4
FROM abc x JOIN abc y ON x.col0 = y.col0
AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY c1, c2, c3, c4;
----
1 0 1 0
1 0 1 0
1 0 1 0
1 0 1 0
1 x 1 x
1 x 1 x
1 x 1 x
1 x 1 x
# tests with NULLs
statement ok
CREATE TABLE tbl_null (col0 INTEGER, col1 INTEGER);
statement ok
INSERT INTO tbl_null VALUES (1, 0), (1, 1), (1, NULL), (NULL, 1), (0, NULL), (NULL, 0), (NULL, NULL);
query II
SELECT x.col1, y.col1 FROM tbl_null x JOIN tbl_null y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1, y.col1;
----
0 0
1 1
NULL NULL
NULL NULL
query II
SELECT x.col1, y.col1 FROM tbl_null x JOIN tbl_null y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1;
----
0 0
1 1
query II
SELECT x.col1, y.col1 FROM tbl_null x JOIN tbl_null y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1;
----
0 0
1 1
NULL NULL
NULL NULL
query II
SELECT x.col1, y.col1 FROM tbl_null x JOIN tbl_null y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1;
----
0 0
1 1
# similar but with structs
statement ok
CREATE TABLE tbl_s_null (col0 STRUCT(x INTEGER), col1 STRUCT(x INTEGER));
statement ok
INSERT INTO tbl_s_null VALUES ({x: 1}, {x: 0}), ({x: 1}, {x: 1}), ({x: 1}, NULL), ({x: 1}, {x: NULL});
query II
SELECT x.col1, y.col1 FROM tbl_s_null x JOIN tbl_s_null y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1, y.col1 NULLS LAST;
----
{'x': 0} {'x': 0}
{'x': 1} {'x': 1}
{'x': NULL} {'x': NULL}
NULL NULL
query II
SELECT x.col1, y.col1 FROM tbl_s_null x JOIN tbl_s_null y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1.x, y.col1.x NULLS LAST;
----
{'x': 0} {'x': 0}
{'x': 1} {'x': 1}
{'x': NULL} {'x': NULL}
query II
SELECT x.col1, y.col1 FROM tbl_s_null x JOIN tbl_s_null y
ON x.col0 = y.col0 AND x.col1 > y.col1
ORDER BY x.col1.x, y.col1.x NULLS LAST;
----
{'x': 1} {'x': 0}
{'x': NULL} {'x': 0}
{'x': NULL} {'x': 1}
query II
SELECT x.col1, y.col1 FROM tbl_s_null x JOIN tbl_s_null y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1;
----
{'x': 0} {'x': 0}
{'x': 1} {'x': 1}
{'x': NULL} {'x': NULL}
NULL NULL
query II
SELECT x.col1, y.col1 FROM tbl_s_null x JOIN tbl_s_null y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1;
----
{'x': 0} {'x': 0}
{'x': 1} {'x': 1}
{'x': NULL} {'x': NULL}
# same but with lists
statement ok
CREATE TABLE tbl_l_null (col0 INTEGER[], col1 INTEGER[]);
statement ok
INSERT INTO tbl_l_null VALUES ([1], [0]), ([1], [1]), ([1], NULL), ([1], [NULL]);
query II
SELECT x.col1, y.col1 FROM tbl_l_null x JOIN tbl_l_null y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1, y.col1;
----
[0] [0]
[1] [1]
[NULL] [NULL]
NULL NULL
query II
SELECT x.col1, y.col1 FROM tbl_l_null x JOIN tbl_l_null y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1, y.col1 NULLS LAST;
----
[0] [0]
[1] [1]
[NULL] [NULL]
query II
SELECT x.col1, y.col1 FROM tbl_l_null x JOIN tbl_l_null y
ON x.col0 = y.col0 AND (x.col1 IS NOT DISTINCT FROM y.col1)
ORDER BY x.col1;
----
[0] [0]
[1] [1]
[NULL] [NULL]
NULL NULL
query II
SELECT x.col1, y.col1 FROM tbl_l_null x JOIN tbl_l_null y
ON x.col0 = y.col0 AND x.col1 = y.col1
ORDER BY x.col1;
----
[0] [0]
[1] [1]
[NULL] [NULL]
# duckdb-r issue 8
statement ok
create table tb1 as select range*2 as a from range(100);
statement ok
create table tb2 as select range*4 as a from range(100);
statement ok
insert into tb2 (select NULL from range(20));
statement ok
insert into tb1 (select NULL from range(20));
query I
SELECT count(*) FROM tb1 AS lhs ANTI JOIN tb2 AS rhs ON (lhs.a IS NOT DISTINCT FROM rhs.a);
----
50
# and some coverage
statement ok
create or replace table tb1 as select range*2 as a, range*50 as b from range(2);
statement ok
create or replace table tb2 as select range*4 as a, range*500 as b from range(2);
statement ok
insert into tb2 (select NULL, NULL from range(2));
statement ok
insert into tb1 (select NULL, NULL from range(2));
query II
SELECT lhs.a, rhs.a FROM tb1 AS lhs LEFT JOIN tb2 AS rhs ON (lhs.a IS NOT DISTINCT FROM rhs.a) ORDER BY ALL;
----
0 0
2 NULL
NULL NULL
NULL NULL
NULL NULL
NULL NULL

View File

@@ -0,0 +1,248 @@
# name: test/sql/join/inner/test_join_perfect_hash.test_slow
# description: Test joins that would generate a perfect hashtable
# group: [inner]
statement ok
SET default_null_order='nulls_first';
statement ok
PRAGMA enable_verification
foreach type <numeric> DECIMAL(4,0) DECIMAL(8,0) DECIMAL(16,0) DECIMAL(32,0)
statement ok
CREATE TABLE test1 (a ${type}, b ${type});
statement ok
INSERT INTO test1 VALUES (11, 1), (12, 2), (13, 3)
statement ok
CREATE TABLE test2 (b ${type}, c ${type});
statement ok
INSERT INTO test2 VALUES (1, 10), (2, 20), (3, 30), (1, 10), (2, 20), (3, 30), (1, 10), (2, 20), (3, 30), (1, 10), (2, 20), (3, 30), (1, 10), (2, 20), (3, 30)
# simple inner join
query III
SELECT a, test1.b,c FROM test1, test2 WHERE test1.b = test2.b order by a, test1.b,c;
----
11 1 10
11 1 10
11 1 10
11 1 10
11 1 10
12 2 20
12 2 20
12 2 20
12 2 20
12 2 20
13 3 30
13 3 30
13 3 30
13 3 30
13 3 30
statement ok
DROP TABLE test1;
statement ok
DROP TABLE test2;
endloop
foreach type TINYINT SMALLINT INTEGER BIGINT
statement ok
CREATE OR REPLACE TABLE test3 (a ${type}, b ${type});
statement ok
INSERT INTO test3 VALUES (-11, -1), (-12, -2), (13, 3)
statement ok
CREATE OR REPLACE TABLE test4 (b ${type}, c ${type});
statement ok
INSERT INTO test4 VALUES (-1, -10), (-2, -20), (3, 30), (-1, -10), (-2, -20), (3, 30), (-1, -10), (-2, -20), (3, 30), (-1, -10), (-2, -20), (3, 30), (-1, -10), (-2, -20), (3, 30)
# negative keys inner join
query III
SELECT a, test3.b,c FROM test3, test4 WHERE test3.b = test4.b order by a, test3.b,c ;
----
-12 -2 -20
-12 -2 -20
-12 -2 -20
-12 -2 -20
-12 -2 -20
-11 -1 -10
-11 -1 -10
-11 -1 -10
-11 -1 -10
-11 -1 -10
13 3 30
13 3 30
13 3 30
13 3 30
13 3 30
endloop
foreach type <integral>
statement ok
CREATE OR REPLACE TABLE test5 (a ${type}, b ${type});
statement ok
INSERT INTO test5 VALUES (11, 1), (12, 2), (13, 3), (14, null), (null, 4)
statement ok
CREATE OR REPLACE TABLE test6 (b ${type}, c ${type});
statement ok
INSERT INTO test6 VALUES (1, 10), (2, 20), (3, 30), (1, 10), (2, 20), (3, 30), (1, 10), (2, 20), (3, 30), (1, 10), (2, 20), (3, 30), (1, 10), (2, 20), (3, 30), (4, 40), (null, 30), (1, null)
# inner join with nulls in the build and probe side
query III
SELECT a, test5.b,c FROM test5, test6 WHERE test5.b = test6.b order by a, test5.b,c;
----
NULL 4 40
11 1 NULL
11 1 10
11 1 10
11 1 10
11 1 10
11 1 10
12 2 20
12 2 20
12 2 20
12 2 20
12 2 20
13 3 30
13 3 30
13 3 30
13 3 30
13 3 30
statement ok
CREATE OR REPLACE TABLE test7 (a ${type}, b ${type});
statement ok
INSERT INTO test7 VALUES (11, 1), (12, 2), (13, 3), (15, 5)
statement ok
CREATE OR REPLACE TABLE test8 (b ${type}, c ${type});
statement ok
INSERT INTO test8 VALUES (1, 10), (2, 20), (3, 30), (1, 10), (2, 20), (3, 30), (1, 10), (2, 20), (3, 30), (1, 10), (2, 20), (3, 30), (1, 10), (2, 20), (3, 30), (4, 40)
# inner join with non-matching keys in the build and in the probe side
query III
SELECT a, test7.b,c FROM test7, test8 WHERE test7.b = test8.b order by a, test7.b,c ;
----
11 1 10
11 1 10
11 1 10
11 1 10
11 1 10
12 2 20
12 2 20
12 2 20
12 2 20
12 2 20
13 3 30
13 3 30
13 3 30
13 3 30
13 3 30
endloop
# create the table integers with the values 0..1026
statement ok
CREATE TABLE test9 AS SELECT range r FROM range(0, 1026, 1);
statement ok
CREATE TABLE test10 AS SELECT range r FROM range(0, 1025, 1);
# START LOOP 0..9
loop i 0 9
statement ok
INSERT INTO test10 SELECT * FROM test9;
endloop
# inner join with bigger than vector size tuples
query I
select test9.r, test10.r from test9,test10 where test9.r=test10.r order by test9.r, test10.r;
----
20518 values hashing to 43cfa09ff243deb128dd2bbcbb30527c
statement ok
CREATE TABLE test11 (a INTEGER, b INTEGER);
statement ok
INSERT INTO test11 VALUES (1, 1), (50000, 2), (13, 3), (NULL, NULL), (NULL, 20000), (20000, NULL)
statement ok
CREATE TABLE test12 (b INTEGER, c INTEGER);
statement ok
INSERT INTO test12 VALUES (1, 10), (2, 20), (50000, 30), (NULL, NULL), (20000, NULL), (NULL, 20000)
# simple inner join
query III
SELECT a, test11.b,c FROM test11, test12 WHERE test11.b = test12.b order by a, test11.b,c;
----
NULL 20000 NULL
1 1 10
50000 2 20
statement ok
CREATE TABLE cohort (
cohort_definition_id INTEGER,
subject_id INTEGER,
cohort_start_date DATE,
cohort_end_date DATE,
);
statement ok
INSERT INTO cohort VALUES
(100, 1, '2002-12-25', '2002-12-25'),
(100, 1, '2007-03-01', '2007-03-01'),
(100, 2, '2003-03-01', '2003-03-01'),
(100, 2, '2005-03-01', '2005-03-01'),
;
statement ok
CREATE TABLE observation_period (
observation_period_id INTEGER,
person_id INTEGER,
observation_period_start_date DATE,
observation_period_end_date DATE,
period_type_concept_id INTEGER,
);
statement ok
INSERT INTO observation_period VALUES
(1, 1, '1963-12-31', '2010-01-01', 1),
(2, 2, '1963-12-31', '2010-01-01', 2),
;
# Statistics propagation with condition pruning
query IIIIIIII
select cohort_definition_id, subject_id, cohort_start_date, cohort_end_date, op1.observation_period_start_date, op1.observation_period_end_date,
tc1.cohort_start_date >= op1.observation_period_start_date as gt_test,
tc1.cohort_start_date <= op1.observation_period_end_date as lt_test
from main.cohort tc1
inner join main.observation_period op1
on tc1.subject_id = op1.person_id
and tc1.cohort_start_date >= op1.observation_period_start_date
and tc1.cohort_start_date <= op1.observation_period_end_date
where cohort_definition_id in (100) order by subject_id, cohort_start_date;
----
100 1 2002-12-25 2002-12-25 1963-12-31 2010-01-01 true true
100 1 2007-03-01 2007-03-01 1963-12-31 2010-01-01 true true
100 2 2003-03-01 2003-03-01 1963-12-31 2010-01-01 true true
100 2 2005-03-01 2005-03-01 1963-12-31 2010-01-01 true true

View File

@@ -0,0 +1,78 @@
# name: test/sql/join/inner/test_join_types.test_slow
# description: Test joins with different types
# group: [inner]
statement ok
PRAGMA enable_verification
statement ok
pragma verify_external
# numeric types
foreach type <numeric> decimal(4,1) decimal(8,1) decimal(12,1) decimal(18,1)
statement ok
begin transaction
statement ok
create table a as select i::${type} AS i from range(1, 101, 1) t1(i)
# range joins
query IR
select count(*), sum(i) from a, (SELECT 100::${type} AS j) b where i < j
----
99 4950.000000
query I
select count(*) from a, (SELECT 100::${type} AS j) b where i <= j
----
100
query I
select count(*) from a, (SELECT 1::${type} AS j) b where i > j
----
99
query I
select count(*) from a, (SELECT 1::${type} AS j) b where i >= j
----
100
# inequality join
query I
select count(*) from a, (SELECT 1::${type} AS j) b where i <> j
----
99
query I
select count(*) from a, (SELECT 1::${type} AS j) b where i <> j AND i=j
----
0
# equality join
query I
select count(*) from a, (SELECT 1::${type} AS j) b where i = j
----
1
# no results on one side
query I
select count(*) from a, (SELECT 1::${type} AS j) b where i > j AND i>120
----
0
query I
select count(*) from a, (SELECT 1::${type} AS j) b where i <> j AND i>120
----
0
query I
select count(*) from a, (SELECT 1::${type} AS j) b where i = j AND i>120
----
0
statement ok
rollback
endloop

View File

@@ -0,0 +1,35 @@
# name: test/sql/join/inner/test_join_with_nulls.test_slow
# description: Test joins on uint64 columns with NULL values
# group: [inner]
set seed 0.42
statement ok
PRAGMA enable_verification
statement ok
PRAGMA disable_optimizer;
statement ok
CREATE OR REPLACE TABLE build AS (SELECT if(random() < 0.1,null, CAST(round(random() * 1_000_000) as INT64)) as key FROM range(1_000_000))
statement ok
CREATE OR REPLACE TABLE probe AS (SELECT if(random() < 0.1,null, CAST(round(random() * 1_000_000) as INT64)) as key FROM range(4_000_000))
query II
SELECT COUNT(*), SUM(probe.key) FROM probe JOIN build ON probe.key = build.key;
----
3239239 1617830750716
statement ok
CREATE OR REPLACE TABLE build2 AS (SELECT if(CAST(round(random() * 400_000) as INT64) < 10, null, CAST(round(random() * 400_000) as INT64)) as key FROM range(500_000));
query II
SELECT COUNT(*), SUM(probe.key) FROM probe JOIN build2 ON probe.key = build2.key;
----
1801809 360752228491
query II
SELECT COUNT(*), SUM(probe.key) FROM probe JOIN build2 ON probe.key IS NOT DISTINCT FROM build2.key;
----
5393349 360752228491

View File

@@ -0,0 +1,30 @@
# name: test/sql/join/inner/test_lt_join.test
# description: Test less than join
# group: [inner]
statement ok
PRAGMA enable_verification
statement ok
create table a AS SELECT i FROM range(1, 2001, 1) t1(i)
query I
select count(*) from a, (SELECT 2000 AS j) b where i < j
----
1999
query I
select count(*) from a, (SELECT 2000 AS j) b where i <= j
----
2000
query I
select count(*) from a, (SELECT 1 AS j) b where i > j
----
1999
query I
select count(*) from a, (SELECT 1 AS j) b where i >= j
----
2000

View File

@@ -0,0 +1,82 @@
# name: test/sql/join/inner/test_range_join.test
# description: Test range joins
# group: [inner]
statement ok
PRAGMA enable_verification
# create tables
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 1), (12, 2), (13, 3)
statement ok
CREATE TABLE test2 (b INTEGER, c INTEGER);
statement ok
INSERT INTO test2 VALUES (1, 10), (1, 20), (2, 30)
query II
SELECT test.b, test2.b FROM test, test2 WHERE test.b<test2.b
----
1 2
query II
SELECT test.b, test2.b FROM test, test2 WHERE test.b <= test2.b ORDER BY 1,2
----
1 1
1 1
1 2
2 2
# range join on multiple predicates
query IIII
SELECT test.a, test.b, test2.b, test2.c FROM test, test2 WHERE test.a>test2.c AND test.b <= test2.b
----
11 1 1 10
# introduce some NULL values
statement ok
INSERT INTO test VALUES (11, NULL), (NULL, 1)
# join result should be unchanged
query IIII
SELECT test.a, test.b, test2.b, test2.c FROM test, test2 WHERE test.a>test2.c AND test.b <= test2.b
----
11 1 1 10
# on the RHS as well
statement ok
INSERT INTO test2 VALUES (1, NULL), (NULL, 10)
# join result should be unchanged
query IIII
SELECT test.a, test.b, test2.b, test2.c FROM test, test2 WHERE test.a>test2.c AND test.b <= test2.b
----
11 1 1 10
# Forced external
statement ok
PRAGMA debug_force_external=true;
# In memory unswizzling
statement ok
CREATE TABLE issue4419 (x INT, y VARCHAR);
statement ok
INSERT INTO issue4419 VALUES (1, 'sssssssssssssssssueufuheuooefef');
statement ok
INSERT INTO issue4419 VALUES (2, 'sssssssssssssssssueufuheuooefesffff');
statement ok
INSERT INTO issue4419 VALUES (2, 'sssssssssssssssssueufuheuooefesffffsssssssieiffih');
query IIII
SELECT * FROM issue4419 t1 INNER JOIN issue4419 t2 ON t1.x < t2.x;
----
1 sssssssssssssssssueufuheuooefef 2 sssssssssssssssssueufuheuooefesffff
1 sssssssssssssssssueufuheuooefef 2 sssssssssssssssssueufuheuooefesffffsssssssieiffih

View File

@@ -0,0 +1,83 @@
# name: test/sql/join/inner/test_unequal_join.test
# description: Test inequality join
# group: [inner]
statement ok
PRAGMA enable_verification
# create tables
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 1), (12, 2), (13, 3)
statement ok
CREATE TABLE test2 (b INTEGER, c INTEGER);
statement ok
INSERT INTO test2 VALUES (1, 10), (1, 20), (2, 30)
# inequality join
query II
SELECT test.b, test2.b FROM test, test2 WHERE test.b <> test2.b ORDER BY test.b, test2.b
----
1 2
2 1
2 1
3 1
3 1
3 2
# inequality join with filter
query II
SELECT test.b, test2.b FROM test, test2 WHERE test.b <> test2.b AND test.b <> 1 AND test2.b <> 2 ORDER BY test.b, test2.b
----
2 1
2 1
3 1
3 1
statement ok
INSERT INTO test VALUES (NULL, NULL)
statement ok
INSERT INTO test2 VALUES (NULL, NULL)
# inequality join with NULL values
query II
SELECT test.b, test2.b FROM test, test2 WHERE test.b <> test2.b ORDER BY test.b, test2.b
----
1 2
2 1
2 1
3 1
3 1
3 2
# inequality join with filter and NULL values
query II
SELECT test.b, test2.b FROM test, test2 WHERE test.b <> test2.b AND test.b <> 1 AND test2.b <> 2 ORDER BY test.b, test2.b
----
2 1
2 1
3 1
3 1
statement ok
create table a (i integer)
statement ok
insert into a values ('28579'),('16098'),('25281'),('28877'),('18048'),('26820'),('26971'),('22812'),('11757'),('21851'),('27752'),('28354'),('29843'),('28828'),('16668'),('20534'),('28222'),('24244'),('28877'),('20150'),('23451'),('23683'),('20419'),('28048'),('24244'),('28605'),('25752'),('24466'),('26557'),('16098'),('29454'),('24854'),('13298'),('29584'),('13394'),('24843'),('22477'),('14593'),('24244'),('28722'),('25124'),('16668'),('26787'),('28877'),('27752'),('28482'),('24408'),('25752'),('24136'),('28222'),('17683'),('24244'),('19275'),('21087'),('26594'),('22293'),('25281'),('12898'),('23451'),('12898'),('21757'),('20965'),('25709'),('26614'),('10399'),('28773'),('11933'),('29584'),('29003'),('26871'),('17746'),('24092'),('26192'),('19310'),('10965'),('29275'),('20191'),('29101'),('28059'),('29584'),('20399'),('24338'),('26192'),('25124'),('28605'),('13003'),('16668'),('23511'),('26534'),('24107')
statement ok
create table b (j integer)
statement ok
insert into b values ('31904'),('31904'),('31904'),('31904'),('35709'),('31904'),('31904'),('35709'),('31904'),('31904'),('31904'),('31904')
query I
select count(*) from a,b where i <> j
----
1080

View File

@@ -0,0 +1,26 @@
# name: test/sql/join/inner/test_unequal_join_duplicates.test
# description: Test inequality join with > STANDARD_VECTOR_SIZE duplicates
# group: [inner]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE test (b INTEGER);
statement ok
INSERT INTO test VALUES (1), (2)
statement ok
CREATE TABLE test2 AS SELECT * FROM repeat(1, 10*1024) t1(b);
query I
SELECT COUNT(*) FROM test2;
----
10240
query I
SELECT COUNT(*) FROM test INNER JOIN test2 ON test.b<>test2.b
----
10240

View File

@@ -0,0 +1,75 @@
# name: test/sql/join/inner/test_using_chain.test
# description: Test chaining USING joins
# group: [inner]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE t1 (a INTEGER, b INTEGER)
statement ok
INSERT INTO t1 VALUES (1, 2)
statement ok
CREATE TABLE t2 (b INTEGER, c INTEGER)
statement ok
INSERT INTO t2 VALUES (2, 3)
statement ok
CREATE TABLE t3 (c INTEGER, d INTEGER)
statement ok
INSERT INTO t3 VALUES (3, 4)
# multiple joins with using
# single column
query IIII
SELECT * FROM t1 JOIN t2 USING (b) JOIN t3 USING (c) ORDER BY 1, 2, 3, 4;
----
1 2 3 4
# column does not exist on left side of join
statement error
SELECT * FROM t1 JOIN t2 USING (c)
----
# column does not exist on right side of join
statement error
SELECT * FROM t1 JOIN t2 USING (a)
----
statement ok
DROP TABLE t1
statement ok
DROP TABLE t2
statement ok
DROP TABLE t3
statement ok
CREATE TABLE t1 (a INTEGER, b INTEGER, c INTEGER)
statement ok
INSERT INTO t1 VALUES (1, 2, 2)
statement ok
CREATE TABLE t2 (b INTEGER, c INTEGER, d INTEGER, e INTEGER)
statement ok
INSERT INTO t2 VALUES (2, 2, 3, 4)
statement ok
CREATE TABLE t3 (d INTEGER, e INTEGER)
statement ok
INSERT INTO t3 VALUES (3, 4)
# multi column
query IIIII
SELECT * FROM t1 JOIN t2 USING (b, c) JOIN t3 USING (d, e);
----
1 2 2 3 4

View File

@@ -0,0 +1,102 @@
# name: test/sql/join/inner/test_using_join.test
# description: Test USING joins
# group: [inner]
statement ok
PRAGMA enable_verification
# create tables
statement ok
CREATE TABLE t1 (a INTEGER, b INTEGER, c INTEGER);
statement ok
INSERT INTO t1 VALUES (1,2,3);
statement ok
CREATE TABLE t2 (a INTEGER, b INTEGER, c INTEGER);
statement ok
INSERT INTO t2 VALUES (1,2,3), (2,2,4), (1,3,4);
query IIIIIII
SELECT * FROM t1 JOIN t2 USING(a) JOIN t2 t2b USING (a) ORDER BY 1, 2, 3, 4, 5, 6, 7;
----
1 2 3 2 3 2 3
1 2 3 2 3 3 4
1 2 3 3 4 2 3
1 2 3 3 4 3 4
# USING join
query III
SELECT t2.a, t2.b, t2.c FROM t1 JOIN t2 USING(a) ORDER BY t2.b
----
1 2 3
1 3 4
query III
SELECT t2.a, t2.b, t2.c FROM t1 JOIN t2 USING(b) ORDER BY t2.c
----
1 2 3
2 2 4
query III
SELECT t2.a, t2.b, t2.c FROM t1 JOIN t2 USING(a,b)
----
1 2 3
query III
SELECT t2.a, t2.b, t2.c FROM t1 JOIN t2 USING(a,b,c)
----
1 2 3
# USING columns can be used without requiring a table specifier
query I
SELECT a+1 FROM t1 JOIN t2 USING(a) ORDER BY a
----
2
2
statement error
SELECT t2.a, t2.b, t2.c FROM t1 JOIN t2 USING(a+b)
----
Parser Error: syntax error at or near "+"
statement error
SELECT t2.a, t2.b, t2.c FROM t1 JOIN t2 USING("")
----
Parser Error: zero-length delimited identifier at or near """"
statement error
SELECT t2.a, t2.b, t2.c FROM t1 JOIN t2 USING(d)
----
statement error
SELECT t2.a, t2.b, t2.c FROM t1 JOIN t2 USING(t1.a)
----
Parser Error: syntax error at or near "."
query IIII
SELECT * FROM t1 JOIN t2 USING(a,b)
----
1 2 3 3
# CONTROVERSIAL:
# we do not allow this because it is ambiguous: "b" can be bind to both "t1.b" or "t2.b" and this would give
# different results SQLite allows this, PostgreSQL does not
statement error
SELECT * FROM t1 JOIN t2 USING(a) JOIN t2 t2b USING (b);
----
# this is the same, but now with a duplicate potential binding on the RHS
statement error
select * from (values (1)) tbl(i) join ((values (1)) tbl2(i) join (values (1)) tbl3(i) on tbl2.i=tbl3.i) using (i)
----
# a chain with the same column name is allowed though!
query IIIIIII
SELECT * FROM t1 JOIN t2 USING(a) JOIN t2 t2b USING (a) ORDER BY 1, 2, 3, 4, 5, 6, 7
----
1 2 3 2 3 2 3
1 2 3 2 3 3 4
1 2 3 3 4 2 3
1 2 3 3 4 3 4

View File

@@ -0,0 +1,27 @@
# name: test/sql/join/inner/test_varchar_join.test
# description: Test joins on VARCHAR columns with NULL values
# group: [inner]
statement ok
PRAGMA enable_verification
query TT
select * from (select NULL::varchar as b) sq1, (select 'asdf' as b) sq2 where sq1.b = sq2.b;
----
query ITIT
select * from (select 42 as a, NULL::varchar as b) sq1, (select 42 as a, 'asdf' as b) sq2 where sq1.b <> sq2.b;
----
query ITIT
select * from (select 42 as a, NULL::varchar as b) sq1, (select 42 as a, 'asdf' as b) sq2 where sq1.a=sq2.a and sq1.b <> sq2.b;
----
query ITIT
select * from (select 42 as a, 'asdf' as b) sq2, (select 42 as a, NULL::varchar as b) sq1 where sq1.b <> sq2.b;
----
query ITIT
select * from (select 42 as a, 'asdf' as b) sq2, (select 42 as a, NULL::varchar as b) sq1 where sq1.a=sq2.a and sq1.b <> sq2.b;
----