Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force oracle to use index

Tags:

oracle

Is there any way to force oracle to use index except Hints?

like image 596
P Sharma Avatar asked Dec 07 '22 05:12

P Sharma


2 Answers

No. And if the optimizer doesn't use the index, it usually has a good reason for it. Index usage, if the index is poor, can actually slow your queries down.

like image 108
Donnie Avatar answered Dec 09 '22 19:12

Donnie


Oracle doesn't use an index when it thinks the index is

  • disabled
  • invalid (for example, after a huge data load and the statistics about the index haven't been updated)
  • won't help (for example, when there are only two different values in 5 million rows)

So the first thing to check is that the index is enabled, then run the correct GATHER command on your index/table/schema. When that doesn't help, Oracle thinks that loading your index will actually take more time than loading the actual row values. In this case, add more columns to the index to make it appear more "diverse".

like image 44
Aaron Digulla Avatar answered Dec 09 '22 17:12

Aaron Digulla