Fix cross to inner join using error

This commit is contained in:
Viachaslau Boben 2021-05-04 19:11:15 +03:00 committed by vdimir
parent 53fce1411c
commit 5d40471ea3
No known key found for this signature in database
GPG Key ID: 9B404D301C0CC7EB
5 changed files with 33 additions and 15 deletions

View File

@ -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<JoinedElement> & joined_tabl
size_t num_array_join = 0;
size_t num_using = 0;
// For diagnostic messages.
std::vector<IAST *> tables_with_using;
tables_with_using.reserve(num_tables);
for (const auto & child : tables->children)
{
auto * table_element = child->as<ASTTablesInSelectQueryElement>();
@ -185,7 +180,6 @@ bool getTables(ASTSelectQuery & select, std::vector<JoinedElement> & 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<JoinedElement> & 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;
}
}

View File

@ -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`,

View File

@ -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);

View File

@ -0,0 +1,2 @@
1 1 1 1
1 1 1 1

View File

@ -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;