• 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');

  • 相关阅读:
    Assetbundle资源单一打包,以及加载方法
    VS2010 Chromium编译
    一道思考题
    Windbg源码调试
    C++ static_cast dynamic_cast reinterpret_cast const_cast转换
    条件断点设置
    FFmpeg 2.0编译配置
    error LNK2001: 无法解析的外部符号 _IID_IDirectDraw7
    Windbg常用命令
    DDraw绘图
  • 原文地址:https://www.cnblogs.com/zhangeamon/p/7524480.html
Copyright © 2020-2023  润新知