zoukankan      html  css  js  c++  java
  • [Postgres]关于Postgres的INHERIT,分表

    实在是很强大的功能

    可以通过Check的制约把结构相同的表合并起来,或者反过来说,可以在一个表名下数据库自动的根据Check条件往对应的分表里存储数据

    [USER_DATA表]

    CREATE TABLE test."USER_DATA"
    (
    "MAC" character varying(12) NOT NULL,
    "ID" character(3) NOT NULL,
    "YEARS" numeric(6,0) NOT NULL,
    "DAY" numeric(2,0) NOT NULL,
    "HOUR" numeric(2,0) NOT NULL,
    CONSTRAINT "USER_DATA_pkey" PRIMARY KEY ("MAC", "ID", "YEARS", "DAY", "HOUR")
    )

    [USER_DATA]的分表1[USER_DATA_201310]

    CREATE TABLE test."USER_DATA_201310"
    (
    -- Inherit from table test."USER_DATA": "MAC" character varying(12) NOT NULL,
    -- Inherit from table test."USER_DATA": "ID" character(3) NOT NULL,
    -- Inherit from table test."USER_DATA": "YEARS" numeric(6,0) NOT NULL,
    -- Inherit from table test."USER_DATA": "DAY" numeric(2,0) NOT NULL,
    -- Inherit from table test."USER_DATA": "HOUR" numeric(2,0) NOT NULL,
    CONSTRAINT "USER_DATA_201210_pkey" PRIMARY KEY ("MAC", "ID", "YEARS", "DAY", "HOUR"),
    CONSTRAINT "USER_DATA_YEARS_check" CHECK ("YEARS" = 201310::numeric)
    )
    INHERITS (test."USER_DATA")

    [USER_DATA]的分表2[USER_DATA_201311]

    CREATE TABLE test."USER_DATA_201311"
    (
    -- Inherit from table test."USER_DATA": "MAC" character varying(12) NOT NULL,
    -- Inherit from table test."USER_DATA": "ID" character(3) NOT NULL,
    -- Inherit from table test."USER_DATA": "YEARS" numeric(6,0) NOT NULL,
    -- Inherit from table test."USER_DATA": "DAY" numeric(2,0) NOT NULL,
    -- Inherit from table test."USER_DATA": "HOUR" numeric(2,0) NOT NULL,
    CONSTRAINT "USER_DATA_201210_pkey" PRIMARY KEY ("MAC", "ID", "YEARS", "DAY", "HOUR"),
    CONSTRAINT "USER_DATA_YEARS_check" CHECK ("YEARS" = 201311::numeric)
    )
    INHERITS (test."USER_DATA")

    通过CHECK ("YEARS" = 2013xx::numeric)来把往表[USER_DATA]上存储的数据自动的存储到分表1[USER_DATA_201310]或者分表2[USER_DATA_201311]上

    这样做不仅可以降低单表的数据量,而且可以方便的拆分,组合,更方便的是,取数据的时候只用去访问[USER_DATA]表,就可以查询所有分表里的数据

    组合

    ALTER TABLE test."USER_DATA_201312" INHERIT test."USER_DATA"

    拆分

    ALTER TABLE test."USER_DATA_201310" NO INHERIT test."USER_DATA"

  • 相关阅读:
    maven-eclipse 中index.html页面乱码
    java-Unsupported major.minor version 52.0错误解决
    eclipse引入httpServlet源码
    eclipse恢复默认布局
    eclipse导入Java源码
    bootstrap fileinput api翻译笔记
    js判断display隐藏显示
    php根据路径获取文件名
    js事件处理-整理
    Jms(消息中间件)两种消息传输方式QUEUE和TOPIC比较
  • 原文地址:https://www.cnblogs.com/boneking/p/3347490.html
Copyright © 2011-2022 走看看