mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
better ambiguous column detection in multiple join rewriter
This commit is contained in:
parent
37f07213ee
commit
c5a850240c
@ -224,17 +224,15 @@ struct ColumnAliasesMatcher
|
||||
|
||||
bool last_table = false;
|
||||
String long_name;
|
||||
for (auto & table : data.tables)
|
||||
|
||||
size_t table_pos = 0;
|
||||
if (IdentifierSemantic::chooseTable(node, data.tables, table_pos))
|
||||
{
|
||||
if (value(IdentifierSemantic::canReferColumnToTable(node, table)))
|
||||
{
|
||||
if (!long_name.empty())
|
||||
throw Exception("Cannot refer column '" + node.name + "' to one table", ErrorCodes::AMBIGUOUS_COLUMN_NAME);
|
||||
IdentifierSemantic::setColumnLongName(node, table); /// table_name.column_name -> table_alias.column_name
|
||||
long_name = node.name;
|
||||
if (&table == &data.tables.back())
|
||||
last_table = true;
|
||||
}
|
||||
auto & table = data.tables[table_pos];
|
||||
IdentifierSemantic::setColumnLongName(node, table); /// table_name.column_name -> table_alias.column_name
|
||||
long_name = node.name;
|
||||
if (&table == &data.tables.back())
|
||||
last_table = true;
|
||||
}
|
||||
|
||||
if (long_name.empty())
|
||||
|
@ -4,3 +4,9 @@
|
||||
0
|
||||
0
|
||||
0
|
||||
┌─[1mone.dummy[0m─┬─[1mA.dummy[0m─┬─[1mB.dummy[0m─┐
|
||||
│ 0 │ 0 │ 0 │
|
||||
└───────────┴─────────┴─────────┘
|
||||
┌─[1mA.dummy[0m─┬─[1mone.dummy[0m─┬─[1mtwo.dummy[0m─┐
|
||||
│ 0 │ 0 │ 0 │
|
||||
└─────────┴───────────┴───────────┘
|
||||
|
@ -13,12 +13,12 @@ SELECT dummy FROM one l JOIN one r ON l.dummy = dummy; -- { serverError 352 }
|
||||
SELECT dummy FROM one l JOIN one r ON one.dummy = r.dummy; -- { serverError 352 }
|
||||
SELECT dummy FROM one l JOIN one r ON l.dummy = one.dummy; -- { serverError 352 }
|
||||
|
||||
-- SELECT * from one
|
||||
-- JOIN one A ON one.dummy = A.dummy
|
||||
-- JOIN one B ON one.dummy = B.dummy
|
||||
-- FORMAT PrettyCompact;
|
||||
--
|
||||
-- SELECT * from one
|
||||
-- JOIN one A ON dummy = A.dummy
|
||||
-- JOIN one B ON dummy = B.dummy
|
||||
-- FORMAT PrettyCompact;
|
||||
SELECT * from one
|
||||
JOIN one A ON one.dummy = A.dummy
|
||||
JOIN one B ON one.dummy = B.dummy
|
||||
FORMAT PrettyCompact;
|
||||
|
||||
SELECT * from one A
|
||||
JOIN system.one one ON A.dummy = one.dummy
|
||||
JOIN system.one two ON A.dummy = two.dummy
|
||||
FORMAT PrettyCompact;
|
||||
|
Loading…
Reference in New Issue
Block a user