mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-19 06:01:57 +00:00
apply final only on storages that support it
This commit is contained in:
parent
252575ee23
commit
3239516521
@ -499,9 +499,7 @@ InterpreterSelectQuery::InterpreterSelectQuery(
|
||||
query_info.additional_filter_ast = parseAdditionalFilterConditionForTable(
|
||||
settings.additional_table_filters, joined_tables.tablesWithColumns().front().table, *context);
|
||||
|
||||
|
||||
// query.tables() is required because not all queries have tables in it, it could be a function.
|
||||
if (context->getSettingsRef().force_select_final && !query.final() && query.tables())
|
||||
if (forceSelectFinalOnSelectQuery(query))
|
||||
{
|
||||
query.setFinal();
|
||||
}
|
||||
@ -2916,6 +2914,15 @@ void InterpreterSelectQuery::ignoreWithTotals()
|
||||
getSelectQuery().group_by_with_totals = false;
|
||||
}
|
||||
|
||||
bool InterpreterSelectQuery::forceSelectFinalOnSelectQuery(ASTSelectQuery & query)
|
||||
{
|
||||
// query.tables() is required because not all queries have tables in it, it could be a function.
|
||||
auto isFinalSupported = storage && storage->supportsFinal() && query.tables();
|
||||
auto isForceSelectFinalSettingOn = context->getSettingsRef().force_select_final;
|
||||
auto isQueryAlreadyFinal = query.final();
|
||||
|
||||
return isForceSelectFinalSettingOn && !isQueryAlreadyFinal && isFinalSupported;
|
||||
}
|
||||
|
||||
void InterpreterSelectQuery::initSettings()
|
||||
{
|
||||
|
@ -194,6 +194,7 @@ private:
|
||||
void executeDistinct(QueryPlan & query_plan, bool before_order, Names columns, bool pre_distinct);
|
||||
void executeExtremes(QueryPlan & query_plan);
|
||||
void executeSubqueriesInSetsAndJoins(QueryPlan & query_plan);
|
||||
bool forceSelectFinalOnSelectQuery(ASTSelectQuery & select_query);
|
||||
|
||||
enum class Modificator
|
||||
{
|
||||
|
@ -26,3 +26,10 @@ set force_select_final = 1;
|
||||
-- expected output is 1 because force_select_final == 1
|
||||
select count() from lhs inner join rhs on lhs.x = rhs.x;
|
||||
1
|
||||
-- regular non final table
|
||||
set force_select_final = 1;
|
||||
create table if not exists regular_mt_table (x String) engine=MergeTree() ORDER BY x;
|
||||
insert into regular_mt_table values ('abc');
|
||||
-- expected output is 1, it should silently ignore final modifier
|
||||
select count() from regular_mt_table;
|
||||
1
|
||||
|
@ -31,3 +31,10 @@ select count() from lhs inner join rhs on lhs.x = rhs.x;
|
||||
set force_select_final = 1;
|
||||
-- expected output is 1 because force_select_final == 1
|
||||
select count() from lhs inner join rhs on lhs.x = rhs.x;
|
||||
|
||||
-- regular non final table
|
||||
set force_select_final = 1;
|
||||
create table if not exists regular_mt_table (x String) engine=MergeTree() ORDER BY x;
|
||||
insert into regular_mt_table values ('abc');
|
||||
-- expected output is 1, it should silently ignore final modifier
|
||||
select count() from regular_mt_table;
|
||||
|
Loading…
Reference in New Issue
Block a user