预测 Postgres 中哈希分区的分区号

问题描述

在 Postgres 11 上有这个简单的表和分区定义

Place

在这个表中插入一个值 14 并检查它所在的分区

ap=# \d+ hp
                              Partitioned table "public.hp"
 Column |  Type  | Collation | Nullable | Default | Storage | Stats target | Description 
--------+--------+-----------+----------+---------+---------+--------------+-------------
 foo    | bigint |           |          |         | plain   |              | 
Partition key: HASH (foo)
Partitions: hp_0 FOR VALUES WITH (modulus 10,remainder 0),hp_1 FOR VALUES WITH (modulus 10,remainder 1),hp_2 FOR VALUES WITH (modulus 10,remainder 2),hp_3 FOR VALUES WITH (modulus 10,remainder 3),hp_4 FOR VALUES WITH (modulus 10,remainder 4),hp_5 FOR VALUES WITH (modulus 10,remainder 5),hp_6 FOR VALUES WITH (modulus 10,remainder 6),hp_7 FOR VALUES WITH (modulus 10,remainder 7),hp_8 FOR VALUES WITH (modulus 10,remainder 8),hp_9 FOR VALUES WITH (modulus 10,remainder 9)

无法解释 14 是如何落在分区 hp_0 中的。从我收集到的 bigint 哈希函数是 hashint8

insert into hp values(14);
SELECT tableoid::regclass,* FROM hp;
 tableoid | foo 
----------+-----
 hp_0     |  14
(1 row)

-1018458207 mod 10 将是 -7

-1018458207 转换为无符号整数和 mod 10 ==> 3276509089 mod 10 = 9

所以无法看到它是如何落在 hp_0 中的,即余数为 0。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)