cluster, clusterAllReplicas

    clusterAllReplicas function — same as cluster, but all replicas are queried. Each replica in a cluster is used as a separate shard/connection.

    Note

    All available clusters are listed in the system.clusters table.

    Syntax

    • cluster_name – Name of a cluster that is used to build a set of addresses and connection parameters to remote and local servers.
    • db.table or db, table - Name of a database and a table.

    Returned value

    The dataset from clusters.

    Using Macros

    can contain macros — substitution in curly brackets. The substituted value is taken from the section of the server configuration file.

    1. SELECT * FROM cluster('{cluster}', default.example_table);

    Usage and Recommendations

    Using the cluster and clusterAllReplicas table functions are less efficient than creating a Distributed table because in this case, the server connection is re-established for every request. When processing a large number of queries, please always create the Distributed table ahead of time, and do not use the cluster and clusterAllReplicas table functions.

    The and clusterAllReplicas table functions can be useful in the following cases:

    • Accessing a specific cluster for data comparison, debugging, and testing.
    • Infrequent distributed requests that are made manually.

    Connection settings like host, port, user, password, compression, secure are taken from config section. See details in Distributed engine.