【发布时间】:2018-12-23 13:19:04
【问题描述】:
由于我按月对目标表进行了间隔分区,并且只保留 27 个月的数据(因此需要每月删除最旧的分区)。 在我使用下面的 SQL 删除它之后,我运行了 SP,SP 很慢。
alter table target_table drop partition target_eldest_partition;
于是我取消了SP并分析了表格
ANALYZE TABLE target_table COMPUTE STATISTICS;
但是遇到了错误
Error starting at line : 12 in command -
ANALYZE TABLE per_limra COMPUTE STATISTICS
Error report -
ORA-01502: index 'target_index' or partition of such index is in unusable state
01502. 00000 - "index '%s.%s' or partition of such index is in unusable state"
*Cause: An attempt has been made to access an index or index partition
that has been marked unusable by a direct load or by a DDL
operation
*Action: DROP the specified index, or REBUILD the specified index, or
REBUILD the unusable index partition
所以我google了一下,有一些问题,请帮忙。
问题1:ANALYZE TABLE不会重建索引吧?
问题2:索引错误原因,*Cause: ........ by a direct load是什么意思?
问题3:背景,通过下面的SQL检查,实际上我的目标表的索引现在无法使用。
SELECT owner, index_name, tablespace_name
FROM dba_indexes
WHERE status = 'UNUSABLE';
我在使用以下 SQL 创建分区表时创建了索引
CREATE INDEX "schema_name"."target_index1" ON "schema_name"."target_table" ("col1")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS NOLOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "target_tablespace" ;
我知道在使用分区表时,索引有两种类型,全局索引和本地索引,我的索引定义属于什么?看来我没有使用分区索引,因为我在这里没有找到我的目标表分区名称。
问题4:如何解决索引不可用的问题,删除分区后需要成熟的解决方案。
问题5:我的目标表有5000万条数据,每个月大概有190万条,所以我认为使用DBMS_STATS.GATHER_TABLE_STATS或ANALYZE TABLE target_table COMPUTE STATISTICS更新统计是必要的,但是太慢了,有什么其他的解决方案。
请帮忙提供建议。谢谢。
【问题讨论】:
-
索引是全局的(一个段代表整个索引),不是分区的(按分区键分割)。如果您想要分区索引,请在您的
create index命令中使用local关键字。或者,将其保留为全局,但在管理表分区时包含update global indexes子句,以便它不会失效。您的 Oracle 版本在这里很重要,因为更高版本具有更多功能。 -
明白了,非常感谢@Wernfried
标签: oracle indexing partitioning