【发布时间】:2018-04-08 00:41:38
【问题描述】:
这是另外两个表的关联表,外键是'num_compte'和'id_statut'
我有一个查询(我在这里创建了一个视图)来选择所有帐户的最新状态,如下所示:
CREATE OR REPLACE FORCE VIEW "HR"."ETATACTUELCOMPTES"
("id_statut", "num_compte") AS
select r2."id_statut",r2."num_compte" from
(
select "num_compte",max("createdAt") createdAt
from "AvoirStatuts"
group by "num_compte"
) r1, "AvoirStatuts" r2
where
r1."num_compte"=r2."num_compte"
and r1.createdAt=r2."createdAt";
我想用索引加速这个查询,所以我创建了一个这样的索引
create index creation_index on "AvoirStatuts"
("num_compte","createdAt" desc );
但是查询没有使用那个索引,我不知道为什么!
【问题讨论】:
-
“AvoirStatuts”表中有多少行?如果只有少数,优化器可能会决定读取整个表并扫描它比使用索引更快。计划中的 FULL TABLE SCAN 操作的成本仅为 5,因此很难改进。
标签: oracle indexing query-optimization