ClickHouse/tests/queries/0_stateless/02372_analyzer_join.sql.j2

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

171 lines
6.6 KiB
Plaintext
Raw Normal View History

2022-10-18 10:02:28 +00:00
-- Tags: long
SET allow_experimental_analyzer = 1;
2022-08-20 14:01:50 +00:00
DROP TABLE IF EXISTS test_table_join_1;
CREATE TABLE test_table_join_1
(
id UInt64,
value String
) ENGINE = TinyLog;
DROP TABLE IF EXISTS test_table_join_2;
CREATE TABLE test_table_join_2
(
id UInt64,
value String
) ENGINE = TinyLog;
DROP TABLE IF EXISTS test_table_join_3;
CREATE TABLE test_table_join_3
(
id UInt64,
value String
) ENGINE = TinyLog;
INSERT INTO test_table_join_1 VALUES (0, 'Join_1_Value_0');
INSERT INTO test_table_join_1 VALUES (1, 'Join_1_Value_1');
2022-08-20 20:15:33 +00:00
INSERT INTO test_table_join_1 VALUES (2, 'Join_1_Value_2');
2022-08-20 14:01:50 +00:00
INSERT INTO test_table_join_2 VALUES (0, 'Join_2_Value_0');
INSERT INTO test_table_join_2 VALUES (1, 'Join_2_Value_1');
2022-08-20 20:15:33 +00:00
INSERT INTO test_table_join_2 VALUES (3, 'Join_2_Value_3');
2022-08-20 14:01:50 +00:00
INSERT INTO test_table_join_3 VALUES (0, 'Join_3_Value_0');
INSERT INTO test_table_join_3 VALUES (1, 'Join_3_Value_1');
2022-08-20 20:15:33 +00:00
INSERT INTO test_table_join_3 VALUES (4, 'Join_3_Value_4');
2022-08-20 14:01:50 +00:00
-- { echoOn }
{% for join_type in ['INNER', 'LEFT', 'RIGHT', 'FULL'] -%}
SELECT 'JOIN {{ join_type }}';
2022-08-20 20:15:33 +00:00
SELECT 'JOIN ON without conditions';
2022-08-20 14:01:50 +00:00
SELECT test_table_join_1.id, test_table_join_1.value, test_table_join_2.id, test_table_join_2.value
FROM test_table_join_1 {{ join_type }} JOIN test_table_join_2 ON test_table_join_1.id = test_table_join_2.id;
SELECT '--';
SELECT t1.id, t1.value, t2.id, t2.value
FROM test_table_join_1 AS t1 {{ join_type }} JOIN test_table_join_2 AS t2 ON t1.id = t2.id;
SELECT '--';
SELECT t1.id, test_table_join_1.id, t1.value, test_table_join_1.value, t2.id, test_table_join_2.id, t2.value, test_table_join_2.value
FROM test_table_join_1 AS t1 {{ join_type }} JOIN test_table_join_2 AS t2 ON t1.id = t2.id;
SELECT '--';
2022-08-20 20:15:33 +00:00
SELECT t1.value, t2.value
FROM test_table_join_1 AS t1 {{ join_type }} JOIN test_table_join_2 AS t2 ON t1.id = t2.id;
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
SELECT id FROM test_table_join_1 {{ join_type }} JOIN test_table_join_2 ON test_table_join_1.id = test_table_join_2.id; -- { serverError 207 }
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
SELECT value FROM test_table_join_1 {{ join_type }} JOIN test_table_join_2 ON test_table_join_1.id = test_table_join_2.id; -- { serverError 207 }
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
SELECT 'JOIN ON with conditions';
2022-08-20 14:01:50 +00:00
SELECT t1.id, t1.value, t2.id, t2.value
FROM test_table_join_1 AS t1 INNER JOIN test_table_join_2 AS t2 ON t1.id = t2.id AND t1.value = 'Join_1_Value_0';
SELECT '--';
SELECT t1.id, t1.value, t2.id, t2.value
FROM test_table_join_1 AS t1 {{ join_type }} JOIN test_table_join_2 AS t2 ON t1.id = t2.id AND t2.value = 'Join_2_Value_0';
SELECT '--';
SELECT t1.id, t1.value, t2.id, t2.value
FROM test_table_join_1 AS t1 {{ join_type }} JOIN test_table_join_2 AS t2 ON t1.id = t2.id AND t1.value = 'Join_1_Value_0' AND t2.value = 'Join_2_Value_0';
SELECT '--';
SELECT t1.id, t1.value, t2.id, t2.value
FROM test_table_join_1 AS t1 {{ join_type }} JOIN test_table_join_2 AS t2 ON toString(t1.id) = toString(t2.id) AND t1.value = 'Join_1_Value_0' AND t2.value = 'Join_2_Value_0';
2022-08-20 20:15:33 +00:00
SELECT 'JOIN multiple clauses';
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
SELECT t1.id, t1.value, t2.id, t2.value
FROM test_table_join_1 AS t1 {{ join_type }} JOIN test_table_join_2 AS t2 ON t1.id = t2.id OR t1.id = t2.id;
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
SELECT 'JOIN expression aliases';
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
SELECT t1_id, t1.value, t2_id, t2.value FROM test_table_join_1 AS t1 {{ join_type }} JOIN test_table_join_2 AS t2 ON (t1.id AS t1_id) = (t2.id AS t2_id);
2022-08-20 14:01:50 +00:00
SELECT '--';
2022-08-20 20:15:33 +00:00
SELECT t1.id AS t1_id, t1.value, t2.id AS t2_id, t2.value FROM test_table_join_1 AS t1 {{ join_type }} JOIN test_table_join_2 AS t2 ON t1_id = t2_id;
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
{% endfor %}
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
{% for first_join_type in ['INNER', 'LEFT', 'RIGHT', 'FULL'] -%}
{% for second_join_type in ['INNER', 'LEFT', 'RIGHT', 'FULL'] -%}
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
SELECT 'First JOIN {{ first_join_type }} second JOIN {{ second_join_type }}';
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
SELECT 'JOIN ON without conditions';
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
SELECT test_table_join_1.id, test_table_join_1.value, test_table_join_2.id, test_table_join_2.value, test_table_join_3.id, test_table_join_3.value
FROM test_table_join_1 {{ first_join_type }} JOIN test_table_join_2 ON test_table_join_1.id = test_table_join_2.id
{{ second_join_type }} JOIN test_table_join_3 ON test_table_join_2.id = test_table_join_3.id;
2022-08-20 14:01:50 +00:00
SELECT '--';
2022-08-20 20:15:33 +00:00
SELECT t1.id, t1.value, t2.id, t2.value, t3.id, t3.value
FROM test_table_join_1 AS t1 {{ first_join_type }} JOIN test_table_join_2 AS t2 ON test_table_join_1.id = test_table_join_2.id
{{ second_join_type }} JOIN test_table_join_3 AS t3 ON test_table_join_2.id = test_table_join_3.id;
2022-08-20 14:01:50 +00:00
SELECT '--';
2022-08-20 20:15:33 +00:00
SELECT t1.id, test_table_join_1.id, t1.value, test_table_join_1.value, t2.id, test_table_join_2.id, t2.value, test_table_join_2.value,
t3.id, test_table_join_3.id, t3.value, test_table_join_3.value
FROM test_table_join_1 AS t1 {{ first_join_type }} JOIN test_table_join_2 AS t2 ON test_table_join_1.id = test_table_join_2.id
{{ second_join_type }} JOIN test_table_join_3 AS t3 ON test_table_join_2.id = test_table_join_3.id;
2022-08-20 14:01:50 +00:00
SELECT '--';
SELECT t1.value, t2.value, t3.value
2022-08-20 20:15:33 +00:00
FROM test_table_join_1 AS t1 {{ first_join_type }} JOIN test_table_join_2 AS t2 ON test_table_join_1.id = test_table_join_2.id
{{ second_join_type }} JOIN test_table_join_3 AS t3 ON test_table_join_2.id = test_table_join_3.id;
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
SELECT 'JOIN ON with conditions';
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
SELECT t1.id, t1.value, t2.id, t2.value, t3.id, t3.value
FROM test_table_join_1 AS t1 {{ first_join_type }} JOIN test_table_join_2 AS t2 ON t1.id = t2.id AND t1.value == 'Join_1_Value_0'
{{ second_join_type }} JOIN test_table_join_3 AS t3 ON t2.id = t3.id AND t2.value == 'Join_2_Value_0';
2022-08-20 14:01:50 +00:00
SELECT '--';
2022-08-20 20:15:33 +00:00
SELECT t1.id, t1.value, t2.id, t2.value, t3.id, t3.value
FROM test_table_join_1 AS t1 {{ first_join_type }} JOIN test_table_join_2 AS t2 ON t1.id = t2.id AND t1.value == 'Join_1_Value_0' AND t2.value == 'Join_2_Value_0'
{{ second_join_type }} JOIN test_table_join_3 AS t3 ON t2.id = t3.id AND t2.value == 'Join_2_Value_0' AND t3.value == 'Join_3_Value_0';
SELECT 'JOIN multiple clauses';
2022-08-20 14:01:50 +00:00
SELECT t1.value, t2.value, t3.value
FROM test_table_join_1 AS t1
2022-08-20 20:15:33 +00:00
{{ first_join_type }} JOIN test_table_join_2 AS t2 ON t1.id = t2.id OR t1.id = t2.id
{{ second_join_type }} JOIN test_table_join_3 AS t3 ON t2.id = t3.id OR t3.id = t2.id;
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
SELECT 'JOIN expression aliases';
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
SELECT t1_id, t1.value, t2_id, t2.value, t3_id, t3.value
FROM test_table_join_1 AS t1 {{ first_join_type }} JOIN test_table_join_2 AS t2 ON (t1.id AS t1_id) = (t2.id AS t2_id)
{{ second_join_type }} JOIN test_table_join_3 AS t3 ON t2_id = (t3.id AS t3_id);
2022-08-20 14:01:50 +00:00
SELECT '--';
2022-08-20 20:15:33 +00:00
SELECT t1.id AS t1_id, t1.value, t2.id AS t2_id, t2.value, t3.id AS t3_id, t3.value
FROM test_table_join_1 AS t1 {{ first_join_type }} JOIN test_table_join_2 AS t2 ON t1_id = t2_id
{{ second_join_type }} JOIN test_table_join_3 AS t3 ON t2_id = t3_id;
2022-08-20 14:01:50 +00:00
2022-08-20 20:15:33 +00:00
{% endfor %}
2022-08-20 14:01:50 +00:00
{% endfor %}
-- { echoOff }
DROP TABLE test_table_join_1;
DROP TABLE test_table_join_2;
DROP TABLE test_table_join_3;