Use local shard if there are no remote connections

This commit is contained in:
Maksim Kita 2021-04-16 16:01:53 +03:00
parent b5cbbce314
commit d88e0b1b44
3 changed files with 22 additions and 1 deletions

View File

@ -160,7 +160,7 @@ void SelectStreamFactory::createForShard(
const auto & settings = context->getSettingsRef();
if (settings.prefer_localhost_replica && shard_info.isLocal())
if ((settings.prefer_localhost_replica && shard_info.isLocal()) || !shard_info.hasRemoteConnections())
{
StoragePtr main_table_storage;

View File

@ -0,0 +1,19 @@
DROP DATABASE IF EXISTS 01813_db;
CREATE DATABASE 01813_db;
DROP TABLE IF EXISTS 01813_db.data;
CREATE TABLE 01813_db.data (a Int64, b Int64) ENGINE = TinyLog();
DROP TABLE IF EXISTS 01813_db.data_distributed;
CREATE TABLE 01813_db.data_distributed (a Int64, b Int64) ENGINE = Distributed(test_shard_localhost, '01813_db', data);
INSERT INTO 01813_db.data VALUES (0, 0);
SET prefer_localhost_replica = 1;
SELECT a / (SELECT sum(number) FROM numbers(10)) FROM 01813_db.data_distributed;
SET prefer_localhost_replica = 0;
SELECT a / (SELECT sum(number) FROM numbers(10)) FROM 01813_db.data_distributed;
DROP TABLE 01813_db.data_distributed;
DROP TABLE 01813_db.data;