mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Fix virtual columns for prewhere with aliases.
This commit is contained in:
parent
0cb7947835
commit
641771f66f
@ -201,7 +201,16 @@ ExpressionAnalyzer::ExpressionAnalyzer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (storage && source_columns.empty())
|
if (storage && source_columns.empty())
|
||||||
source_columns = storage->getColumns().getAllPhysical();
|
{
|
||||||
|
auto physical_columns = storage->getColumns().getAllPhysical();
|
||||||
|
if (source_columns.empty())
|
||||||
|
source_columns.swap(physical_columns);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
source_columns.insert(source_columns.end(), physical_columns.begin(), physical_columns.end());
|
||||||
|
removeDuplicateColumns(source_columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
removeDuplicateColumns(source_columns);
|
removeDuplicateColumns(source_columns);
|
||||||
|
|
||||||
|
@ -677,8 +677,6 @@ void InterpreterSelectQuery::executeFetchColumns(
|
|||||||
/// Separate expression for columns used in prewhere.
|
/// Separate expression for columns used in prewhere.
|
||||||
auto required_prewhere_columns_expr_list = std::make_shared<ASTExpressionList>();
|
auto required_prewhere_columns_expr_list = std::make_shared<ASTExpressionList>();
|
||||||
|
|
||||||
/// Columns which we will get after prewhere execution.
|
|
||||||
auto source_columns = storage->getColumns().getAllPhysical();
|
|
||||||
|
|
||||||
for (const auto & column : required_columns)
|
for (const auto & column : required_columns)
|
||||||
{
|
{
|
||||||
@ -701,6 +699,8 @@ void InterpreterSelectQuery::executeFetchColumns(
|
|||||||
required_columns_expr_list->children.emplace_back(std::move(column_expr));
|
required_columns_expr_list->children.emplace_back(std::move(column_expr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Columns which we will get after prewhere execution.
|
||||||
|
NamesAndTypesList additional_source_columns;
|
||||||
/// Add columns which will be added by prewhere (otherwise we will remove them in project action).
|
/// Add columns which will be added by prewhere (otherwise we will remove them in project action).
|
||||||
for (const auto & column : prewhere_actions_result)
|
for (const auto & column : prewhere_actions_result)
|
||||||
{
|
{
|
||||||
@ -708,10 +708,10 @@ void InterpreterSelectQuery::executeFetchColumns(
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
required_columns_expr_list->children.emplace_back(std::make_shared<ASTIdentifier>(column.name));
|
required_columns_expr_list->children.emplace_back(std::make_shared<ASTIdentifier>(column.name));
|
||||||
source_columns.emplace_back(column.name, column.type);
|
additional_source_columns.emplace_back(column.name, column.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
alias_actions = ExpressionAnalyzer(required_columns_expr_list, context, nullptr, source_columns).getActions(true);
|
alias_actions = ExpressionAnalyzer(required_columns_expr_list, context, storage, additional_source_columns).getActions(true);
|
||||||
|
|
||||||
/// The set of required columns could be added as a result of adding an action to calculate ALIAS.
|
/// The set of required columns could be added as a result of adding an action to calculate ALIAS.
|
||||||
required_columns = alias_actions->getRequiredColumns();
|
required_columns = alias_actions->getRequiredColumns();
|
||||||
|
Loading…
Reference in New Issue
Block a user