zoukankan      html  css  js  c++  java
  • Postgresql 分区表 一

    Postgres 10 新特性 分区表

    http://francs3.blog.163.com/blog/static/40576727201742103158135/

    Postgres 10 之前分区表插件实现 pg_pathman

    https://yq.aliyun.com/articles/62314#25

    这里简单记录基于触发器或规则实现

    创建分区表
    CREATE TABLE RECORD ( --主表
    record_id int NOT NULL,
    record_pro text NOT NULL,
    city_id int,
    city_name text
    );

    CREATE TABLE RECORD_DEFALUT (CHECK(city_id = 0)) INHERITS (RECORD); --DEFAULT
    CREATE TABLE RECORD_BJ (CHECK(city_id = 1)) INHERITS (RECORD); --北京
    CREATE TABLE RECORD_SH (CHECK(city_id = 2)) INHERITS (RECORD); --上海
    CREATE TABLE RECORD_GZ (CHECK(city_id = 3)) INHERITS (RECORD); --广州
    CREATE TABLE RECORD_SZ (CHECK(city_id = 4)) INHERITS (RECORD); --深圳

    创建规则

    CREATE RULE RECORD_DEFAULT_RULE_INSERT AS
    ON INSERT TO RECORD WHERE city_id = 0
    DO INSTEAD
    INSERT INTO RECORD_DEFALUT VALUES (NEW.*);

    CREATE RULE RECORD_BJ_RULE_INSERT AS
    ON INSERT TO RECORD WHERE city_id = 1
    DO INSTEAD
    INSERT INTO RECORD_BJ VALUES (NEW.*);

    CREATE RULE RECORD_SH_RULE_INSERT AS
    ON INSERT TO RECORD WHERE city_id = 2
    DO INSTEAD
    INSERT INTO RECORD_SH VALUES (NEW.*);

    CREATE RULE RECORD_GZ_RULE_INSERT AS
    ON INSERT TO RECORD WHERE city_id = 3
    DO INSTEAD
    INSERT INTO RECORD_GZ VALUES (NEW.*);

    CREATE RULE RECORD_SZ_RULE_INSERT AS
    ON INSERT TO RECORD WHERE city_id = 4
    DO INSTEAD
    INSERT INTO RECORD_SZ VALUES (NEW.*);

    输入模拟数据

    truncate RECORD;

    INSERT INTO RECORD
    SELECT generate_series(1, 100),'recode', (int4(random()*10))%5,'city';

    INSERT INTO RECORD VALUES(1 , 'recode', 3 , 'city');
    INSERT INTO RECORD VALUES(2 , 'recode' , 3 , 'city');
    INSERT INTO RECORD VALUES(3 , 'recode' , 0 , 'city');
    INSERT INTO RECORD VALUES(4 , 'recode' , 0 , 'city');
    INSERT INTO RECORD VALUES(5 , 'recode' , 4 , 'city');
    INSERT INTO RECORD VALUES(6 , 'recode' , 3 , 'city');
    INSERT INTO RECORD VALUES(7 , 'recode' , 3 , 'city');
    INSERT INTO RECORD VALUES(8 , 'recode' , 0 , 'city');
    INSERT INTO RECORD VALUES(9 , 'recode' , 0 , 'city');
    INSERT INTO RECORD VALUES(10 , 'recode', 2, 'city');

  • 相关阅读:
    ARM汇编指令
    Linux系统里如何彻底的清空终端屏幕?
    Linux命令(16)压缩,解压文件
    Linux命令(18)查看当前用户who、whoami、who am i
    Linux命令(17)du 查看文件和目录磁盘使用情况
    Mongodb(3)插入文档,更新文档,删除文档
    Mongodb(2)创建数据库,删除数据库,创建集合,删除集合,显示文档内容
    Mongodb(1)如何存储以及简介
    Linux命令(15)查看系统版本信息
    Python 结巴分词(2)关键字提取
  • 原文地址:https://www.cnblogs.com/zhangeamon/p/7524480.html
Copyright © 2011-2022 走看看