使用Order by子句时如何强制执行索引?

时间:2017-08-09 12:34:33

标签: oracle performance indexing sql-order-by

where子句和order by子句不同,Oracle没有识别索引

INNER JOIN ORG_ACCOUNTING_PERIODS p
 ON p.ORG_ROADMARK = c.ORG_ROADMARK
 AND p.ACCOUNTING_PERIOD = c.SERVICE_PERIOD
        where ( c.ORG_ROADMARK =:roadMark )
        and c.ORG_ROADMARK = c.move_road 
        ORDER BY EVENT_DATETIME;

1 个答案:

答案 0 :(得分:0)

当按顺序使用索引和顺序时,应该是where子句的子集,因为索引直接应用于where子句。

所以添加--->

INNER JOIN ORG_ACCOUNTING_PERIODS p ON p.ORG_ROADMARK = c.ORG_ROADMARK AND p.ACCOUNTING_PERIOD = c.SERVICE_PERIOD
        where ( c.ORG_ROADMARK =:roadMark )
        and c.ORG_ROADMARK = c.move_road         
        and c.EVENT_DATETIME between :eventFrom AND :eventTo
        ORDER BY EVENT_DATETIME ;

create index --> `CREATE INDEX "CARHIRE_EVENTS_IX" ON "CARHIRE_EVENTS" ("EVENT_DATETIME", "MOVE_ROAD", "ORG_ROADMARK") ;`