> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Distributed DDL 文档

# Distributed DDL 查询（ON CLUSTER 子句）

默认情况下，`CREATE`、`DROP`、`ALTER` 和 `RENAME` 查询仅会影响执行它们的当前服务器。在集群环境中，可以通过 `ON CLUSTER` 子句以分布式方式执行这类查询。

例如，以下查询会在 `cluster` 中的每个主机上创建 `all_hits` `Distributed` 表：

```sql theme={null}
CREATE TABLE IF NOT EXISTS all_hits ON CLUSTER cluster (p Date, i Int32) ENGINE = Distributed(cluster, default, hits)
```

为了让这些查询正确运行，每台主机都必须具有相同的集群定义 (为简化配置同步，你可以使用 ZooKeeper 中的替换) 。它们还必须连接到 ZooKeeper 服务器。

查询的本地版本最终会在集群中的每台主机上执行，即使某些主机当前不可用。

<Warning>
  在单台主机内执行查询的顺序是有保证的。
</Warning>
