查看数据库版本

select version();
PostgreSQL 10.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18), 64-bit

list 分区
创建分区主表 drop table tmp_par_list

create table tmp_par_list ( id int8,random_char varchar(100),day_id varchar(8)
) partition by list(day_id);

创建分区从表

CREATE TABLE tmp_par_list_p20171130   PARTITION OF tmp_par_list FOR VALUES in ('20171130');
CREATE TABLE tmp_par_list_p20171201   PARTITION OF tmp_par_list FOR VALUES in ('20171201');
CREATE TABLE tmp_par_list_p20171202   PARTITION OF tmp_par_list FOR VALUES in ('20171202');
CREATE TABLE tmp_par_list_p20171203   PARTITION OF tmp_par_list FOR VALUES in ('20171203');

创建索引

create index idx_tmp_par_list_p20171130_x1 on tmp_par_list_p20171130(day_id);
create index idx_tmp_par_list_p20171201_x1 on tmp_par_list_p20171201(day_id);
create index idx_tmp_par_list_p20171202_x1 on tmp_par_list_p20171202(day_id);
create index idx_tmp_par_list_p20171203_x1 on tmp_par_list_p20171203(day_id);

插入数据

insert into tmp_par_list
select *
from (select generate_series(1, 5) as id, md5(random()::text) as info , '20171130' as day_id union allselect generate_series(1, 5) as id, md5(random()::text) as info , '20171201' as day_id union allselect generate_series(1, 5) as id, md5(random()::text) as info , '20171202' as day_id union allselect generate_series(1, 5) as id, md5(random()::text) as info , '20171203' as day_id ) t0
;

查看数据

select * from public.tmp_par_list order by day_id,id ;select * from public.tmp_par_list_p20171130;
select * from public.tmp_par_list_p20171201;
select * from public.tmp_par_list_p20171202;
select * from public.tmp_par_list_p20171203;

查看执行计划

explain
select *from tmp_par_list tpwhere 1=1Append  (cost=0.00..51.20 rows=1120 width=260)->  Seq Scan on tmp_par_list_p20171130 tp  (cost=0.00..12.80 rows=280 width=260)->  Seq Scan on tmp_par_list_p20171201 tp_1  (cost=0.00..12.80 rows=280 width=260)->  Seq Scan on tmp_par_list_p20171202 tp_2  (cost=0.00..12.80 rows=280 width=260)->  Seq Scan on tmp_par_list_p20171203 tp_3  (cost=0.00..12.80 rows=280 width=260)explain
select *from tmp_par_list tpwhere 1=1and tp.day_id='20171201'Append  (cost=0.15..8.17 rows=1 width=260)->  Index Scan using idx_tmp_par_list_p20171201_x1 on tmp_par_list_p20171201 tp  (cost=0.15..8.17 rows=1 width=260)Index Cond: ((day_id)::text = '20171201'::text)explain
select *from tmp_par_list tpwhere 1=1and tp.day_id in ( '20171201' , '20171202')Append  (cost=0.00..27.00 rows=6 width=260)->  Seq Scan on tmp_par_list_p20171201 tp  (cost=0.00..13.50 rows=3 width=260)Filter: ((day_id)::text = ANY ('{20171201,20171202}'::text[]))->  Seq Scan on tmp_par_list_p20171202 tp_1  (cost=0.00..13.50 rows=3 width=260)Filter: ((day_id)::text = ANY ('{20171201,20171202}'::text[]))

插入分区外数据

insert into tmp_par_list
select *
from (select generate_series(1, 5) as id, md5(random()::text) as info , '20171129' as day_id ) t0
;ERROR:  no partition of relation "tmp_par_list" found for row
DETAIL:  Partition key of the failing row contains (day_id) = (20171129).insert into tmp_par_list
select *
from (select generate_series(1, 5) as id, md5(random()::text) as info , '20171204' as day_id ) t0
;ERROR:  no partition of relation "tmp_par_list" found for row
DETAIL:  Partition key of the failing row contains (day_id) = (20171204).

转载于:https://www.cnblogs.com/ctypyb2002/p/9793080.html

