Merge pull request #30293 from amosbird/projection-fix19

Fix projections with JOIN alias columns
This commit is contained in:
Dmitry Novik 2021-10-21 17:49:21 +03:00 committed by GitHub
commit 58ee783be4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 2 deletions

View File

@ -890,9 +890,10 @@ static std::unique_ptr<QueryPlan> buildJoinedPlan(
* - in the addExternalStorage function, the JOIN (SELECT ...) subquery is replaced with JOIN _data1,
* in the subquery_for_set object this subquery is exposed as source and the temporary table _data1 as the `table`.
* - this function shows the expression JOIN _data1.
* - JOIN tables will need aliases to correctly resolve USING clause.
*/
auto interpreter = interpretSubquery(
join_element.table_expression, context, original_right_columns, query_options.copy().setWithAllColumns());
join_element.table_expression, context, original_right_columns, query_options.copy().setWithAllColumns().ignoreAlias(false));
auto joined_plan = std::make_unique<QueryPlan>();
interpreter->buildQueryPlan(*joined_plan);
{

View File

@ -272,6 +272,7 @@ InterpreterSelectQuery::InterpreterSelectQuery(
query_info.ignore_projections = options.ignore_projections;
query_info.is_projection_query = options.is_projection_query;
query_info.original_query = query_ptr->clone();
initSettings();
const Settings & settings = context->getSettingsRef();

View File

@ -4531,7 +4531,7 @@ bool MergeTreeData::getQueryProcessingStageWithAggregateProjection(
if (!settings.allow_experimental_projection_optimization || query_info.ignore_projections || query_info.is_projection_query)
return false;
const auto & query_ptr = query_info.query;
const auto & query_ptr = query_info.original_query;
if (auto * select = query_ptr->as<ASTSelectQuery>(); select)
{

View File

@ -133,6 +133,7 @@ struct SelectQueryInfo
{
ASTPtr query;
ASTPtr view_query; /// Optimized VIEW query
ASTPtr original_query; /// Unmodified query for projection analysis
/// Cluster for the query.
ClusterPtr cluster;

View File

@ -0,0 +1,8 @@
drop table if exists t;
create table t (s UInt16, l UInt16, projection p (select s, l order by l)) engine MergeTree order by s;
select s from t join (select toUInt16(1) as s) x using (s) settings allow_experimental_projection_optimization = 1;
select s from t join (select toUInt16(1) as s) x using (s) settings allow_experimental_projection_optimization = 0;
drop table t;