您的位置:首页 > 数据库 > Oracle

Oracle vs PostgreSQL DBA(13)- 拆分(split)分区

2019-08-03 17:05 1311 查看

直至12版本,PostgreSQL仍没有提供直接拆分分区的功能,暂时只能通过detach&attach实现,相对于Oracle的split支持,PG显得比较的simple&naive.

PG 12

 
  1.  
  2. [pg12@localhost ~]$ psql -d testdb
  3. Timing is on.
  4. Expanded display is used automatically.
  5. psql (12beta1)
  6. Type "help" for help.
  7. [local]:5432 pg12@testdb=#drop table t_p1;
  8. ) to (200);
  9. create table t_p1_maxvalue partition of t_p1 for values from (200) to (maxvalue);
  10. truncate table t_p1;
  11. insert into t_p1(id,c1) values(1,1);
  12. insert into t_p1(id,c1) values(2,100);
  13. insert into t_p1(id,c1) values(3,125);
  14. insert into t_p1(id,c1) values(4,200);
  15. insert into t_p1(id,c1) values(5,250);
  16. insert into t_p1(id,c1) values(6,300);
  17. insert into t_p1(id,c1) values(7,350);
  18. insert into t_p1(id,c1) values(8,4500);
  19. alter table t_p1 detach partition t_p1_maxvalue;
  20. create table t_p1_3 partition of t_ERROR: table "t_p1" does not exist
  21. Time: 8.497 ms
  22. [local]:5432 pg12@testdb=#create table t_p1 (id int, c1 int) partition by range (c1);
  23. p1 for values from (200) to (300);
  24. insert into t_p1_3 select * from t_p1_maxvalue where c1 >= 200 and c1 < 300;
  25. delete from t_p1_maxvalue where c1 >= 200 and c1 < 300;
  26. alter table t_p1 attach partition t_p1_maxvalue for values from (300) to (maxvalue);CREATE TABLE
  27. Time: 235.099 ms
  28. [local]:5432 pg12@testdb=#create table t_p1_default partition of t_p1 default;
  29. CREATE TABLE
  30. Time: 11.941 ms
  31. [local]:5432 pg12@testdb=#create table t_p1_1 partition of t_p1 for values from (1) to (100);
  32. CREATE TABLE
  33. Time: 15.247 ms
  34. [local]:5432 pg12@testdb=#create table t_p1_2 partition of t_p1 for values from (100) to (200);
  35. CREATE TABLE
  36. Time: 1.705 ms
  37. [local]:5432 pg12@testdb=#create table t_p1_maxvalue partition of t_p1 for values from (200) to (maxvalue);
  38. CREATE TABLE
  39. Time: 1.842 ms
  40. [local]:5432 pg12@testdb=#
  41. [local]:5432 pg12@testdb=#truncate table t_p1;
  42. TRUNCATE TABLE
  43. Time: 3.413 ms
  44. [local]:5432 pg12@testdb=#insert into t_p1(id,c1) values(1,1);
  45. INSERT 0 1
  46. Time: 1.152 ms
  47. [local]:5432 pg12@testdb=#insert into t_p1(id,c1) values(2,100);
  48. INSERT 0 1
  49. Time: 0.871 ms
  50. [local]:5432 pg12@testdb=#insert into t_p1(id,c1) values(3,125);
  51. INSERT 0 1
  52. Time: 0.487 ms
  53. [local]:5432 pg12@testdb=#insert into t_p1(id,c1) values(4,200);
  54. INSERT 0 1
  55. Time: 0.949 ms
  56. [local]:5432 pg12@testdb=#insert into t_p1(id,c1) values(5,250);
  57. INSERT 0 1
  58. Time: 0.494 ms
  59. [local]:5432 pg12@testdb=#insert into t_p1(id,c1) values(6,300);
  60. INSERT 0 1
  61. Time: 0.463 ms
  62. [local]:5432 pg12@testdb=#insert into t_p1(id,c1) values(7,350);
  63. INSERT 0 1
  64. Time: 0.481 ms
  65. [local]:5432 pg12@testdb=#insert into t_p1(id,c1) values(8,4500);
  66. INSERT 0 1
  67. Time: 0.464 ms
  68. [local]:5432 pg12@testdb=#
  69. [local]:5432 pg12@testdb=#alter table t_p1 detach partition t_p1_maxvalue;
  70. ALTER TABLE
  71. Time: 0.864 ms
  72. [local]:5432 pg12@testdb=#create table t_p1_3 partition of t_p1 for values from (200) to (300);
  73. CREATE TABLE
  74. Time: 1.752 ms
  75. [local]:5432 pg12@testdb=#insert into t_p1_3 select * from t_p1_maxvalue where c1 >= 200 and c1 < 300;
  76. INSERT 0 2
  77. Time: 7.578 ms
  78. [local]:5432 pg12@testdb=#delete from t_p1_maxvalue where c1 >= 200 and c1 < 300;
  79. DELETE 2
  80. Time: 21.992 ms
  81. [local]:5432 pg12@testdb=#alter table t_p1 attach partition t_p1_maxvalue for values from (300) to (maxvalue);
  82. ALTER TABLE
  83. Time: 7.356 ms
  84. [local]:5432 pg12@testdb=#
  85.  

Oracle

郑州人流医院:http://yyk.39.net/zz3/zonghe/1d426.html/
  1.  
  2. TEST-orcl@DESKTOP-V430TU3>create table t_p1(id int,c1 int)
  3. 2 partition by range(c1)
  4. 3 (partition p1 values less than(100),
  5. 4 partition p2 values less than(200),
  6. 5 partition pmax values less than(maxvalue)
  7. 6 );
  8. Table created.
  9. TEST-orcl@DESKTOP-V430TU3>
  10. TEST-orcl@DESKTOP-V430TU3>truncate table t_p1;
  11. Table truncated.
  12. TEST-orcl@DESKTOP-V430TU3>insert into t_p1(id,c1) values(1,1);
  13. 1 row created.
  14. TEST-orcl@DESKTOP-V430TU3>insert into t_p1(id,c1) values(2,100);
  15. 1 row created.
  16. TEST-orcl@DESKTOP-V430TU3>insert into t_p1(id,c1) values(3,125);
  17. 1 row created.
  18. TEST-orcl@DESKTOP-V430TU3>insert into t_p1(id,c1) values(4,200);
  19. 1 row created.
  20. TEST-orcl@DESKTOP-V430TU3>insert into t_p1(id,c1) values(5,250);
  21. 1 row created.
  22. TEST-orcl@DESKTOP-V430TU3>insert into t_p1(id,c1) values(6,300);
  23. 1 row created.
  24. TEST-orcl@DESKTOP-V430TU3>insert into t_p1(id,c1) values(7,350);
  25. 1 row created.
  26. TEST-orcl@DESKTOP-V430TU3>insert into t_p1(id,c1) values(8,4500);
  27. 1 row created.
  28. TEST-orcl@DESKTOP-V430TU3>alter table t_p1 split partition pmax at(1000) into (partition p3,partition pmx);
  29. Table altered.
  30. TEST-orcl@DESKTOP-V430TU3>
  31.  

可以参照EDB的做法,加入此兼容性.

参考资料 
13.3 Partitioning Commands Compatible with Oracle Databases

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: