mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
Planner table expression data column order fix
This commit is contained in:
parent
6209d13ad5
commit
bff55d5b2a
@ -259,7 +259,7 @@ JoinTreeQueryPlan buildQueryPlanForTableExpression(const QueryTreeNodePtr & tabl
|
||||
|
||||
from_stage = storage->getQueryProcessingStage(query_context, select_query_options.to_stage, storage_snapshot, table_expression_query_info);
|
||||
|
||||
Names columns_names = table_expression_data.getColumnNames();
|
||||
auto columns_names = table_expression_data.getColumnNames();
|
||||
|
||||
/** The current user must have the SELECT privilege.
|
||||
* We do not check access rights for table functions because they have been already checked in ITableFunction::execute().
|
||||
|
@ -63,9 +63,7 @@ public:
|
||||
if (hasColumn(column.name))
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Column with name {} already exists");
|
||||
|
||||
column_name_to_column.emplace(column.name, column);
|
||||
column_name_to_column_identifier.emplace(column.name, column_identifier);
|
||||
column_identifier_to_column_name.emplace(column_identifier, column.name);
|
||||
addColumnImpl(column, column_identifier);
|
||||
}
|
||||
|
||||
/** Add column if it does not exists in table expression data.
|
||||
@ -76,9 +74,7 @@ public:
|
||||
if (hasColumn(column.name))
|
||||
return;
|
||||
|
||||
column_name_to_column.emplace(column.name, column);
|
||||
column_name_to_column_identifier.emplace(column.name, column_identifier);
|
||||
column_identifier_to_column_name.emplace(column_identifier, column.name);
|
||||
addColumnImpl(column, column_identifier);
|
||||
}
|
||||
|
||||
/// Add alias column name
|
||||
@ -100,15 +96,9 @@ public:
|
||||
}
|
||||
|
||||
/// Get column names
|
||||
Names getColumnNames() const
|
||||
const Names & getColumnNames() const
|
||||
{
|
||||
Names result;
|
||||
result.reserve(column_name_to_column.size());
|
||||
|
||||
for (const auto & [column_name, _] : column_name_to_column)
|
||||
result.push_back(column_name);
|
||||
|
||||
return result;
|
||||
return column_names;
|
||||
}
|
||||
|
||||
ColumnIdentifiers getColumnIdentifiers() const
|
||||
@ -142,7 +132,6 @@ public:
|
||||
auto it = column_name_to_column.find(column_name);
|
||||
if (it == column_name_to_column.end())
|
||||
{
|
||||
auto column_names = getColumnNames();
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
||||
"Column for column name {} does not exists. There are only column names: {}",
|
||||
column_name,
|
||||
@ -172,7 +161,6 @@ public:
|
||||
auto it = column_name_to_column_identifier.find(column_name);
|
||||
if (it == column_name_to_column_identifier.end())
|
||||
{
|
||||
auto column_names = getColumnNames();
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
||||
"Column identifier for column name {} does not exists. There are only column names: {}",
|
||||
column_name,
|
||||
@ -240,6 +228,17 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void addColumnImpl(const NameAndTypePair & column, const ColumnIdentifier & column_identifier)
|
||||
{
|
||||
column_names.push_back(column.name);
|
||||
column_name_to_column.emplace(column.name, column);
|
||||
column_name_to_column_identifier.emplace(column.name, column_identifier);
|
||||
column_identifier_to_column_name.emplace(column_identifier, column.name);
|
||||
}
|
||||
|
||||
/// Valid for table, table function, array join, query, union nodes
|
||||
Names column_names;
|
||||
|
||||
/// Valid for table, table function, array join, query, union nodes
|
||||
ColumnNameToColumn column_name_to_column;
|
||||
|
||||
|
@ -24,15 +24,15 @@ Header: count() UInt64
|
||||
Header: default.a.a2_4 String
|
||||
default.b.b1_0 UInt64
|
||||
Join (JOIN FillRightFirst)
|
||||
Header: default.a.a2_4 String
|
||||
default.a.a1_1 UInt64
|
||||
Header: default.a.a1_1 UInt64
|
||||
default.a.a2_4 String
|
||||
default.b.b1_0 UInt64
|
||||
Expression ((JOIN actions + Change column names to column identifiers))
|
||||
Header: default.a.a2_4 String
|
||||
default.a.a1_1 UInt64
|
||||
Header: default.a.a1_1 UInt64
|
||||
default.a.a2_4 String
|
||||
ReadFromStorage (Memory)
|
||||
Header: a2 String
|
||||
a1 UInt64
|
||||
Header: a1 UInt64
|
||||
a2 String
|
||||
Expression ((JOIN actions + Change column names to column identifiers))
|
||||
Header: default.b.b1_0 UInt64
|
||||
ReadFromStorage (Memory)
|
||||
@ -52,27 +52,27 @@ Expression ((Project names + (Projection + DROP unused columns after JOIN)))
|
||||
Header: a2 String
|
||||
d2 String
|
||||
Join (JOIN FillRightFirst)
|
||||
Header: default.a.k_2 UInt64
|
||||
default.a.a2_0 String
|
||||
Header: default.a.a2_0 String
|
||||
default.a.k_2 UInt64
|
||||
default.d.d2_1 String
|
||||
Expression (DROP unused columns after JOIN)
|
||||
Header: default.a.k_2 UInt64
|
||||
default.a.a2_0 String
|
||||
Header: default.a.a2_0 String
|
||||
default.a.k_2 UInt64
|
||||
Join (JOIN FillRightFirst)
|
||||
Header: default.a.k_2 UInt64
|
||||
default.a.a2_0 String
|
||||
Header: default.a.a2_0 String
|
||||
default.a.k_2 UInt64
|
||||
Expression (DROP unused columns after JOIN)
|
||||
Header: default.a.k_2 UInt64
|
||||
default.a.a2_0 String
|
||||
Header: default.a.a2_0 String
|
||||
default.a.k_2 UInt64
|
||||
Join (JOIN FillRightFirst)
|
||||
Header: default.a.k_2 UInt64
|
||||
default.a.a2_0 String
|
||||
Header: default.a.a2_0 String
|
||||
default.a.k_2 UInt64
|
||||
Expression (Change column names to column identifiers)
|
||||
Header: default.a.k_2 UInt64
|
||||
default.a.a2_0 String
|
||||
Header: default.a.a2_0 String
|
||||
default.a.k_2 UInt64
|
||||
ReadFromStorage (Memory)
|
||||
Header: k UInt64
|
||||
a2 String
|
||||
Header: a2 String
|
||||
k UInt64
|
||||
Expression (Change column names to column identifiers)
|
||||
Header: default.b.k_3 UInt64
|
||||
ReadFromStorage (Memory)
|
||||
@ -82,11 +82,11 @@ Header: a2 String
|
||||
ReadFromStorage (Memory)
|
||||
Header: k UInt64
|
||||
Expression (Change column names to column identifiers)
|
||||
Header: default.d.k_5 UInt64
|
||||
default.d.d2_1 String
|
||||
Header: default.d.d2_1 String
|
||||
default.d.k_5 UInt64
|
||||
ReadFromStorage (Memory)
|
||||
Header: k UInt64
|
||||
d2 String
|
||||
Header: d2 String
|
||||
k UInt64
|
||||
EXPLAIN PLAN header = 1
|
||||
SELECT b.bx FROM a
|
||||
JOIN (SELECT b1, b2 || 'x' AS bx FROM b ) AS b ON b.b1 = a.a1
|
||||
@ -123,28 +123,28 @@ Header: bx String
|
||||
b.bx_0 String
|
||||
b.b1_1 UInt64
|
||||
Join (JOIN FillRightFirst)
|
||||
Header: default.a.a2_6 String
|
||||
default.a.a1_2 UInt64
|
||||
Header: default.a.a1_2 UInt64
|
||||
default.a.a2_6 String
|
||||
b.bx_0 String
|
||||
b.b1_1 UInt64
|
||||
Expression ((JOIN actions + Change column names to column identifiers))
|
||||
Header: default.a.a2_6 String
|
||||
default.a.a1_2 UInt64
|
||||
Header: default.a.a1_2 UInt64
|
||||
default.a.a2_6 String
|
||||
ReadFromStorage (Memory)
|
||||
Header: a2 String
|
||||
a1 UInt64
|
||||
Header: a1 UInt64
|
||||
a2 String
|
||||
Expression ((JOIN actions + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers)))))
|
||||
Header: b.b1_1 UInt64
|
||||
b.bx_0 String
|
||||
ReadFromStorage (Memory)
|
||||
Header: b2 String
|
||||
b1 UInt64
|
||||
Header: b1 UInt64
|
||||
b2 String
|
||||
Expression ((JOIN actions + Change column names to column identifiers))
|
||||
Header: default.c.c2_5 String
|
||||
default.c.c1_3 UInt64
|
||||
Header: default.c.c1_3 UInt64
|
||||
default.c.c2_5 String
|
||||
ReadFromStorage (Memory)
|
||||
Header: c2 String
|
||||
c1 UInt64
|
||||
Header: c1 UInt64
|
||||
c2 String
|
||||
Expression ((JOIN actions + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers)))))
|
||||
Header: d.d1_4 UInt64
|
||||
ReadFromStorage (SystemNumbers)
|
||||
|
Loading…
Reference in New Issue
Block a user