@@ -50,6 +50,7 @@ namespace DB
5050{
5151namespace Setting
5252{
53+ extern const SettingsUInt64 allow_experimental_parallel_reading_from_replicas;
5354 extern const SettingsBool async_query_sending_for_remote;
5455 extern const SettingsBool async_socket_for_remote;
5556 extern const SettingsString cluster_for_parallel_replicas;
@@ -600,6 +601,7 @@ void ReadFromRemote::addPipe(Pipes & pipes, const ClusterProxy::SelectStreamFact
600601 bool add_extremes = false ;
601602 bool async_read = context->getSettingsRef ()[Setting::async_socket_for_remote];
602603 bool async_query_sending = context->getSettingsRef ()[Setting::async_query_sending_for_remote];
604+ bool parallel_replicas_disabled = context->getSettingsRef ()[Setting::allow_experimental_parallel_reading_from_replicas] == 0 ;
603605 if (stage == QueryProcessingStage::Complete)
604606 {
605607 if (const auto * ast_select = shard.query ->as <ASTSelectQuery>())
@@ -690,14 +692,16 @@ void ReadFromRemote::addPipe(Pipes & pipes, const ClusterProxy::SelectStreamFact
690692 shard.shard_info .pool , query_string, shard.header , context, throttler, scalars, external_tables, stage_to_use, shard.query_plan );
691693 remote_query_executor->setLogger (log);
692694
693- if (context->canUseTaskBasedParallelReplicas ())
695+ if (context->canUseTaskBasedParallelReplicas () || parallel_replicas_disabled )
694696 {
695697 // when doing parallel reading from replicas (ParallelReplicasMode::READ_TASKS) on a shard:
696698 // establish a connection to a replica on the shard, the replica will instantiate coordinator to manage parallel reading from replicas on the shard.
697699 // The coordinator will return query result from the shard.
698700 // Only one coordinator per shard is necessary. Therefore using PoolMode::GET_ONE to establish only one connection per shard.
699701 // Using PoolMode::GET_MANY for this mode will(can) lead to instantiation of several coordinators (depends on max_parallel_replicas setting)
700702 // each will execute parallel reading from replicas, so the query result will be multiplied by the number of created coordinators
703+ //
704+ // In case parallel replicas are disabled, there also should be a single connection to each shard to prevent result duplication
701705 remote_query_executor->setPoolMode (PoolMode::GET_ONE);
702706 }
703707 else
0 commit comments