今天是学习openGauss的第8天,分区表的学习。
分区表是把逻辑上的一张表根据某种方案分成几张物理块进行存储,这张逻辑上的表称之为分区表,物理块称之为分区。
分区表是一张逻辑表,不存储数据,数据实际是存储在分区上的。
常见的分区方案有范围分区(Range Partitioning)、间隔分区(Interval Partitioning)、哈希分区(Hash Partitioning)、列表分区(List Partitioning)、数值分区(Value Partition)等。
目前行存表支持范围分区、间隔分区、哈希分区、列表分区,列存表仅支持范围分区。
常见的二级分区表组合方案有Range-Range分区、Range-List分区、Range-Hash分区、List-Range分区、List-List分区、List-Hash分区、Hash-Range分区、Hash-List分区、Hash-Hash分区等。
目前二级分区仅支持行存表。
测试样例:
omm@modb:~$ gsql -r
gsql ((openGauss 2.0.0 build 78689da9) compiled at 2021-03-31 21:03:52 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
omm=# create table store (c1 int, c2 integer)
partition by range (c1)
omm-# (
omm(# omm-# partition p1 values less than (50),
omm(# partition p2 values less than (100),
omm(# omm(# partition p3 values less than (150),
partition p4 values less than (200),
omm(# partition p5 values less than (250)
omm(# );
CREATE TABLE
omm=# insert into store values(1,111),(55,555),(120,333),(160,444),(230,555);
INSERT 0 5
omm=# select * from store partition(p1);
c1 | c2
----+-----
1 | 111
(1 row)
omm=# alter table store rename partition p2 to p2_2;
ALTER TABLE
omm=# alter table store drop partition p5;
ALTER TABLE
omm=# alter table store add partition p6 values less than 600;
ERROR: syntax error at or near "600"
LINE 1: alter table store add partition p6 values less than 600;
^
omm=# alter table store add partition p6 values less than (600);
ALTER TABLE
omm=#
omm=# select * from store partition(p1);
c1 | c2
----+-----
1 | 111
(1 row)
omm=# select * from store partition(p2);
ERROR: partition "p2" of relation "store" does not exist
omm=# select * from store partition(p2_2);
c1 | c2
----+-----
55 | 555
(1 row)
omm=# select * from store partition(p3);
omm=# c1 | c2
-----+-----
120 | 333
(1 row)
omm=# select * from store partition(p4);
c1 | c2
-----+-----
160 | 444
(1 row)
omm=# select * from store partition(p6);
omm=# c1 | c2
----+----
(0 rows)
omm=# select * from pg_partition;
relname | parttype | parentid | rangenum | intervalnum | partstrategy | relfilenode | reltablespace | relpages | reltuples | relal
lvisible | reltoastrelid | reltoastidxid | indextblid | indisusable | reldeltarelid | reldeltaidx | relcudescrelid | relcudescidx |
relfrozenxid | intspnum | partkey | intervaltablespace | interval | boundaries | transit | reloptions
| relfrozenxid64
---------+----------+----------+----------+-------------+--------------+-------------+---------------+----------+-----------+------
---------+---------------+---------------+------------+-------------+---------------+-------------+----------------+--------------+
--------------+----------+---------+--------------------+----------+------------+---------+----------------------------------------
-----------+----------------
store | r | 16397 | 0 | 0 | r | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | t | 0 | 0 | 0 | 0 |
0 | | 1 | | | | | {orientation=row,compression=no,wait_cl
ean_gpi=n} | 0
0 | 0 | 0 | 0 | t | 0 | 0 | 0 | 0 |
9327 | | | | | {50} | | {orientation=row,compression=no}
| 9327
p3 | p | 16397 | 0 | 0 | r | 16403 | 0 | 0 | 0 |
p1 | p | 16397 | 0 | 0 | r | 16401 | 0 | 0 | 0 |
9327 | | | | | {150} | | {orientation=row,compression=no}
| 9327
p4 | p | 16397 | 0 | 0 | r | 16404 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | t | 0 | 0 | 0 | 0 |
9327 | | | | | {200} | | {orientation=row,compression=no}
--More-- 0 | 0 | 0 | 0 | t | 0 | 0 | 0 | 0 |
| 9327
p2_2 | p | 16397 | 0 | 0 | r | 16402 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | t | 0 | 0 | 0 | 0 |
9327 | | | | | {100} | | {orientation=row,compression=no}
| 9327
p6 | p | 16397 | 0 | 0 | r | 16406 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | t | 0 | 0 | 0 | 0 |
9331 | | | | | {600} | | {orientation=row,compression=no}
| 9331
(6 rows)
omm=#
omm=#
omm=# drop table store;
DROP TABLE
omm=#




