diff --git a/src/Interpreters/CrossToInnerJoinVisitor.cpp b/src/Interpreters/CrossToInnerJoinVisitor.cpp index b6f977cd9b5..2a2dca19966 100644 --- a/src/Interpreters/CrossToInnerJoinVisitor.cpp +++ b/src/Interpreters/CrossToInnerJoinVisitor.cpp @@ -23,7 +23,6 @@ namespace DB namespace ErrorCodes { extern const int LOGICAL_ERROR; - extern const int NOT_IMPLEMENTED; } namespace @@ -163,10 +162,6 @@ bool getTables(ASTSelectQuery & select, std::vector & joined_tabl size_t num_array_join = 0; size_t num_using = 0; - // For diagnostic messages. - std::vector tables_with_using; - tables_with_using.reserve(num_tables); - for (const auto & child : tables->children) { auto * table_element = child->as(); @@ -185,7 +180,6 @@ bool getTables(ASTSelectQuery & select, std::vector & joined_tabl if (t.hasUsing()) { ++num_using; - tables_with_using.push_back(table_element); continue; } @@ -203,14 +197,7 @@ bool getTables(ASTSelectQuery & select, std::vector & joined_tabl } } - if (num_using && (num_tables - num_array_join) > 2) - { - throw Exception("Multiple CROSS/COMMA JOIN do not support USING (while " - "processing '" + IAST::formatForErrorMessage(tables_with_using) + "')", - ErrorCodes::NOT_IMPLEMENTED); - } - - return !(num_array_join || num_using); + return !num_array_join && num_tables - num_using > 1; } } diff --git a/tests/queries/0_stateless/00849_multiple_comma_join_2.reference b/tests/queries/0_stateless/00849_multiple_comma_join_2.reference index 5709db44eb1..2652a82ab54 100644 --- a/tests/queries/0_stateless/00849_multiple_comma_join_2.reference +++ b/tests/queries/0_stateless/00849_multiple_comma_join_2.reference @@ -184,6 +184,14 @@ FROM CROSS JOIN t3 SELECT `--t1.a` AS `t1.a` FROM +( + SELECT a AS `--t1.a` + FROM t1 + ALL INNER JOIN t2 USING (a) +) AS `--.s` +CROSS JOIN t3 +SELECT `--t1.a` AS `t1.a` +FROM ( SELECT a AS `--t1.a`, diff --git a/tests/queries/0_stateless/00849_multiple_comma_join_2.sql b/tests/queries/0_stateless/00849_multiple_comma_join_2.sql index 5203376befd..58535f556d9 100644 --- a/tests/queries/0_stateless/00849_multiple_comma_join_2.sql +++ b/tests/queries/0_stateless/00849_multiple_comma_join_2.sql @@ -27,7 +27,7 @@ EXPLAIN SYNTAX SELECT t1.a FROM t1, t2, t3, t4; EXPLAIN SYNTAX SELECT t1.a FROM t1 CROSS JOIN t2 CROSS JOIN t3 CROSS JOIN t4; EXPLAIN SYNTAX SELECT t1.a FROM t1, t2 CROSS JOIN t3; -EXPLAIN SYNTAX SELECT t1.a FROM t1 JOIN t2 USING a CROSS JOIN t3; -- { serverError 48 } +EXPLAIN SYNTAX SELECT t1.a FROM t1 JOIN t2 USING a CROSS JOIN t3; EXPLAIN SYNTAX SELECT t1.a FROM t1 JOIN t2 ON t1.a = t2.a CROSS JOIN t3; INSERT INTO t1 values (1,1), (2,2), (3,3), (4,4); diff --git a/tests/queries/0_stateless/01852_multiple_joins_with_union_join.reference b/tests/queries/0_stateless/01852_multiple_joins_with_union_join.reference new file mode 100644 index 00000000000..eb37a198435 --- /dev/null +++ b/tests/queries/0_stateless/01852_multiple_joins_with_union_join.reference @@ -0,0 +1,2 @@ +1 1 1 1 +1 1 1 1 diff --git a/tests/queries/0_stateless/01852_multiple_joins_with_union_join.sql b/tests/queries/0_stateless/01852_multiple_joins_with_union_join.sql new file mode 100644 index 00000000000..da388c62219 --- /dev/null +++ b/tests/queries/0_stateless/01852_multiple_joins_with_union_join.sql @@ -0,0 +1,21 @@ +DROP TABLE IF EXISTS v1; +DROP TABLE IF EXISTS v2; + +CREATE TABLE v1 ( id Int32 ) ENGINE = MergeTree() ORDER BY id; +CREATE TABLE v2 ( value Int32 ) ENGINE = MergeTree() ORDER BY value; + +INSERT INTO v1 ( id ) VALUES (1); +INSERT INTO v2 ( value ) VALUES (1); + +SELECT * FROM v1 AS t1 +JOIN v1 AS t2 USING (id) +JOIN v2 AS n1 ON t1.id = n1.value +JOIN v2 AS n2 ON t1.id = n2.value; + +SELECT * FROM v1 AS t1 +JOIN v1 AS t2 USING (id) +CROSS JOIN v2 AS n1 +CROSS JOIN v2 AS n2; + +DROP TABLE IF EXISTS v1; +DROP TABLE IF EXISTS v2;