PURGE_PARTITION

清除已删除行的表分区。类似 PURGEPURGE_PROJECTION,该函数会从物理存储中移除已删除的数据,这样可以重复使用磁盘空间。 PURGE_PARTITION 仅移除 AHM 时期及更早时期的数据。

这是元函数。您必须在顶级 SELECT 语句中调用元函数。

行为类型

易变

语法

PURGE_PARTITION ( '[[database.]schema.]table', partition‑key )

参数

[database.]schema

数据库和架构。默认架构为 public。如果指定一个数据库,它必须是当前数据库。

要清除的已分区的表。
partition‑key
要清除的分区的键。

特权

  • 表所有者

  • 对架构的 USAGE 权限

示例

以下示例列出了表中每个分区已删除行的数量,然后调用 PURGE_PARTITION() 从数据清除已删除的行。

=> SELECT partition_key,table_schema,projection_name,sum(deleted_row_count)
   AS deleted_row_count FROM partitions
   GROUP BY partition_key,table_schema,projection_name
   ORDER BY partition_key;

 partition_key | table_schema | projection_name | deleted_row_count
---------------+--------------+-----------------+-------------------
 0             | public       | t_super         |                 2
 1             | public       | t_super         |                 2
 2             | public       | t_super         |                 2
 3             | public       | t_super         |                 2
 4             | public       | t_super         |                 2
 5             | public       | t_super         |                 2
 6             | public       | t_super         |                 2
 7             | public       | t_super         |                 2
 8             | public       | t_super         |                 2
 9             | public       | t_super         |                 1
(10 rows)
=> SELECT PURGE_PARTITION('t',5); -- Purge partition with key 5.
                            purge_partition
------------------------------------------------------------------------
 Task: merge partitions
(Table: public.t) (Projection: public.t_super)
(1 row)

=> SELECT partition_key,table_schema,projection_name,sum(deleted_row_count)
   AS deleted_row_count FROM partitions
   GROUP BY partition_key,table_schema,projection_name
   ORDER BY partition_key;


 partition_key | table_schema | projection_name | deleted_row_count
---------------+--------------+-----------------+-------------------
 0             | public       | t_super         |                 2
 1             | public       | t_super         |                 2
 2             | public       | t_super         |                 2
 3             | public       | t_super         |                 2
 4             | public       | t_super         |                 2
 5             | public       | t_super         |                 0
 6             | public       | t_super         |                 2
 7             | public       | t_super         |                 2
 8             | public       | t_super         |                 2
 9             | public       | t_super         |                 1
(10 rows)

另请参阅