2021-09-12 12:35:27 +00:00
-- Tags: long
2021-02-19 11:17:15 +00:00
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
CREATE TABLE t1 (a UInt16, b UInt16) ENGINE = TinyLog;
CREATE TABLE t2 (a Int16, b Nullable(Int64)) ENGINE = TinyLog;
INSERT INTO t1 SELECT number as a, 100 + number as b FROM system.numbers LIMIT 1, 10;
INSERT INTO t2 SELECT number - 5 as a, 200 + number - 5 as b FROM system.numbers LIMIT 1, 10;
2022-09-26 13:47:29 +00:00
{% macro is_implemented(join_algorithm) -%}
{% if join_algorithm == 'grace_hash' %} -- { serverError NOT_IMPLEMENTED } {% endif %}
{% endmacro -%}
2022-09-07 16:38:47 +00:00
{% for join_algorithm in ['hash', 'partial_merge', 'auto', 'full_sorting_merge', 'grace_hash'] -%}
2021-02-19 11:17:15 +00:00
2022-09-07 16:38:47 +00:00
SELECT '=== {{ join_algorithm }} ===';
SET join_algorithm = '{{ join_algorithm }}';
2021-02-19 11:17:15 +00:00
2022-09-07 16:38:47 +00:00
{% if join_algorithm == 'auto' -%}
2021-02-19 11:17:15 +00:00
SET max_bytes_in_join = 100;
2022-06-23 13:55:15 +00:00
{% else %}
SET max_bytes_in_join = '100M';
2021-07-20 13:41:24 +00:00
{% endif -%}
2021-02-19 11:17:15 +00:00
SELECT '= full =';
2022-09-26 13:47:29 +00:00
SELECT a, b, t2.b FROM t1 FULL JOIN t2 USING (a) ORDER BY (a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT '= left =';
SELECT a, b, t2.b FROM t1 LEFT JOIN t2 USING (a) ORDER BY (a);
SELECT '= right =';
2022-09-26 13:47:29 +00:00
SELECT a, b, t2.b FROM t1 RIGHT JOIN t2 USING (a) ORDER BY (a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT '= inner =';
SELECT a, b, t2.b FROM t1 INNER JOIN t2 USING (a) ORDER BY (a);
SELECT '= full =';
2022-09-26 13:47:29 +00:00
SELECT a, t1.a, t2.a FROM t1 FULL JOIN t2 USING (a) ORDER BY (t1.a, t2.a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT '= left =';
SELECT a, t1.a, t2.a FROM t1 LEFT JOIN t2 USING (a) ORDER BY (t1.a, t2.a);
SELECT '= right =';
2022-09-26 13:47:29 +00:00
SELECT a, t1.a, t2.a FROM t1 RIGHT JOIN t2 USING (a) ORDER BY (t1.a, t2.a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT '= inner =';
SELECT a, t1.a, t2.a FROM t1 INNER JOIN t2 USING (a) ORDER BY (t1.a, t2.a);
SELECT '= join on =';
SELECT '= full =';
2022-09-26 13:47:29 +00:00
SELECT a, b, t2.a, t2.b FROM t1 FULL JOIN t2 ON (t1.a == t2.a) ORDER BY (t1.a, t2.a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT '= left =';
SELECT a, b, t2.a, t2.b FROM t1 LEFT JOIN t2 ON (t1.a == t2.a) ORDER BY (t1.a, t2.a);
SELECT '= right =';
2022-09-26 13:47:29 +00:00
SELECT a, b, t2.a, t2.b FROM t1 RIGHT JOIN t2 ON (t1.a == t2.a) ORDER BY (t1.a, t2.a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT '= inner =';
SELECT a, b, t2.a, t2.b FROM t1 INNER JOIN t2 ON (t1.a == t2.a) ORDER BY (t1.a, t2.a);
SELECT '= full =';
2022-09-26 13:47:29 +00:00
SELECT * FROM t1 FULL JOIN t2 ON (t1.a + t1.b = t2.a + t2.b - 100) ORDER BY (t1.a, t2.a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT '= left =';
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a + t1.b = t2.a + t2.b - 100) ORDER BY (t1.a, t2.a);
SELECT '= right =';
2022-09-26 13:47:29 +00:00
SELECT * FROM t1 RIGHT JOIN t2 ON (t1.a + t1.b = t2.a + t2.b - 100) ORDER BY (t1.a, t2.a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT '= inner =';
SELECT * FROM t1 INNER JOIN t2 ON (t1.a + t1.b = t2.a + t2.b - 100) ORDER BY (t1.a, t2.a);
-- Int64 and UInt64 has no supertype
SELECT * FROM t1 FULL JOIN t2 ON (t1.a + t1.b + 100 = t2.a + t2.b) ORDER BY (t1.a, t2.a); -- { serverError 53 }
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a + t1.b + 100 = t2.a + t2.b) ORDER BY (t1.a, t2.a); -- { serverError 53 }
SELECT * FROM t1 RIGHT JOIN t2 ON (t1.a + t1.b + 100 = t2.a + t2.b) ORDER BY (t1.a, t2.a); -- { serverError 53 }
SELECT * FROM t1 INNER JOIN t2 ON (t1.a + t1.b + 100 = t2.a + t2.b) ORDER BY (t1.a, t2.a); -- { serverError 53 }
SELECT '= agg =';
2022-09-26 13:47:29 +00:00
SELECT sum(a) == 7 FROM t1 FULL JOIN t2 USING (a) WHERE b > 102 AND t2.b <= 204; {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT sum(a) == 7 FROM t1 INNER JOIN t2 USING (a) WHERE b > 102 AND t2.b <= 204;
SELECT sum(b) = 103 FROM t1 LEFT JOIN t2 USING (a) WHERE b > 102 AND t2.b < 204;
2022-09-26 13:47:29 +00:00
SELECT sum(t2.b) = 203 FROM t1 RIGHT JOIN t2 USING (a) WHERE b > 102 AND t2.b < 204; {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
2022-09-26 13:47:29 +00:00
SELECT sum(a) == 2 + 3 + 4 FROM t1 FULL JOIN t2 ON (t1.a + t1.b = t2.a + t2.b - 100) WHERE t1.b < 105 AND t2.b > 201; {{ is_implemented(join_algorithm) }}
SELECT sum(a) == 55 FROM t1 FULL JOIN t2 ON (t1.a + t1.b = t2.a + t2.b - 100) WHERE 1; {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
2022-09-26 13:47:29 +00:00
SELECT a > 0, sum(a), sum(b) FROM t1 FULL JOIN t2 USING (a) GROUP BY (a > 0) ORDER BY a > 0; {{ is_implemented(join_algorithm) }}
SELECT a > 0, sum(a), sum(t2.a), sum(b), sum(t2.b) FROM t1 FULL JOIN t2 ON (t1.a == t2.a) GROUP BY (a > 0) ORDER BY a > 0; {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT '= types =';
2022-09-26 13:47:29 +00:00
SELECT any(toTypeName(a)) == 'Int32' AND any(toTypeName(t2.a)) == 'Int32' FROM t1 FULL JOIN t2 USING (a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT any(toTypeName(a)) == 'Int32' AND any(toTypeName(t2.a)) == 'Int32' FROM t1 LEFT JOIN t2 USING (a);
2022-09-26 13:47:29 +00:00
SELECT any(toTypeName(a)) == 'Int32' AND any(toTypeName(t2.a)) == 'Int32' FROM t1 RIGHT JOIN t2 USING (a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT any(toTypeName(a)) == 'Int32' AND any(toTypeName(t2.a)) == 'Int32' FROM t1 INNER JOIN t2 USING (a);
2022-09-26 13:47:29 +00:00
SELECT toTypeName(any(a)) == 'Int32' AND toTypeName(any(t2.a)) == 'Int32' FROM t1 FULL JOIN t2 USING (a); {{ is_implemented(join_algorithm) }}
SELECT min(toTypeName(a) == 'Int32' AND toTypeName(t2.a) == 'Int32') FROM t1 FULL JOIN t2 USING (a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
2022-09-26 13:47:29 +00:00
SELECT any(toTypeName(a)) == 'UInt16' AND any(toTypeName(t2.a)) == 'Int16' FROM t1 FULL JOIN t2 ON (t1.a == t2.a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT any(toTypeName(a)) == 'UInt16' AND any(toTypeName(t2.a)) == 'Int16' FROM t1 LEFT JOIN t2 ON (t1.a == t2.a);
2022-09-26 13:47:29 +00:00
SELECT any(toTypeName(a)) == 'UInt16' AND any(toTypeName(t2.a)) == 'Int16' FROM t1 RIGHT JOIN t2 ON (t1.a == t2.a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SELECT any(toTypeName(a)) == 'UInt16' AND any(toTypeName(t2.a)) == 'Int16' FROM t1 INNER JOIN t2 ON (t1.a == t2.a);
2022-09-26 13:47:29 +00:00
SELECT toTypeName(any(a)) == 'UInt16' AND toTypeName(any(t2.a)) == 'Int16' FROM t1 FULL JOIN t2 ON (t1.a == t2.a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
2022-09-07 16:38:47 +00:00
{% if join_algorithm == 'auto' -%}
2021-02-19 11:17:15 +00:00
SET max_bytes_in_join = 0;
2021-07-20 13:41:24 +00:00
{% endif -%}
2022-09-07 16:38:47 +00:00
{% if join_algorithm not in ['full_sorting_merge'] -%}
2021-02-19 11:17:15 +00:00
SELECT '=== join use nulls ===';
SET join_use_nulls = 1;
SELECT '= full =';
2022-09-26 13:47:29 +00:00
SELECT a, b, t2.b FROM t1 FULL JOIN t2 USING (a) ORDER BY (a); {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT '= left =';
SELECT a, b, t2.b FROM t1 LEFT JOIN t2 USING (a) ORDER BY (a);
2021-02-19 11:17:15 +00:00
SELECT '= right =';
2022-09-26 13:47:29 +00:00
SELECT a, b, t2.b FROM t1 RIGHT JOIN t2 USING (a) ORDER BY (a); {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT '= inner =';
SELECT a, b, t2.b FROM t1 INNER JOIN t2 USING (a) ORDER BY (a);
SELECT '= full =';
2022-09-26 13:47:29 +00:00
SELECT a, t1.a, t2.a FROM t1 FULL JOIN t2 USING (a) ORDER BY (t1.a, t2.a); {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT '= left =';
SELECT a, t1.a, t2.a FROM t1 LEFT JOIN t2 USING (a) ORDER BY (t1.a, t2.a);
SELECT '= right =';
2022-09-26 13:47:29 +00:00
SELECT a, t1.a, t2.a FROM t1 RIGHT JOIN t2 USING (a) ORDER BY (t1.a, t2.a); {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT '= inner =';
SELECT a, t1.a, t2.a FROM t1 INNER JOIN t2 USING (a) ORDER BY (t1.a, t2.a);
SELECT '= join on =';
SELECT '= full =';
2022-09-26 13:47:29 +00:00
SELECT a, b, t2.a, t2.b FROM t1 FULL JOIN t2 ON (t1.a == t2.a) ORDER BY (t1.a, t2.a); {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT '= left =';
SELECT a, b, t2.a, t2.b FROM t1 LEFT JOIN t2 ON (t1.a == t2.a) ORDER BY (t1.a, t2.a);
SELECT '= right =';
2022-09-26 13:47:29 +00:00
SELECT a, b, t2.a, t2.b FROM t1 RIGHT JOIN t2 ON (t1.a == t2.a) ORDER BY (t1.a, t2.a); {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT '= inner =';
SELECT a, b, t2.a, t2.b FROM t1 INNER JOIN t2 ON (t1.a == t2.a) ORDER BY (t1.a, t2.a);
SELECT '= full =';
2022-09-26 13:47:29 +00:00
SELECT * FROM t1 FULL JOIN t2 ON (t1.a + t1.b = t2.a + t2.b - 100) ORDER BY (t1.a, t2.a); {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT '= left =';
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a + t1.b = t2.a + t2.b - 100) ORDER BY (t1.a, t2.a);
SELECT '= right =';
2022-09-26 13:47:29 +00:00
SELECT * FROM t1 RIGHT JOIN t2 ON (t1.a + t1.b = t2.a + t2.b - 100) ORDER BY (t1.a, t2.a); {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT '= inner =';
SELECT * FROM t1 INNER JOIN t2 ON (t1.a + t1.b = t2.a + t2.b - 100) ORDER BY (t1.a, t2.a);
-- Int64 and UInt64 has no supertype
SELECT * FROM t1 FULL JOIN t2 ON (t1.a + t1.b + 100 = t2.a + t2.b) ORDER BY (t1.a, t2.a); -- { serverError 53 }
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a + t1.b + 100 = t2.a + t2.b) ORDER BY (t1.a, t2.a); -- { serverError 53 }
SELECT * FROM t1 RIGHT JOIN t2 ON (t1.a + t1.b + 100 = t2.a + t2.b) ORDER BY (t1.a, t2.a); -- { serverError 53 }
SELECT * FROM t1 INNER JOIN t2 ON (t1.a + t1.b + 100 = t2.a + t2.b) ORDER BY (t1.a, t2.a); -- { serverError 53 }
SELECT '= agg =';
2022-09-26 13:47:29 +00:00
SELECT sum(a) == 7 FROM t1 FULL JOIN t2 USING (a) WHERE b > 102 AND t2.b <= 204; {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT sum(a) == 7 FROM t1 INNER JOIN t2 USING (a) WHERE b > 102 AND t2.b <= 204;
SELECT sum(b) = 103 FROM t1 LEFT JOIN t2 USING (a) WHERE b > 102 AND t2.b < 204;
2022-09-26 13:47:29 +00:00
SELECT sum(t2.b) = 203 FROM t1 RIGHT JOIN t2 USING (a) WHERE b > 102 AND t2.b < 204; {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
2022-09-26 13:47:29 +00:00
SELECT sum(a) == 2 + 3 + 4 FROM t1 FULL JOIN t2 ON (t1.a + t1.b = t2.a + t2.b - 100) WHERE t1.b < 105 AND t2.b > 201; {{ is_implemented(join_algorithm) }}
SELECT sum(a) == 55 FROM t1 FULL JOIN t2 ON (t1.a + t1.b = t2.a + t2.b - 100) WHERE 1; {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
2022-09-26 13:47:29 +00:00
SELECT a > 0, sum(a), sum(b) FROM t1 FULL JOIN t2 USING (a) GROUP BY (a > 0) ORDER BY a > 0; {{ is_implemented(join_algorithm) }}
SELECT a > 0, sum(a), sum(t2.a), sum(b), sum(t2.b) FROM t1 FULL JOIN t2 ON (t1.a == t2.a) GROUP BY (a > 0) ORDER BY a > 0; {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT '= types =';
2022-09-26 13:47:29 +00:00
SELECT any(toTypeName(a)) == 'Nullable(Int32)' AND any(toTypeName(t2.a)) == 'Nullable(Int32)' FROM t1 FULL JOIN t2 USING (a); {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT any(toTypeName(a)) == 'Int32' AND any(toTypeName(t2.a)) == 'Nullable(Int32)' FROM t1 LEFT JOIN t2 USING (a);
2022-09-26 13:47:29 +00:00
SELECT any(toTypeName(a)) == 'Nullable(Int32)' AND any(toTypeName(t2.a)) == 'Int32' FROM t1 RIGHT JOIN t2 USING (a); {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT any(toTypeName(a)) == 'Int32' AND any(toTypeName(t2.a)) == 'Int32' FROM t1 INNER JOIN t2 USING (a);
2022-09-26 13:47:29 +00:00
SELECT toTypeName(any(a)) == 'Nullable(Int32)' AND toTypeName(any(t2.a)) == 'Nullable(Int32)' FROM t1 FULL JOIN t2 USING (a); {{ is_implemented(join_algorithm) }}
SELECT min(toTypeName(a) == 'Nullable(Int32)' AND toTypeName(t2.a) == 'Nullable(Int32)') FROM t1 FULL JOIN t2 USING (a); {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
2022-09-26 13:47:29 +00:00
SELECT any(toTypeName(a)) == 'Nullable(UInt16)' AND any(toTypeName(t2.a)) == 'Nullable(Int16)' FROM t1 FULL JOIN t2 ON (t1.a == t2.a); {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT any(toTypeName(a)) == 'UInt16' AND any(toTypeName(t2.a)) == 'Nullable(Int16)' FROM t1 LEFT JOIN t2 ON (t1.a == t2.a);
2022-09-26 13:47:29 +00:00
SELECT any(toTypeName(a)) == 'Nullable(UInt16)' AND any(toTypeName(t2.a)) == 'Int16' FROM t1 RIGHT JOIN t2 ON (t1.a == t2.a); {{ is_implemented(join_algorithm) }}
2021-03-08 14:21:50 +00:00
SELECT any(toTypeName(a)) == 'UInt16' AND any(toTypeName(t2.a)) == 'Int16' FROM t1 INNER JOIN t2 ON (t1.a == t2.a);
2022-09-26 13:47:29 +00:00
SELECT toTypeName(any(a)) == 'Nullable(UInt16)' AND toTypeName(any(t2.a)) == 'Nullable(Int16)' FROM t1 FULL JOIN t2 ON (t1.a == t2.a); {{ is_implemented(join_algorithm) }}
2021-02-19 11:17:15 +00:00
SET join_use_nulls = 0;
2022-09-07 16:38:47 +00:00
{% endif -%}
{% endfor -%}
2021-02-19 11:17:15 +00:00
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;