Citus 是否公开了用于修剪碎片的哈希函数?

Does Citus expose the hash function used to prune shards?

This 文档很好地描述了如何准备范围分区数据以插入到目标分片中。如果我知道确切的哈希函数,我可以类似地准备数据以插入到哈希分布式表中。

源代码中, but I could not find it where I expected暗示了这样的功能。

Citus 在哪里确定分片修剪期间要使用的哈希函数?

我们最近发布了 Citus 5.1。它在散列分区表上具有 COPY 支持,并且 COPY 至少比 copy_to_distributed_table(现已弃用)快一个数量级。我们将很快更新我们的文档以阐明我们的 COPY 支持。

您可以从 Red Hat or Debian PGDG 存储库安装 Citus 5.1。

metdos 的回答有助于解决潜在的问题(数据迁移缓慢),但看起来您仍然希望对 "Does Citus expose the hash function it uses?"

的原始问题有一个明确的答案

这个问题的答案是"No, not directly, but it does expose the cached information about each distributed table and you can use that to discover the hash function, which you'd just need to call"。下面是如何做到这一点的草图......

函数 DistributedTableCacheEntry takes a table's identifier as its input and returns a struct 填充了将用于 table 的散列函数。

它是一个 public 函数,由 Citus 安装的 headers 公开,所以你应该可以 link 反对它写一个 C-level PostgreSQL 函数给定它所属的 table 的分区值。请参阅 FastShardPruning 了解如何使用它。

签名可能如下所示:CREATE FUNCTION citus_hash(distrel regclass, anyelement partitionval) RETURNS integer。伪代码:

  1. distrel 作为参数调用 DistributedTableCacheEntry
  2. 确保 table 是 hash-partitioned
  3. 从缓存条目中获取哈希函数
  4. 确保 partitionval 是预期的类型
  5. partitionval 调用哈希函数并 return 结果

请参阅 PostgreSQL 的 own documentation 了解如何编写此类函数。