mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
fix
fix
This commit is contained in:
parent
0001a3a076
commit
fdf646283d
@ -473,6 +473,7 @@ struct Settings : public SettingsCollection<Settings>
|
||||
M(SettingBool, output_format_enable_streaming, false, "Enable streaming in output formats that support it.", 0) \
|
||||
M(SettingBool, output_format_write_statistics, true, "Write statistics about read rows, bytes, time elapsed in suitable output formats.", 0) \
|
||||
M(SettingBool, allow_non_metadata_alters, true, "Allow to execute alters which affects not only tables metadata, but also data on disk", 0) \
|
||||
M(SettingBool, optimize_trivial_insert_select, true, "Optimize trivial 'INSERT INTO table SELECT ... FROM TABLES' query", 0) \
|
||||
|
||||
#define LIST_OF_SETTINGS(M) \
|
||||
COMMON_SETTINGS(M) \
|
||||
|
@ -201,53 +201,62 @@ BlockIO InterpreterInsertQuery::execute()
|
||||
size_t out_streams_size = 1;
|
||||
if (query.select)
|
||||
{
|
||||
auto is_trivial_select = [](const auto query_)
|
||||
{
|
||||
if (query_.tables())
|
||||
{
|
||||
const auto & tables_in_select_query = query_.tables()->template as<ASTTablesInSelectQuery &>();
|
||||
for (const auto & child : tables_in_select_query.children)
|
||||
auto optimize_trivial_insert_select = settings.optimize_trivial_insert_select;
|
||||
if(optimize_trivial_insert_select)
|
||||
{
|
||||
auto is_trivial_select = [](const auto query_) {
|
||||
if (query_.tables())
|
||||
{
|
||||
const auto & table_element = child->template as<ASTTablesInSelectQueryElement &>();
|
||||
const auto & table_expr = table_element.table_expression->template as<ASTTableExpression &>();
|
||||
if (table_expr.subquery)
|
||||
const auto & tables_in_select_query = query_.tables()->template as<ASTTablesInSelectQuery &>();
|
||||
for (const auto & child : tables_in_select_query.children)
|
||||
{
|
||||
return false;
|
||||
const auto & table_element = child->template as<ASTTablesInSelectQueryElement &>();
|
||||
const auto & table_expr = table_element.table_expression->template as<ASTTableExpression &>();
|
||||
if (table_expr.subquery)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!query_.distinct && !query_.limit_with_ties && !query_.prewhere()
|
||||
&& !query_.where() && !query_.groupBy() && !query_.having() && !query_.orderBy() && !query_.limitBy())
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
if (!query_.distinct && !query_.limit_with_ties && !query_.prewhere() && !query_.where() && !query_.groupBy()
|
||||
&& !query_.having() && !query_.orderBy() && !query_.limitBy())
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
const auto & ast = query.select->as<ASTSelectWithUnionQuery &>();
|
||||
size_t num_selects = ast.list_of_selects->children.size();
|
||||
bool is_trivial_query = true;
|
||||
for (size_t query_num = 0; query_num < num_selects; ++query_num)
|
||||
{
|
||||
const auto & query_select = ast.list_of_selects->children.at(query_num)->as<ASTSelectQuery &>();
|
||||
if (!is_trivial_select(query_select))
|
||||
const auto & ast = query.select->as<ASTSelectWithUnionQuery &>();
|
||||
size_t num_selects = ast.list_of_selects->children.size();
|
||||
bool is_trivial_query = true;
|
||||
for (size_t query_num = 0; query_num < num_selects; ++query_num)
|
||||
{
|
||||
is_trivial_query = false;
|
||||
break;
|
||||
const auto & query_select = ast.list_of_selects->children.at(query_num)->as<ASTSelectQuery &>();
|
||||
if (!is_trivial_select(query_select))
|
||||
{
|
||||
is_trivial_query = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_trivial_query)
|
||||
{
|
||||
auto new_context = context;
|
||||
UInt64 max_threads = settings.max_insert_threads;
|
||||
UInt64 min_insert_block_size_rows = settings.min_insert_block_size_rows;
|
||||
new_context.setSetting("max_threads", std::max<UInt64>(1, max_threads));
|
||||
if (min_insert_block_size_rows)
|
||||
new_context.setSetting("max_block_size", min_insert_block_size_rows);
|
||||
if (is_trivial_query)
|
||||
{
|
||||
auto new_context = context;
|
||||
UInt64 max_threads = settings.max_insert_threads;
|
||||
UInt64 min_insert_block_size_rows = settings.min_insert_block_size_rows;
|
||||
new_context.setSetting("max_threads", std::max<UInt64>(1, max_threads));
|
||||
if (min_insert_block_size_rows)
|
||||
new_context.setSetting("max_block_size", min_insert_block_size_rows);
|
||||
|
||||
/// Passing 1 as subquery_depth will disable limiting size of intermediate result.
|
||||
InterpreterSelectWithUnionQuery interpreter_select{
|
||||
query.select, new_context, SelectQueryOptions(QueryProcessingStage::Complete, 1)};
|
||||
res = interpreter_select.execute();
|
||||
/// Passing 1 as subquery_depth will disable limiting size of intermediate result.
|
||||
InterpreterSelectWithUnionQuery interpreter_select{
|
||||
query.select, new_context, SelectQueryOptions(QueryProcessingStage::Complete, 1)};
|
||||
res = interpreter_select.execute();
|
||||
}
|
||||
else
|
||||
{
|
||||
InterpreterSelectWithUnionQuery interpreter_select{
|
||||
query.select, context, SelectQueryOptions(QueryProcessingStage::Complete, 1)};
|
||||
res = interpreter_select.execute();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
DROP TABLE IF EXISTS numbers_squashed;
|
||||
CREATE TABLE numbers_squashed AS system.numbers ENGINE = StripeLog;
|
||||
|
||||
SET optimize_trivial_insert_select = 'false';
|
||||
SET max_block_size = 10000;
|
||||
|
||||
SET min_insert_block_size_rows = 1000000;
|
||||
|
@ -78,7 +78,7 @@ insert into data_01278 select
|
||||
from numbers(100000); -- { serverError 241; }
|
||||
EOL
|
||||
} | {
|
||||
execute --max_memory_usage=$TEST_01278_MEMORY "$@"
|
||||
execute --max_memory_usage=$TEST_01278_MEMORY --optimize_trivial_insert_select='false' "$@"
|
||||
}
|
||||
echo 'select count() from out_01278' | execute
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user