postgres=# explain analyze select * from h where id = 1; QUERY PLAN ---------------------------------------------------------------------------------------------------- Append (cost=0.00..41.88 rows=13 width=4) (actual time=0.022..0.026 rows=1 loops=1) -> Seq Scan on h3 (cost=0.00..41.88 rows=13 width=4) (actual time=0.014..0.017 rows=1 loops=1) Filter: (id = 1) Rows Removed by Filter: 4 Planning time: 0.271 ms Execution time: 0.069 ms (6 rows)
postgres=# explain analyze select * from h where id = 1 or id = 20; QUERY PLAN ---------------------------------------------------------------------------------------------------- Append (cost=0.00..96.50 rows=50 width=4) (actual time=0.015..0.028 rows=2 loops=1) -> Seq Scan on h3 (cost=0.00..48.25 rows=25 width=4) (actual time=0.014..0.017 rows=1 loops=1) Filter: ((id = 1) OR (id = 20)) Rows Removed by Filter: 4 -> Seq Scan on h4 (cost=0.00..48.25 rows=25 width=4) (actual time=0.006..0.008 rows=1 loops=1) Filter: ((id = 1) OR (id = 20)) Rows Removed by Filter: 10 Planning time: 0.315 ms Execution time: 0.080 ms (9 rows)
postgres=# explain analyze select * from h where id in (1,2,3); QUERY PLAN ---------------------------------------------------------------------------------------------------- Append (cost=0.00..90.12 rows=76 width=4) (actual time=0.015..0.028 rows=3 loops=1) -> Seq Scan on h3 (cost=0.00..45.06 rows=38 width=4) (actual time=0.014..0.018 rows=2 loops=1) Filter: (id = ANY ('{1,2,3}'::integer[])) Rows Removed by Filter: 3 -> Seq Scan on h4 (cost=0.00..45.06 rows=38 width=4) (actual time=0.005..0.008 rows=1 loops=1) Filter: (id = ANY ('{1,2,3}'::integer[])) Rows Removed by Filter: 10 Planning time: 0.377 ms Execution time: 0.073 ms (9 rows)
--- only accept "list" and "range" as partitioning strategy -CREATETABLE partitioned ( - a int -) PARTITIONBYHASH (a); -ERROR: unrecognized partitioning strategy "hash"
postgres=# \d+ h* Table "public.h" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description --------+---------+-----------+----------+---------+---------+--------------+------------- id | integer | | | | plain | | Partition key: HASH (id) Partitions: h1 SERIAL NUMBER 0, h2 SERIAL NUMBER 1
Table "public.h1" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description --------+---------+-----------+----------+---------+---------+--------------+------------- id | integer | | | | plain | | Partition of: h SERIAL NUMBER 0 Partition constraint: (id IS NOT NULL)
Table "public.h2" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description --------+---------+-----------+----------+---------+---------+--------------+------------- id | integer | | | | plain | | Partition of: h SERIAL NUMBER 1 Partition constraint: (id IS NOT NULL)
限制
不支持 attach、detach
1 2 3 4 5 6
postgres=# create table h3 (id int); CREATETABLE postgres=# alter table h attach partition h3; ERROR: hashpartitiondonot support attach operation postgres=# alter table h detach partition h2; ERROR: hashpartitiondonot support detach operation
不支持 drop 分区子表
1 2
postgres=# drop table h2; ERROR: hash partition "h2" can not be dropped