Can I change the distribution method on an existing Citus table?

浪尽此生 提交于 2019-12-22 05:54:13

问题


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.

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:

  1. Update the minvalue and maxvalue columns of the pg_dist_shard table for all shards being changed
  2. Update the shard storage type column of the pg_dist_partition table from r to h
  3. COMMIT;

回答1:


That is a good question. Currently, Citus does not provide a direct way to change partition type of existing data.

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.

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.

For more information, you can refer to Working with Distributed Tables and Hash Distribution sections of Citus Documentation.



来源:https://stackoverflow.com/questions/36908508/can-i-change-the-distribution-method-on-an-existing-citus-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!