mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +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);
|
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.
|
/** 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().
|
* 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))
|
if (hasColumn(column.name))
|
||||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Column with name {} already exists");
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Column with name {} already exists");
|
||||||
|
|
||||||
column_name_to_column.emplace(column.name, column);
|
addColumnImpl(column, column_identifier);
|
||||||
column_name_to_column_identifier.emplace(column.name, column_identifier);
|
|
||||||
column_identifier_to_column_name.emplace(column_identifier, column.name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add column if it does not exists in table expression data.
|
/** Add column if it does not exists in table expression data.
|
||||||
@ -76,9 +74,7 @@ public:
|
|||||||
if (hasColumn(column.name))
|
if (hasColumn(column.name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
column_name_to_column.emplace(column.name, column);
|
addColumnImpl(column, column_identifier);
|
||||||
column_name_to_column_identifier.emplace(column.name, column_identifier);
|
|
||||||
column_identifier_to_column_name.emplace(column_identifier, column.name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add alias column name
|
/// Add alias column name
|
||||||
@ -100,15 +96,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get column names
|
/// Get column names
|
||||||
Names getColumnNames() const
|
const Names & getColumnNames() const
|
||||||
{
|
{
|
||||||
Names result;
|
return column_names;
|
||||||
result.reserve(column_name_to_column.size());
|
|
||||||
|
|
||||||
for (const auto & [column_name, _] : column_name_to_column)
|
|
||||||
result.push_back(column_name);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnIdentifiers getColumnIdentifiers() const
|
ColumnIdentifiers getColumnIdentifiers() const
|
||||||
@ -142,7 +132,6 @@ public:
|
|||||||
auto it = column_name_to_column.find(column_name);
|
auto it = column_name_to_column.find(column_name);
|
||||||
if (it == column_name_to_column.end())
|
if (it == column_name_to_column.end())
|
||||||
{
|
{
|
||||||
auto column_names = getColumnNames();
|
|
||||||
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
||||||
"Column for column name {} does not exists. There are only column names: {}",
|
"Column for column name {} does not exists. There are only column names: {}",
|
||||||
column_name,
|
column_name,
|
||||||
@ -172,7 +161,6 @@ public:
|
|||||||
auto it = column_name_to_column_identifier.find(column_name);
|
auto it = column_name_to_column_identifier.find(column_name);
|
||||||
if (it == column_name_to_column_identifier.end())
|
if (it == column_name_to_column_identifier.end())
|
||||||
{
|
{
|
||||||
auto column_names = getColumnNames();
|
|
||||||
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
||||||
"Column identifier for column name {} does not exists. There are only column names: {}",
|
"Column identifier for column name {} does not exists. There are only column names: {}",
|
||||||
column_name,
|
column_name,
|
||||||
@ -240,6 +228,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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
|
/// Valid for table, table function, array join, query, union nodes
|
||||||
ColumnNameToColumn column_name_to_column;
|
ColumnNameToColumn column_name_to_column;
|
||||||
|
|
||||||
|
@ -24,15 +24,15 @@ Header: count() UInt64
|
|||||||
Header: default.a.a2_4 String
|
Header: default.a.a2_4 String
|
||||||
default.b.b1_0 UInt64
|
default.b.b1_0 UInt64
|
||||||
Join (JOIN FillRightFirst)
|
Join (JOIN FillRightFirst)
|
||||||
Header: default.a.a2_4 String
|
Header: default.a.a1_1 UInt64
|
||||||
default.a.a1_1 UInt64
|
default.a.a2_4 String
|
||||||
default.b.b1_0 UInt64
|
default.b.b1_0 UInt64
|
||||||
Expression ((JOIN actions + Change column names to column identifiers))
|
Expression ((JOIN actions + Change column names to column identifiers))
|
||||||
Header: default.a.a2_4 String
|
Header: default.a.a1_1 UInt64
|
||||||
default.a.a1_1 UInt64
|
default.a.a2_4 String
|
||||||
ReadFromStorage (Memory)
|
ReadFromStorage (Memory)
|
||||||
Header: a2 String
|
Header: a1 UInt64
|
||||||
a1 UInt64
|
a2 String
|
||||||
Expression ((JOIN actions + Change column names to column identifiers))
|
Expression ((JOIN actions + Change column names to column identifiers))
|
||||||
Header: default.b.b1_0 UInt64
|
Header: default.b.b1_0 UInt64
|
||||||
ReadFromStorage (Memory)
|
ReadFromStorage (Memory)
|
||||||
@ -52,27 +52,27 @@ Expression ((Project names + (Projection + DROP unused columns after JOIN)))
|
|||||||
Header: a2 String
|
Header: a2 String
|
||||||
d2 String
|
d2 String
|
||||||
Join (JOIN FillRightFirst)
|
Join (JOIN FillRightFirst)
|
||||||
Header: default.a.k_2 UInt64
|
Header: default.a.a2_0 String
|
||||||
default.a.a2_0 String
|
default.a.k_2 UInt64
|
||||||
default.d.d2_1 String
|
default.d.d2_1 String
|
||||||
Expression (DROP unused columns after JOIN)
|
Expression (DROP unused columns after JOIN)
|
||||||
Header: default.a.k_2 UInt64
|
Header: default.a.a2_0 String
|
||||||
default.a.a2_0 String
|
default.a.k_2 UInt64
|
||||||
Join (JOIN FillRightFirst)
|
Join (JOIN FillRightFirst)
|
||||||
Header: default.a.k_2 UInt64
|
Header: default.a.a2_0 String
|
||||||
default.a.a2_0 String
|
default.a.k_2 UInt64
|
||||||
Expression (DROP unused columns after JOIN)
|
Expression (DROP unused columns after JOIN)
|
||||||
Header: default.a.k_2 UInt64
|
Header: default.a.a2_0 String
|
||||||
default.a.a2_0 String
|
default.a.k_2 UInt64
|
||||||
Join (JOIN FillRightFirst)
|
Join (JOIN FillRightFirst)
|
||||||
Header: default.a.k_2 UInt64
|
Header: default.a.a2_0 String
|
||||||
default.a.a2_0 String
|
default.a.k_2 UInt64
|
||||||
Expression (Change column names to column identifiers)
|
Expression (Change column names to column identifiers)
|
||||||
Header: default.a.k_2 UInt64
|
Header: default.a.a2_0 String
|
||||||
default.a.a2_0 String
|
default.a.k_2 UInt64
|
||||||
ReadFromStorage (Memory)
|
ReadFromStorage (Memory)
|
||||||
Header: k UInt64
|
Header: a2 String
|
||||||
a2 String
|
k UInt64
|
||||||
Expression (Change column names to column identifiers)
|
Expression (Change column names to column identifiers)
|
||||||
Header: default.b.k_3 UInt64
|
Header: default.b.k_3 UInt64
|
||||||
ReadFromStorage (Memory)
|
ReadFromStorage (Memory)
|
||||||
@ -82,11 +82,11 @@ Header: a2 String
|
|||||||
ReadFromStorage (Memory)
|
ReadFromStorage (Memory)
|
||||||
Header: k UInt64
|
Header: k UInt64
|
||||||
Expression (Change column names to column identifiers)
|
Expression (Change column names to column identifiers)
|
||||||
Header: default.d.k_5 UInt64
|
Header: default.d.d2_1 String
|
||||||
default.d.d2_1 String
|
default.d.k_5 UInt64
|
||||||
ReadFromStorage (Memory)
|
ReadFromStorage (Memory)
|
||||||
Header: k UInt64
|
Header: d2 String
|
||||||
d2 String
|
k UInt64
|
||||||
EXPLAIN PLAN header = 1
|
EXPLAIN PLAN header = 1
|
||||||
SELECT b.bx FROM a
|
SELECT b.bx FROM a
|
||||||
JOIN (SELECT b1, b2 || 'x' AS bx FROM b ) AS b ON b.b1 = a.a1
|
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.bx_0 String
|
||||||
b.b1_1 UInt64
|
b.b1_1 UInt64
|
||||||
Join (JOIN FillRightFirst)
|
Join (JOIN FillRightFirst)
|
||||||
Header: default.a.a2_6 String
|
Header: default.a.a1_2 UInt64
|
||||||
default.a.a1_2 UInt64
|
default.a.a2_6 String
|
||||||
b.bx_0 String
|
b.bx_0 String
|
||||||
b.b1_1 UInt64
|
b.b1_1 UInt64
|
||||||
Expression ((JOIN actions + Change column names to column identifiers))
|
Expression ((JOIN actions + Change column names to column identifiers))
|
||||||
Header: default.a.a2_6 String
|
Header: default.a.a1_2 UInt64
|
||||||
default.a.a1_2 UInt64
|
default.a.a2_6 String
|
||||||
ReadFromStorage (Memory)
|
ReadFromStorage (Memory)
|
||||||
Header: a2 String
|
Header: a1 UInt64
|
||||||
a1 UInt64
|
a2 String
|
||||||
Expression ((JOIN actions + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers)))))
|
Expression ((JOIN actions + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers)))))
|
||||||
Header: b.b1_1 UInt64
|
Header: b.b1_1 UInt64
|
||||||
b.bx_0 String
|
b.bx_0 String
|
||||||
ReadFromStorage (Memory)
|
ReadFromStorage (Memory)
|
||||||
Header: b2 String
|
Header: b1 UInt64
|
||||||
b1 UInt64
|
b2 String
|
||||||
Expression ((JOIN actions + Change column names to column identifiers))
|
Expression ((JOIN actions + Change column names to column identifiers))
|
||||||
Header: default.c.c2_5 String
|
Header: default.c.c1_3 UInt64
|
||||||
default.c.c1_3 UInt64
|
default.c.c2_5 String
|
||||||
ReadFromStorage (Memory)
|
ReadFromStorage (Memory)
|
||||||
Header: c2 String
|
Header: c1 UInt64
|
||||||
c1 UInt64
|
c2 String
|
||||||
Expression ((JOIN actions + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers)))))
|
Expression ((JOIN actions + (Change column names to column identifiers + (Project names + (Projection + Change column names to column identifiers)))))
|
||||||
Header: d.d1_4 UInt64
|
Header: d.d1_4 UInt64
|
||||||
ReadFromStorage (SystemNumbers)
|
ReadFromStorage (SystemNumbers)
|
||||||
|
Loading…
Reference in New Issue
Block a user