mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Merge pull request #30293 from amosbird/projection-fix19
Fix projections with JOIN alias columns
This commit is contained in:
commit
58ee783be4
@ -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);
|
||||
{
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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;
|
Loading…
Reference in New Issue
Block a user