我可以更改现有Citus表的分配方法吗? [英] Can I change the distribution method on an existing Citus table?
问题描述
在从MySQL迁移到Citus集群的过程中,我使用了 range
分发方法。迁移已完成,但是现在我想将分发方法更改为 hash
。
During a migration from MySQL into a Citus cluster, I used the range
distribution method. The migration is complete, but now I'd like to change the distribution method to hash
.
对于已有数据的表,是否可以将分布方法从 range
更改为 hash
? / strong>
Is there a way to change the distribution method from range
to hash
for an existing table with data already in it?
我想出了以下过程,但不确定是否有效:
I came up with the following procedure, but am not sure it's valid:
- 更新
pg_dist_shard $ c的
minvalue
和maxvalue
列$ c>更改所有分片的表 - 从
更新
到pg_dist_partition
表的分片存储类型列rh
-
COMMIT;
- Update the
minvalue
andmaxvalue
columns of thepg_dist_shard
table for all shards being changed - Update the shard storage type column of the
pg_dist_partition
table fromr
toh
COMMIT;
推荐答案
这是一个好问题。目前,Citus没有提供直接的方法来更改现有数据的分区类型。
That is a good question. Currently, Citus does not provide a direct way to change partition type of existing data.
在范围分区中,记录根据其分区列值和分片最小值放置在分片中。 / max值。如果记录x驻留在分片y中,则表示 y.minvalue< = x.partition_column< = y.maxvalue
。
In range partitioning, records are placed in shards according to their partition column value and shard min/max values. If a record x resides in shard y, then it means y.minvalue <= x.partition_column <= y.maxvalue
.
在哈希分区中,对分区列进行哈希处理,并根据此哈希值路由记录。因此,您在 pg_dist_shard
中看到的最小值/最大值是哈希函数结果的边界值。在这种情况下 y.minvalue< = hash(x.partition_column)< = y.maxvalue
。
In hash partitioning, the partition column is hashed and records are routed according to this hashed value. Therefore, min/max values you see in pg_dist_shard
are the boundary values for the result of the hash function. In this case y.minvalue <= hash(x.partition_column) <= y.maxvalue
.
因此,进行您提到的更改将最终导致分配不正确。为了从范围分区切换到哈希分区,应该重新分配数据。为此,我建议将数据重新加载到一个空的哈希分区表中。
Therefore, doing the changes you have mentioned would end up with an incorrect distribution. In order to switch from range partition to hash partition, the data should be re-distributed. To do that, I suggest reloading the data to an empty hash-partitioned table.
有关更多信息,您可以参考使用分布式表和哈希分布的Citus文档部分。
For more information, you can refer to Working with Distributed Tables and Hash Distribution sections of Citus Documentation.
这篇关于我可以更改现有Citus表的分配方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!