postgresql 10.1 分区表之 list 分区相关推荐

  1. PostgreSQL中的分区表(创建分区)–第1部分

    PostgreSQL中的分区表很容易做到,它涉及PostgreSQL的继承概念和触发器. 在这里,我提供了一个示例来演示如何在PostgreSQL中对表进行分区. 在继续之前,请了解一些基本概念,例如 ...

  2. PostgreSQL 分区表, pg_pathman ,PostgreSQL 10介绍及性能对比(转载)

    转载自:https://my.oschina.net/yonj1e/blog/868402 PostgreSQL 分区表, pg_pathman ,PostgreSQL 10介绍及性能对比 原 yon ...

  3. PostgreSQL 查询涉及分区表过多导致的性能问题 - 性能诊断与优化(大量BIND, spin lock, SLEEP进程)

    摘要: 标签 PostgreSQL , 分区表 , bind , spin lock , 性能分析 , sleep 进程 , CPU空转 , cache 背景 实际上我写过很多文档,关于分区表的优化: ...

  4. 元旦技术大礼包 - 2017金秋将要发布的PostgreSQL 10.0已装备了哪些核武器?

    标签 PostgreSQL , 10.0 , 金秋 , 元旦 , 大礼包 , commitfest 背景 早上送给大家的新年大礼包,一年一个大版本是PostgreSQL社区的传统,虽然发布时间通常为秋 ...

  5. PostgreSQL中的分区表

    PostgreSQL中的分区表 参考:https://www.xmmup.com/pgzhongdefenqubiao.html#PG_11xin_te_xing PostgreSQL分区的意思是把逻 ...

  6. postgresql内置分区表(声明式划分)

    文章目录 一.分区表简介 二.如何创建分区表 1.建主表 2.创建分区 3.创建索引 三.移除分区表 四.Spring Data JPA和分区表 一.分区表简介 存储数据量很大时如果用单表储存数据,查 ...

  7. “王者对战”之 MySQL 8 vs PostgreSQL 10

    本文是对两大开源关系型数据库MySQL.PostgreSQL做了详细的对比,欢迎大家在评论区发表自己的见解. 在这些版本之前,人们普遍认为,Postgres 在功能集表现更出色,也因其"学院 ...

  8. PostgreSQL 10 高可用 本地SSD盘 版本发布

    信息摘要: 相比原 9.4 版本有多项功能更新,但由于架构限制当前不支持 PostgreSQL 9.4 高可用版 及 10 基础版 直接升级 适用客户: 所有 PostgreSQL 数据库用户 版本/ ...

  9. Mysql分区表概述、分区类型、分区管理

    另有一篇简单易懂的好文章帮助学习 Mysql分区表的原理和优缺点以及注意点 一.分区概述 分区是指根据一定的规则,数据库把一个表分解成多个更小的.更容易管理的部分.分区有利于管理非常大的表. MySQ ...

最新文章

  1. Topcoder SRM 657DIV2
  2. SAP QM 事务代码QPR3显示一个Physical Sample Record
  3. 微服务为什么一定要用docker
  4. 计算机视觉 | 计算机界国际学术会议和期刊目录
  5. opencv第三方库JAVA接口,SpringBoot使用OpenCV示例总结
  6. scrapy爬虫实战分享
  7. jsoncpp之初体验
  8. 线性结构 —— ST 表与 RMQ
  9. 将windows c盘安装在linux,将WindowsC盘hda1安装在Linux文件系统的/winsys目录下,命令是()。...
  10. rustdesk:远控工具说明
  11. url 编码(percentcode 百分号编码)
  12. Windows设置访问白名单
  13. RFID工作频率的分类
  14. win8.1产品安装临时密钥
  15. android 合并分区说明,Android系统手机sd卡分区后合并图文详解
  16. php分割金额_PHP实现红包金额拆分算法案例详解
  17. 【PowerDesigner】Mysql设计工具 16.5破解
  18. 3. Unity之三维模型
  19. 搭建SPA项目SPA项目中使用路由嵌套路由
  20. 上海领科作为A-Level领军学校,为什么要开设IB课程?

热门文章

  1. 用Lambda武装你的Java: 集合转换
  2. 使用getopts处理选项
  3. 批量去除歌曲tag标签
  4. 操作系统中的进程与线程
  5. SQL中 decode()函数简介
  6. 第一次用.net2.0 LOGIN登陆控件的困惑和解决方法
  7. nginx模型概念和配置文件结构
  8. Ajax 完整教程(转载)
  9. OC中的自动引用计数
  10. ArcGIS Server开发示例诠释