mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Merge pull request #21579 from azat/dist-query-zero-shards-fix
Fix optimize_skip_unused_shards for zero shards case
This commit is contained in:
commit
3a3f800f6e
@ -48,6 +48,9 @@
|
||||
#include <Interpreters/getTableExpressions.h>
|
||||
#include <Functions/IFunction.h>
|
||||
|
||||
#include <Processors/QueryPlan/ReadFromPreparedSource.h>
|
||||
#include <Processors/Sources/NullSource.h>
|
||||
|
||||
#include <Core/Field.h>
|
||||
#include <Core/Settings.h>
|
||||
|
||||
@ -83,6 +86,7 @@ namespace DB
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int LOGICAL_ERROR;
|
||||
extern const int NOT_IMPLEMENTED;
|
||||
extern const int STORAGE_REQUIRES_PARAMETER;
|
||||
extern const int BAD_ARGUMENTS;
|
||||
@ -532,6 +536,17 @@ void StorageDistributed::read(
|
||||
Block header =
|
||||
InterpreterSelectQuery(query_info.query, context, SelectQueryOptions(processed_stage).analyze()).getSampleBlock();
|
||||
|
||||
/// Return directly (with correct header) if no shard to query.
|
||||
if (query_info.cluster->getShardsInfo().empty())
|
||||
{
|
||||
Pipe pipe(std::make_shared<NullSource>(header));
|
||||
auto read_from_pipe = std::make_unique<ReadFromPreparedSource>(std::move(pipe));
|
||||
read_from_pipe->setStepDescription("Read from NullSource (Distributed)");
|
||||
query_plan.addStep(std::move(read_from_pipe));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const Scalars & scalars = context.hasQueryContext() ? context.getQueryContext().getScalars() : Scalars{};
|
||||
|
||||
bool has_virtual_shard_num_column = std::find(column_names.begin(), column_names.end(), "_shard_num") != column_names.end();
|
||||
@ -546,6 +561,10 @@ void StorageDistributed::read(
|
||||
|
||||
ClusterProxy::executeQuery(query_plan, select_stream_factory, log,
|
||||
modified_query_ast, context, query_info);
|
||||
|
||||
/// This is a bug, it is possible only when there is no shards to query, and this is handled earlier.
|
||||
if (!query_plan.isInitialized())
|
||||
throw Exception("Pipeline is not initialized", ErrorCodes::LOGICAL_ERROR);
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,2 @@
|
||||
create table dist_01756 (dummy UInt8) ENGINE = Distributed('test_cluster_two_shards', 'system', 'one', dummy);
|
||||
select ignore(1), * from dist_01756 where 0 settings optimize_skip_unused_shards=1, force_optimize_skip_unused_shards=1
|
@ -222,3 +222,4 @@
|
||||
01305_polygons_union
|
||||
01306_polygons_intersection
|
||||
01702_system_query_log
|
||||
01759_optimize_skip_unused_shards_zero_shards
|
||||
|
Loading…
Reference in New Issue
Block a user