Sql 索引存在,但在为分区表创建新分区或删除分区后不起作用
我有一个oracle分区表,有一个带有以下sql的Sql 索引存在,但在为分区表创建新分区或删除分区后不起作用,sql,oracle,Sql,Oracle,我有一个oracle分区表,有一个带有以下sql的project\u code索引。我们每天做以下两件事: 创建一个新分区并将数据插入该分区 删除旧分区 几天后,当我看到的执行计划时,我发现查询速度变慢了 select * from MY_TABLE where project_code = '123' 索引仍然存在,但对于上述sql,索引不起作用 如果我删除并重新创建索引,索引将工作,查询将更快 我不确定创建/删除分区是否会导致此问题,以及如何解决此问题 -- Create table cr
project\u code
索引。我们每天做以下两件事:
select * from MY_TABLE where project_code = '123'
索引仍然存在,但对于上述sql,索引不起作用
如果我删除并重新创建索引,索引将工作,查询将更快
我不确定创建/删除分区是否会导致此问题,以及如何解决此问题
-- Create table
create table MY_TABLE
(
country_code VARCHAR2(50),
project_code VARCHAR2(100),
item_code VARCHAR2(100),
BATCHES NUMBER
)
partition by list (BATCHES)
(
partition P1499736558 values (1499736558)
tablespace MY_DATA
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 8M
next 1M
minextents 1
maxextents unlimited
),
partition P1499760276 values (1499760276)
tablespace MY_DATA
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 8M
next 1M
minextents 1
maxextents unlimited
),
partition P1499846713 values (1499846713)
tablespace MY_DATA
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 8M
next 1M
minextents 1
maxextents unlimited
),
partition P1499933071 values (1499933071)
tablespace MY_DATA
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 8M
next 1M
minextents 1
maxextents unlimited
)
);
-- Create/Recreate indexes
create index IDX_PROJECT_CODE on MY_TABLE (PROJECT_CODE)
tablespace MY_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 160K
next 1M
minextents 1
maxextents unlimited
);
索引很可能会过时,这就是为什么CBO(基于成本的优化器)不使用它的原因。此外,新分区中的数据是全新的,您需要收集有关它的统计信息,以便CBO也可以考虑它。阅读更多关于索引陈旧性和表列陈旧性的内容,以及它们与CBO决策的关系。在重新创建索引之后,您已经说过了,没关系。如果我要管理这个过程,在完成整个过程后,我将始终执行以下操作:收集表(列)统计信息、收集索引统计信息、收集分区统计信息。检查此链接: