首页 > 解决方案 > 删除具有全局索引的分区表?

问题描述

PROCEDURE purge_partitions
   (
      p_owner            IN VARCHAR2
     ,p_name             IN VARCHAR2
     ,p_retention_period IN NUMBER
   ) IS
   BEGIN
      FOR partition_rec IN (SELECT partition_name
                                  ,high_value
                              FROM dba_tab_partitions
                             WHERE table_owner = p_owner
                               AND table_name = p_name)

      LOOP
         IF SYSDATE >= add_months(to_date(substr(partition_rec.high_value
                                                ,12
                                                ,19)
                                         ,'YYYY-MM-DD HH24:MI:SS')
                                 ,p_retention_period)
         THEN
            execute_immediate('ALTER TABLE ' || p_owner || '.' ||
                              p_name || ' DROP PARTITION ' ||
                              partition_rec.partition_name)
         END IF;
      END LOOP;
   END purge_partitions;

Purge_Partitions 过程根据单独的配置表中提到的特定保留优先级处理删除分区。我现在正在尝试增强此功能,该功能将负责重建这些分区表的全局索引。不知道如何去做,任何帮助都非常感谢。

标签: oracleindexingplsqlpartitioning

解决方案


考虑update_index_clauses,它使索引保持有效。

在此处查看全局索引的文档和注意事项

在您的情况下,它将是:

 alter table ttttt drop partition pppppp update global indexes;

或者让索引在 中无效DROP PARTITION并用 重建它们alter index xxx rebuild。您可以从此查询获取要重建的索引列表

select OWNER, INDEX_NAME  
from all_indexes 
where owner = 'ooo' and table_name = 'tttttt' and status = 'UNUSABLE';

推荐阅读