mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-28 02:21:59 +00:00
better implementation
Signed-off-by: Duc Canh Le <duccanh.le@ahrefs.com>
This commit is contained in:
parent
10d3a9b818
commit
1929901c7d
@ -122,41 +122,18 @@ void SelectStreamFactory::createForShard(
|
||||
auto it = objects_by_shard.find(shard_info.shard_num);
|
||||
if (it != objects_by_shard.end())
|
||||
replaceMissedSubcolumnsByConstants(storage_snapshot->object_columns, it->second, query_ast);
|
||||
|
||||
const auto & settings = context->getSettingsRef();
|
||||
ASTPtr query;
|
||||
|
||||
if (settings.max_execution_time_leaf.value != 0)
|
||||
{
|
||||
query = query_ast->clone();
|
||||
/// Replace 'max_execution_time' of this sub-query with 'max_execution_time_leaf' and 'timeout_overflow_mode'
|
||||
/// with 'timeout_overflow_mode_leaf'
|
||||
if (auto * select = query->as<ASTSelectQuery>())
|
||||
{
|
||||
auto query_settings = select->settings();
|
||||
if (!query_settings)
|
||||
query_settings = std::make_shared<ASTSetQuery>();
|
||||
|
||||
query_settings->as<ASTSetQuery &>().is_standalone = false;
|
||||
auto & changes = query_settings->as<ASTSetQuery &>().changes;
|
||||
changes.setSetting("max_execution_time", settings.max_execution_time_leaf.value.totalSeconds());
|
||||
changes.setSetting("timeout_overflow_mode", settings.timeout_overflow_mode_leaf.toString());
|
||||
select->setExpression(ASTSelectQuery::Expression::SETTINGS, std::move(query_settings));
|
||||
}
|
||||
}
|
||||
else
|
||||
query = query_ast;
|
||||
|
||||
|
||||
auto emplace_local_stream = [&]()
|
||||
{
|
||||
local_plans.emplace_back(createLocalPlan(
|
||||
query, header, context, processed_stage, shard_info.shard_num, shard_count));
|
||||
query_ast, header, context, processed_stage, shard_info.shard_num, shard_count));
|
||||
};
|
||||
|
||||
auto emplace_remote_stream = [&](bool lazy = false, time_t local_delay = 0)
|
||||
{
|
||||
remote_shards.emplace_back(Shard{
|
||||
.query = query,
|
||||
.query = query_ast,
|
||||
.main_table = main_table,
|
||||
.header = header,
|
||||
.shard_info = shard_info,
|
||||
|
@ -141,6 +141,14 @@ ContextMutablePtr updateSettingsForCluster(const Cluster & cluster,
|
||||
new_settings.allow_experimental_parallel_reading_from_replicas = false;
|
||||
}
|
||||
|
||||
if (settings.max_execution_time_leaf.value > 0)
|
||||
{
|
||||
/// Replace 'max_execution_time' of this sub-query with 'max_execution_time_leaf' and 'timeout_overflow_mode'
|
||||
/// with 'timeout_overflow_mode_leaf'
|
||||
new_settings.max_execution_time = settings.max_execution_time_leaf;
|
||||
new_settings.timeout_overflow_mode = settings.timeout_overflow_mode_leaf;
|
||||
}
|
||||
|
||||
auto new_context = Context::createCopy(context);
|
||||
new_context->setSettings(new_settings);
|
||||
return new_context;
|
||||
|
@ -1,3 +1,3 @@
|
||||
SELECT count() FROM cluster('test_cluster_two_shards', view( SELECT * FROM numbers(1000000000) )) SETTINGS max_execution_time_leaf = 1; -- { serverError 159 }
|
||||
SELECT count() FROM cluster('test_cluster_two_shards', view( SELECT * FROM numbers(100000000000) )) SETTINGS max_execution_time_leaf = 1; -- { serverError 159 }
|
||||
-- Can return partial result
|
||||
SELECT IF(count() > 0, 'OK', 'FAIL') FROM cluster('test_cluster_two_shards', view( SELECT * FROM numbers(1000000000) )) SETTINGS max_execution_time_leaf = 1, timeout_overflow_mode_leaf = 'break';
|
||||
SELECT IF(count() > 0, 'OK', 'FAIL') FROM cluster('test_cluster_two_shards', view( SELECT * FROM numbers(100000000000) )) SETTINGS max_execution_time_leaf = 1, timeout_overflow_mode_leaf = 'break';
|
||||
|
Loading…
Reference in New Issue
Block a user