mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-18 12:22:12 +00:00
Fix cross to inner join using error
This commit is contained in:
parent
53fce1411c
commit
5d40471ea3
@ -23,7 +23,6 @@ namespace DB
|
|||||||
namespace ErrorCodes
|
namespace ErrorCodes
|
||||||
{
|
{
|
||||||
extern const int LOGICAL_ERROR;
|
extern const int LOGICAL_ERROR;
|
||||||
extern const int NOT_IMPLEMENTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -163,10 +162,6 @@ bool getTables(ASTSelectQuery & select, std::vector<JoinedElement> & joined_tabl
|
|||||||
size_t num_array_join = 0;
|
size_t num_array_join = 0;
|
||||||
size_t num_using = 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)
|
for (const auto & child : tables->children)
|
||||||
{
|
{
|
||||||
auto * table_element = child->as<ASTTablesInSelectQueryElement>();
|
auto * table_element = child->as<ASTTablesInSelectQueryElement>();
|
||||||
@ -185,7 +180,6 @@ bool getTables(ASTSelectQuery & select, std::vector<JoinedElement> & joined_tabl
|
|||||||
if (t.hasUsing())
|
if (t.hasUsing())
|
||||||
{
|
{
|
||||||
++num_using;
|
++num_using;
|
||||||
tables_with_using.push_back(table_element);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,14 +197,7 @@ bool getTables(ASTSelectQuery & select, std::vector<JoinedElement> & joined_tabl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_using && (num_tables - num_array_join) > 2)
|
return !num_array_join && num_tables - num_using > 1;
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -184,6 +184,14 @@ FROM
|
|||||||
CROSS JOIN t3
|
CROSS JOIN t3
|
||||||
SELECT `--t1.a` AS `t1.a`
|
SELECT `--t1.a` AS `t1.a`
|
||||||
FROM
|
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
|
SELECT
|
||||||
a AS `--t1.a`,
|
a AS `--t1.a`,
|
||||||
|
@ -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 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, 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;
|
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);
|
INSERT INTO t1 values (1,1), (2,2), (3,3), (4,4);
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
1 1 1 1
|
||||||
|
1 1 1 1
|
@ -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;
|
Loading…
Reference in New Issue
Block a user