在做数据库开发时,总以为用索引可以提高检索效率。今天终于遇到一个用了索引但速度更慢的例子。在用订单头表和订单行表关联选数据时,使用索引查询和插入共用了2个小时,这只是筛选其中一个月的数据。其中和订单头表关联时,用的item和organization_id,而这个索引用的是个范围索引,查询很慢,要四十分钟。一个偶然的条件organization_id=157的让这个索引失效了,订单行表做了全表扫描,这下前面加的那个parallel的hint开始生效,查询插入用了十多分钟,性能已经到了可以接受的范围了。到底是什么原因导致的全表扫描更快,这个问题还要继续寻找。
几个比较有用的hint:
/*+ full(table_name) */ ---强制全表扫描
/*+ index(table_name, index_n1)*/ ---使用索引index_n1
/*+ no_index(table_name, index_n1)*/ ---不使用索引index_n1
/*+ parallel (table_name 10)*/ ---用10并发来跑
几个比较有用的hint:
/*+ full(table_name) */ ---强制全表扫描
/*+ index(table_name, index_n1)*/ ---使用索引index_n1
/*+ no_index(table_name, index_n1)*/ ---不使用索引index_n1
/*+ parallel (table_name 10)*/ ---用10并发来跑