os: Centos 7.4db: postgresql 12.2 postgresql 12 的分区表已经比较完善。 版本 # cat /etc/centos-release CentOS linux release 7.4.1708 (
os: Centos 7.4
db: postgresql 12.2
postgresql 12 的分区表已经比较完善。
# cat /etc/centos-release
CentOS linux release 7.4.1708 (Core)
#
# su - postgres
Last login: Thu Mar 19 14:47:45 CST 2020 on pts/0
$
$ psql
psql (12.2)
Type "help" for help.
postgres=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 12.2 on x86_64-pc-linux-gnu, compiled by GCc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
(1 row)
postgres=# show enable_partition_pruning;
enable_partition_pruning
--------------------------
on
(1 row)
postgres=# select name,setting from pg_settings where name like ‘%partition%‘;
name | setting
-----------------------------------+---------
enable_partition_pruning | on
enable_partitionwise_aggregate | off
enable_partitionwise_join | off
(3 rows)
for list partitioning, the partition key must consist of a single column or expression.
postgres=# CREATE TABLE cities (
city_id bigint not null,
name text not null,
population bigint
) PARTITION BY LIST (name);
CREATE TABLE cities_1 PARTITION OF cities FOR VALUES IN (‘A‘);
CREATE TABLE cities_2 PARTITION OF cities FOR VALUES IN (‘B‘);
CREATE TABLE cities_3 PARTITION OF cities FOR VALUES IN (‘C‘);
CREATE TABLE cities_4 PARTITION OF cities FOR VALUES IN (‘D‘);
postgres=# d+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+-------------------------------+-------------------+----------+------------+-------------
public | cities | partitioned table | postgres | 0 bytes |
public | cities_1 | table | postgres | 8192 bytes |
public | cities_2 | table | postgres | 8192 bytes |
public | cities_3 | table | postgres | 8192 bytes |
public | cities_4 | table | postgres | 8192 bytes |
(5 rows)
postgres=# select * from pg_inherits;
inhrelid | inhparent | inhseqno
----------+-----------+----------
16727 | 16724 | 1
16733 | 16724 | 1
16739 | 16724 | 1
16745 | 16724 | 1
(4 rows)
postgres=# insert into cities
select 1,‘A‘,1
uNIOn all
select 2,‘B‘,2
union all
select 3,‘C‘,3
union all
select 4,‘D‘,4
;
postgres=# d+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+-------------------------------+-------------------+----------+------------+-------------
public | cities | partitioned table | postgres | 0 bytes |
public | cities_1 | table | postgres | 16 kB |
public | cities_2 | table | postgres | 16 kB |
public | cities_3 | table | postgres | 16 kB |
public | cities_4 | table | postgres | 16 kB |
(5 rows)
postgres=# explain select * from cities where name = ‘B‘;
QUERY PLAN
----------------------------------------------------------
Seq Scan on cities_2 (cost=0.00..23.38 rows=5 width=48)
Filter: (name = ‘B‘::text)
(2 rows)
postgres=# explain select * from cities where name in (‘B‘,‘C‘);
QUERY PLAN
-----------------------------------------------------------------
Append (cost=0.00..46.86 rows=22 width=48)
-> Seq Scan on cities_2 (cost=0.00..23.38 rows=11 width=48)
Filter: (name = ANY (‘{B,C}‘::text[]))
-> Seq Scan on cities_3 (cost=0.00..23.38 rows=11 width=48)
Filter: (name = ANY (‘{B,C}‘::text[]))
(5 rows)
参考:
https://www.postgresql.org/docs/12/sql-createtable.html
Https://www.postgresql.org/docs/12/ddl-partitioning.html
postgresql 12 数据库分区表之 list
原文地址:https://www.cnblogs.com/telwanggs/p/13792771.html
--结束END--
本文标题: postgresql 12 数据库分区表之 list
本文链接: https://lsjlt.com/news/7916.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0