清除存储策略

CLEAR_OBJECT_STORAGE_POLICY 元函数从数据库、架构、表或表分区中清除存储策略。例如,以下语句清除表的存储策略:

=> SELECT CLEAR_OBJECT_STORAGE_POLICY ('store.store_sales_fact');
  CLEAR_OBJECT_STORAGE_POLICY
--------------------------------
 Object storage policy cleared.
(1 row)

Tuple Mover 会将现有存储容器移至父存储策略的位置,若无父策略,则移至默认存储位置。默认情况下,此移动发生在所有待定的合并任务返回之后。

您可以通过将函数的 enforce-storage-move 实参设置为 true 来强制立即移动数据。例如,以下语句清除表的存储策略并立即执行移动操作:

=> SELECT CLEAR_OBJECT_STORAGE_POLICY ('store.store_orders_fact', 'true');
                         CLEAR_OBJECT_STORAGE_POLICY
-----------------------------------------------------------------------------
 Object storage policy cleared.
Task: moving storages
(Table: store.store_orders_fact) (Projection: store.store_orders_fact_b0)
(Table: store.store_orders_fact) (Projection: store.store_orders_fact_b1)

(1 row)

对相关元素的影响

清除一个级别(如表)的存储策略不一定会影响其他级别(如该表的分区)的存储策略。

例如,lineorder 表有一个存储策略用来将表数据存储在带有 F2 标签的位置。为该表中的各个分区单独分配各自的存储位置,通过查询 STORAGE_POLICIES 系统表进行验证:

=> SELECT * from v_monitor.storage_policies;
 schema_name | object_name |  policy_details  | location_label
-------------+-------------+------------------+----------------
             | public      | Schema           | F4
 public      | lineorder   | Partition [0, 0] | F1
 public      | lineorder   | Partition [1, 1] | F2
 public      | lineorder   | Partition [2, 2] | F4
 public      | lineorder   | Partition [3, 3] | M1
 public      | lineorder   | Partition [4, 4] | M3
(6 rows)

lineorder 表中清除当前的存储策略对其各个分区的存储策略没有影响。例如,对于以下 CLEAR_OBJECT_STORAGE_POLICY 语句:

=> SELECT CLEAR_OBJECT_STORAGE_POLICY ('lineorder');
      CLEAR_OBJECT_STORAGE_POLICY
-------------------------------------
 Default storage policy cleared.
(1 row)

表中的各个分区保留其存储策略:


=> SELECT * from v_monitor.storage_policies;
 schema_name | object_name |  policy_details  | location_label
-------------+-------------+------------------+----------------
             | public      | Schema           | F4
 public      | lineorder   | Partition [0, 0] | F1
 public      | lineorder   | Partition [1, 1] | F2
 public      | lineorder   | Partition [2, 2] | F4
 public      | lineorder   | Partition [3, 3] | M1
 public      | lineorder   | Partition [4, 4] | M3
(6 rows)

如果您从表中的一个分区键范围中清除存储策略,则父对象和其他分区范围的存储策略不受影响。例如,以下语句从分区键 0 到 3 中清除存储策略:

=> SELECT CLEAR_OBJECT_STORAGE_POLICY ('lineorder','0','3');
      clear_object_storage_policy
-------------------------------------
 Default storage policy cleared.
(1 row)
=> SELECT * from storage_policies;
 schema_name | object_name |  policy_details  | location_label
-------------+-------------+------------------+----------------
             | public      | Schema           | F4
 public      | lineorder   | Table            | F2
 public      | lineorder   | Partition [4, 4] | M3
(2 rows)