mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
rename setting + disable ANY INNER JOIN too
This commit is contained in:
parent
2fee5ccd34
commit
391574f361
@ -200,7 +200,7 @@ struct Settings : public SettingsCollection<Settings>
|
||||
M(SettingBool, join_use_nulls, 0, "Use NULLs for non-joined rows of outer JOINs for types that can be inside Nullable. If false, use default value of corresponding columns data type.") \
|
||||
\
|
||||
M(SettingJoinStrictness, join_default_strictness, JoinStrictness::ALL, "Set default strictness in JOIN query. Possible values: empty string, 'ANY', 'ALL'. If empty, query without strictness will throw exception.") \
|
||||
M(SettingBool, any_join_get_any_from_right_table, false, "Enable ANY RIGHT|FULL JOIN that are not consistent with LEFT one. Right table in ANY JOIN has no key copies so it leads to confusing results for RIGHT and FULL JOINs. User expects 't1 ANY LEFT JOIN t2' is equal to 't2 ANY RIGHT JOIN t1'.") \
|
||||
M(SettingBool, any_join_distinct_right_table_keys, false, "Enable old ANY JOIN logic with many-to-one left-to-right table keys mapping for all ANY JOINs. It leads to confusing not equal results for 't1 ANY LEFT JOIN t2' and 't2 ANY RIGHT JOIN t1'. ANY RIGHT JOIN needs one-to-many keys maping to be consistent with LEFT one.") \
|
||||
\
|
||||
M(SettingUInt64, preferred_block_size_bytes, 1000000, "") \
|
||||
\
|
||||
|
@ -546,14 +546,13 @@ void checkJoin(const ASTTablesInSelectQueryElement * join)
|
||||
|
||||
const auto & table_join = join->table_join->as<ASTTableJoin &>();
|
||||
|
||||
if (table_join.strictness == ASTTableJoin::Strictness::Any ||
|
||||
table_join.strictness == ASTTableJoin::Strictness::Asof)
|
||||
if (table_join.kind == ASTTableJoin::Kind::Right ||
|
||||
table_join.kind == ASTTableJoin::Kind::Full)
|
||||
throw Exception("ANY RIGHT|FULL JOINs are disabled by default cause of confusing results: "
|
||||
"'t1 ANY LEFT JOIN t2' is inconsistent with 't2 ANY RIGHT JOIN t1'."
|
||||
"Default bahaviour is reserved for many-to-one ANY LEFT JOIN and one-to-many ANY RIGHT JOIN."
|
||||
"Set any_join_get_any_from_right_table=1 to enable many-to-one ANY RIGHT|FULL JOINs.",
|
||||
if (table_join.strictness == ASTTableJoin::Strictness::Any)
|
||||
if (table_join.kind != ASTTableJoin::Kind::Left)
|
||||
throw Exception("Old ANY INNER|RIGHT|FULL JOINs are disabled by default. Their logic would be changed."
|
||||
"Old logic is many-to-one for all kinds of ANY JOINs. It's equil to apply distinct for right table keys."
|
||||
"Default bahaviour is reserved for many-to-one LEFT JOIN, one-to-many RIGHT JOIN and one-to-one INNER JOIN."
|
||||
"It would be equal to apply distinct for keys to right, left and both tables respectively."
|
||||
"Set any_join_distinct_right_table_keys=1 to enable old bahaviour.",
|
||||
ErrorCodes::NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
@ -597,7 +596,7 @@ SyntaxAnalyzerResultPtr SyntaxAnalyzer::analyze(
|
||||
|
||||
if (const ASTTablesInSelectQueryElement * node = select_query->join())
|
||||
{
|
||||
if (!settings.any_join_get_any_from_right_table)
|
||||
if (!settings.any_join_distinct_right_table_keys)
|
||||
checkJoin(node);
|
||||
|
||||
if (settings.enable_optimize_predicate_expression)
|
||||
|
@ -1,3 +1,5 @@
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT a.*, b.* FROM
|
||||
(
|
||||
SELECT number AS k FROM system.numbers LIMIT 10
|
||||
|
@ -1,3 +1,5 @@
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT a,b,c,d FROM (SELECT 1 AS a,2 AS b, 3 AS c UNION ALL SELECT 2,3,4 ) ANY INNER JOIN (SELECT 1 AS a,2 AS b,4 AS d UNION ALL SELECT 2,3,5) USING (a) ORDER BY a,b,c,d ASC;
|
||||
SELECT a,b,c,d FROM (SELECT 1 AS a,2 AS b, 3 AS c UNION ALL SELECT 2,3,4 ) ALL LEFT JOIN (SELECT 1 AS a,2 AS b,4 AS d UNION ALL SELECT 2,3,5) USING (a) ORDER BY a,b,c,d ASC;
|
||||
SELECT a,b,c,d FROM (SELECT 1 AS a,2 AS b, 3 AS c UNION ALL SELECT 2,3,4 ) ALL LEFT JOIN (SELECT 1 AS a,2 AS b,4 AS d UNION ALL SELECT 2,3,5) USING a,b ORDER BY a,b,c,d ASC;
|
||||
|
@ -1,3 +1,5 @@
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT number, number / 2 AS n, j1, j2 FROM remote('127.0.0.{2,3}', system.numbers) ANY LEFT JOIN (SELECT number / 3 AS n, number AS j1, 'Hello' AS j2 FROM system.numbers LIMIT 0) USING n LIMIT 10;
|
||||
SELECT dummy + 2 AS number, number / 2 AS n, j1, j2 FROM remote('127.0.0.{2,3}', system.one) ANY INNER JOIN (SELECT number / 3 AS n, number AS j1, 'Hello' AS j2 FROM system.numbers LIMIT 0) USING n LIMIT 10;
|
||||
SELECT number, number / 2 AS n, j1, j2 FROM remote('127.0.0.{2,3}', system.numbers) GLOBAL ANY LEFT JOIN (SELECT number / 3 AS n, number AS j1, 'Hello' AS j2 FROM system.numbers LIMIT 0) USING n LIMIT 10;
|
||||
|
@ -1,3 +1,5 @@
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
DROP TABLE IF EXISTS series;
|
||||
|
||||
CREATE TABLE series(i UInt32, x_value Float64, y_value Float64) ENGINE = Memory;
|
||||
|
@ -1,3 +1,5 @@
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
DROP TABLE IF EXISTS series;
|
||||
|
||||
CREATE TABLE series(i UInt32, x_value Float64, y_value Float64) ENGINE = Memory;
|
||||
|
@ -1,4 +1,4 @@
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT k, x, y FROM (SELECT arrayJoin([1, 2, 3]) AS k, 'Hello' AS x) ANY FULL JOIN (SELECT range(k) AS y, arrayJoin([3, 4, 5]) AS k) USING k WHERE k < 10 ORDER BY k;
|
||||
SELECT k, x FROM (SELECT arrayJoin([1, 2, 3]) AS k, 'Hello' AS x) ANY FULL JOIN (SELECT range(k) AS y, arrayJoin([3, 4, 5]) AS k) USING k WHERE k < 10 ORDER BY k;
|
||||
@ -24,7 +24,7 @@ INSERT INTO t2_00203 VALUES ('ccc', 4, 3, 2), ('ddd', 7, 6, 5);
|
||||
SELECT k1, k2, k3, val_t1, val_t2 FROM t1_00203 ANY FULL JOIN t2_00203 USING (k3, k1, k2 AS k2_alias) ORDER BY k1, k2, k3;
|
||||
SELECT k1, k2, k3, val_t1, val_t2 FROM t1_00203 ANY RIGHT JOIN t2_00203 USING (k3, k1, k2 AS k2_alias) ORDER BY k1, k2, k3;
|
||||
|
||||
SET any_join_get_any_from_right_table = 0;
|
||||
SET any_join_distinct_right_table_keys = 0;
|
||||
SELECT k1, k2, k3, val_t1, val_t2 FROM t1_00203 ANY FULL JOIN t2_00203 USING (k3, k1, k2 AS k2_alias) ORDER BY k1, k2, k3; -- { serverError 48 }
|
||||
SELECT k1, k2, k3, val_t1, val_t2 FROM t1_00203 ANY RIGHT JOIN t2_00203 USING (k3, k1, k2 AS k2_alias) ORDER BY k1, k2, k3; -- { serverError 48 }
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT a, b FROM (SELECT 1 AS a, 2000 AS b) ANY RIGHT JOIN (SELECT 2 AS a, 3000 AS b) USING a, b;
|
||||
SELECT a, b FROM (SELECT 1 AS a, 2000 AS b) ANY RIGHT JOIN (SELECT 2 AS a, 3000 AS b) USING b, a;
|
||||
|
@ -1,3 +1,5 @@
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT
|
||||
floor((ReferrerTimestamp - InstallTimestamp) / 86400) AS DaysSinceInstallations
|
||||
FROM
|
||||
|
@ -1 +1,2 @@
|
||||
set any_join_distinct_right_table_keys = 1;
|
||||
select a from (select (1, 2) as a) any inner join (select (1, 2) as a) using a;
|
||||
|
@ -1,4 +1,4 @@
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
select x, y from (select 1 as x, 2 as y, x, y);
|
||||
select x, y from (select 1 as x, 1 as y, x, y);
|
||||
|
@ -1,5 +1,5 @@
|
||||
SET join_use_nulls = 0;
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT k, a, b
|
||||
FROM
|
||||
|
@ -1,5 +1,5 @@
|
||||
SET join_use_nulls = 0;
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT k, a, b
|
||||
FROM
|
||||
|
@ -14,7 +14,7 @@ INSERT INTO test2_00550 VALUES ('a');
|
||||
CREATE TABLE test3_00550 ( id String, name String ) ENGINE = StripeLog;
|
||||
INSERT INTO test3_00550 VALUES ('a', 'aaa');
|
||||
|
||||
INSERT INTO test1_00550 SELECT id, name FROM test2_00550 ANY INNER JOIN test3_00550 USING (id);
|
||||
INSERT INTO test1_00550 SELECT id, name FROM test2_00550 ANY INNER JOIN test3_00550 USING (id) SETTINGS any_join_distinct_right_table_keys=1;
|
||||
INSERT INTO test1_00550 SELECT id, name FROM test2_00550 ANY LEFT OUTER JOIN test3_00550 USING (id);
|
||||
|
||||
DROP TABLE test1_00550;
|
||||
|
@ -1,3 +1,3 @@
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
SET max_block_size = 10;
|
||||
SELECT * FROM (select toUInt64(1) s limit 1) any right join (select number s, s as x from numbers(11)) using (s) ORDER BY s;
|
||||
|
@ -1,3 +1,5 @@
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
drop table IF EXISTS joinbug;
|
||||
|
||||
CREATE TABLE joinbug (
|
||||
|
@ -1,4 +1,4 @@
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT k, a1, b1, a2, b2 FROM (SELECT 0 AS k, 'hello' AS a1, 123 AS b1, a1) ANY FULL OUTER JOIN (SELECT 1 AS k, 'hello' AS a2, 456 AS b2, a2) USING (k) ORDER BY k;
|
||||
SELECT k, a, b FROM (SELECT 0 AS k, 'hello' AS a, 123 AS b, a) ANY FULL OUTER JOIN (SELECT 1 AS k) USING (k) ORDER BY k;
|
||||
|
@ -1,3 +1,5 @@
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
DROP TABLE IF EXISTS local_statements;
|
||||
DROP TABLE IF EXISTS statements;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
SET send_logs_level = 'none';
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
DROP TABLE IF EXISTS test_00597;
|
||||
DROP TABLE IF EXISTS test_view_00597;
|
||||
|
@ -1,3 +1,5 @@
|
||||
set any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT * FROM (SELECT 1 AS id, 2 AS value);
|
||||
SELECT * FROM (SELECT 1 AS id, 2 AS value, 3 AS A) ANY INNER JOIN (SELECT 1 AS id, 4 AS values, 5 AS D) USING id;
|
||||
SELECT *, d.* FROM ( SELECT 1 AS id, 2 AS value ) ANY INNER JOIN ( SELECT 1 AS id, 3 AS values ) AS d USING id;
|
||||
|
@ -1,4 +1,4 @@
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT * FROM (SELECT 1 AS a, 'x' AS b) join (SELECT 1 as a, 'y' as b) using a;
|
||||
SELECT * FROM (SELECT 1 AS a, 'x' AS b) left join (SELECT 1 as a, 'y' as b) using a;
|
||||
@ -10,6 +10,6 @@ SELECT * FROM (SELECT 1 AS a, 'x' AS b) any left join (SELECT 1 as a, 'y' as b)
|
||||
SELECT * FROM (SELECT 1 AS a, 'x' AS b) any full join (SELECT 1 as a, 'y' as b) using a;
|
||||
SELECT * FROM (SELECT 1 AS a, 'x' AS b) any right join (SELECT 1 as a, 'y' as b) using a;
|
||||
|
||||
SET any_join_get_any_from_right_table = 0;
|
||||
SET any_join_distinct_right_table_keys = 0;
|
||||
SELECT * FROM (SELECT 1 AS a, 'x' AS b) any full join (SELECT 1 as a, 'y' as b) using a; -- { serverError 48 }
|
||||
SELECT * FROM (SELECT 1 AS a, 'x' AS b) any right join (SELECT 1 as a, 'y' as b) using a; -- { serverError 48 }
|
||||
|
@ -1,4 +1,4 @@
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT * FROM (SELECT dummy as a, (toUInt8(0), toUInt8(0)) AS tup FROM system.one)
|
||||
JOIN (SELECT dummy as a, (toUInt8(0), toUInt8(0)) AS tup FROM system.one)
|
||||
|
@ -1,4 +1,4 @@
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
DROP TABLE IF EXISTS t1_00848;
|
||||
DROP TABLE IF EXISTS t2_00848;
|
||||
|
@ -1,3 +1,5 @@
|
||||
set any_join_distinct_right_table_keys = 1;
|
||||
|
||||
drop table if exists fooL;
|
||||
drop table if exists fooR;
|
||||
create table fooL (a Int32, v String) engine = Memory;
|
||||
|
@ -1,4 +1,4 @@
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT * FROM (SELECT 1 AS x) ALL LEFT JOIN (SELECT 1 AS x) USING x;
|
||||
SELECT * FROM (SELECT 1 AS x) ALL LEFT JOIN (SELECT 2 AS x) USING x;
|
||||
|
@ -1,4 +1,4 @@
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
DROP TABLE IF EXISTS test.filtered_table1;
|
||||
DROP TABLE IF EXISTS test.filtered_table2;
|
||||
|
@ -1,3 +1,4 @@
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
SET join_use_nulls = 1;
|
||||
SELECT number FROM system.numbers ANY INNER JOIN (SELECT number, ['test'] FROM system.numbers LIMIT 1) USING (number) LIMIT 1;
|
||||
SELECT number FROM system.numbers ANY LEFT JOIN (SELECT number, ['test'] FROM system.numbers LIMIT 1) USING (number) LIMIT 1;
|
||||
SELECT number FROM system.numbers ANY LEFT JOIN (SELECT number, ['test'] FROM system.numbers LIMIT 1) USING (number) LIMIT 1;
|
||||
|
@ -1,3 +1,5 @@
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT
|
||||
loyalty,
|
||||
count()
|
||||
|
@ -1,3 +1,5 @@
|
||||
SET any_join_distinct_right_table_keys = 1;
|
||||
|
||||
USE test;
|
||||
|
||||
DROP TABLE IF EXISTS join;
|
||||
|
@ -1,4 +1,4 @@
|
||||
SET any_join_get_any_from_right_table = 1;
|
||||
set any_join_distinct_right_table_keys = 1;
|
||||
|
||||
SELECT
|
||||
CounterID,
|
||||
|
Loading…
Reference in New Issue
Block a user