首页 > 解决方案 > 无法理解 postgres 中的哈希分区

问题描述

我有一个虚拟表,我在上面创建了哈希分区,比如

create table hash_test(cat int) partition by hash(cat);
create table h0 partition of hash_test for values with (modulus 2, remainder 0);
create table h1 partition of hash_test for values with (modulus 2, remainder 1);

我在那里添加了一些记录。

insert into hash_test values(0);
insert into hash_test values(1);
and so on....

当我看到两个分区时,我得到以下结果

postgres=# select * from h0;
 cat 
-----
   0
   1
   2
(3 rows)

postgres=# select * from h1;
 cat 
-----
   3
   4
   5
   6
   7
   8
   9
  10
(8 rows)

我将哈希分区理解为, cat modulo 2 == 0 的所有行都将进入分区 h0,否则为 h1。结果与我的理解完全不符。任何人都可以帮我解决这个问题。谢谢你。

标签: postgresql

解决方案


推荐阅读