PostgreSQL Partition Table creation

Source: Internet
Author: User
Tags create index postgresql

Pgsql partition Table:--Main Table CREATE TABLE test (ID integer, name varchar); CREATE index idx_test_id on test using btree (ID);--Table Create Table Test_b (like test including constraints including defaults including indexes) inherits (test); CREATE Table Test_c (li KE test including constraints including defaults including indexes) inherits (test); ALTER TABLE TEST_B add constraint con_t Est_c Check (ID >=1001 and ID <=); ALTER TABLE Test_c add constraint con_test_b check (ID >=2001 and ID <= 3 CREATE TABLE Test_d (check (ID >=3001 and ID <= 4000)) inherits (test);--Plug data insert INTO Test_b select Generate_se Ries (1001,2000), ' BBB '; insert into Test_c select Generate_series (2001,3000), ' CCC '; insert into test_d select Generate_ Series (3001,4000), ' ddd ';--analysis table, join plan analyze Test_a;analyze test_b;analyze test_c;analyze test_d;--test query plan Constraint_ Exclusionset constraint_exclusion = off/partition;show Constraint_exclusion;explain select * FROM test where id = 1;--Test i Nsertinsert into test values (one, ' AAAAA '); select * FROM test where name = ' AAAAA ' select * from Test_a;insert into test values (1, ' a '), (1111, ' V '), (2222, ' vv '); Sele CT * from test_c;--creating trigger functions Create function Tb_partition_insert () returns trigger as$ $beginif (ID >=1 and ID <= 1000)   Then inserts into test_a values (new.*), ElseIf (ID >=1001 and ID <=) then inserts into Test_b values (new.*);   ElseIf (ID >=2001 and ID <=) then insert into test_c values (new.*); Else raise exception ' Date out of range. Fix the Tbl_partition_insert_trigger () function! '; End If; return null; end$ $language plpgsql;--trigger create trigger insert_test_parition before insert on test for each row execute procedure Tb_partition_insert ();--Test insertinsert into test values (1, ' a '), (1111, ' V '), (2222, ' vv '), select Pg_size_pretty (pg_ Relation_size (' test ')); INSERT into Test select Generate_series (1,1000), ' AA '; select COUNT (1) from Test_a;select pg_size _pretty (pg_relation_size (' Test ')); Select Pg_table_size (' Test ')

Reference:

Main: http://www.cnblogs.com/mchina/archive/2013/04/09/2973427.html
Supplement: http://my.oschina.net/Kenyon/blog/59455,

Http://www.postgres.cn/docs/9.4/ddl-partitioning.html#DDL-PARTITIONING-CONSTRAINT-EXCLUSION
Example reference: http://francs3.blog.163.com/blog/static/4057672720112422436937/
Combination: http://www.cnblogs.com/stephen-liu74/archive/2012/04/27/2291814.html
To view table size operations: http://www.cnblogs.com/liuyuanyuanGOGO/p/3224554.html
Partition tables are inherited, and when you clear data operations on a table, be aware that both the parent table and the Word table are cleared http://francs3.blog.163.com/blog/static/40576727201011203725668/















PostgreSQL partition Table established

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.