对新表进行分区

使用 CREATE TABLE 对新表进行分区,由 PARTITION BY 子句指定:

CREATE TABLE table-name... PARTITION BY partition‑expression [ GROUP BY group‑expression ] [ REORGANIZE ];

以下语句创建 store_orders 表并将数据加载到其中。CREATE TABLE 语句包含一个简单的分区子句,指定按年份对数据进行分区:

=> CREATE TABLE public.store_orders
(
    order_no int,
    order_date timestamp NOT NULL,
    shipper varchar(20),
    ship_date date
)
UNSEGMENTED ALL NODES
PARTITION BY YEAR(order_date);
CREATE TABLE
=> COPY store_orders FROM '/home/dbadmin/export_store_orders_data.txt';
41834

当 COPY 将新表数据加载到 ROS 存储中时,Tuple Mover 会将每年的订单划分为单独的分区,且将这些分区合并到 ROS 容器中,以执行表的分区子句。

在这种情况下,Tuple Mover 为加载的数据创建四个分区键(2017、2016、2015 和 2014),并将数据相应划分到单独的 ROS 容器中:

=> SELECT dump_table_partition_keys('store_orders');
... Partition keys on node v_vmart_node0001
  Projection 'store_orders_super'
   Storage [ROS container]
     No of partition keys: 1
     Partition keys: 2017
   Storage [ROS container]
     No of partition keys: 1
     Partition keys: 2016
   Storage [ROS container]
     No of partition keys: 1
     Partition keys: 2015
   Storage [ROS container]
     No of partition keys: 1
     Partition keys: 2014

 Partition keys on node v_vmart_node0002
  Projection 'store_orders_super'
   Storage [ROS container]
     No of partition keys: 1
     Partition keys: 2017
...

(1 row)

当新数据加载到 store_orders 中时,Tuple Mover 会将其合并到适当的分区中,以此根据需要创建新的分区键。