Merge pull request #11114 from azat/max_threads-simple-query-optimization-fix

Do not reserve extra threads after max threads optimization for simple queries
This commit is contained in:
Nikolai Kochetov 2020-05-25 14:05:46 +03:00 committed by GitHub
commit c83014bc76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 1 deletions

View File

@ -1533,7 +1533,7 @@ void InterpreterSelectQuery::executeFetchColumns(
if constexpr (pipeline_with_processors)
{
if (streams.size() == 1 || pipes.size() == 1)
pipeline.setMaxThreads(streams.size());
pipeline.setMaxThreads(1);
/// Unify streams. They must have same headers.
if (streams.size() > 1)

View File

@ -271,6 +271,11 @@ QueryPipeline InterpreterSelectWithUnionQuery::executeWithProcessors()
{
auto common_header = getCommonHeaderForUnion(headers);
main_pipeline.unitePipelines(std::move(pipelines), common_header);
// nested queries can force 1 thread (due to simplicity)
// but in case of union this cannot be done.
UInt64 max_threads = context->getSettingsRef().max_threads;
main_pipeline.setMaxThreads(std::min<UInt64>(nested_interpreters.size(), max_threads));
}
main_pipeline.addInterpreterContext(context);

View File

@ -0,0 +1,21 @@
DROP TABLE IF EXISTS data_01283;
CREATE TABLE data_01283 engine=MergeTree()
ORDER BY key
PARTITION BY key
AS SELECT number key FROM numbers(10);
SET log_queries=1;
SELECT * FROM data_01283 LIMIT 1 FORMAT Null;
SET log_queries=0;
SYSTEM FLUSH LOGS;
-- 1 for PullingAsyncPipelineExecutor::pull
-- 1 for AsynchronousBlockInputStream
SELECT
throwIf(count() != 1, 'no query was logged'),
throwIf(length(thread_ids) != 2, 'too many threads used')
FROM system.query_log
WHERE type = 'QueryFinish' AND query LIKE '%data_01283 LIMIT 1%'
GROUP BY thread_ids
FORMAT Null;