MySQL: SELECT with Index Hint option to Optimize the Query

The Table Indexes are always the main focus to improve the performance of any SQL Query.
In MySQL, We can provide INDEX Hint to Query Optimizer for choosing our analyzed Index.

In most of the cases, Query Planner and Query Optimizer are accurate to choose perfect Index.
But sometimes, still It is required to give Index Hint for reducing the overall Query Planning Time.

If we know that this Index is good for this query, we should Provide the Hint to Query Optimizer.

Here, You can also access one related article.

MySQL: Script to find Index Usage Statistics of a Database

MySQL supports command like USE INDEX, IGNORE INDEX, FORCE INDEX, which we can use for Index Hint.

The USE INDEX hint tells MySQL to use only one of the named indexes to find rows in the table.
The IGNORE INDEX tells MySQL to not use some particular index or indexes.
The FORCE INDEX hint acts like USE INDEX , with the addition that a table scan is assumed to be very expensive.

Prepared small demonstration on this.

Create a sample table:

Insert few sample Records:

Create few sample Indexes:




Anvesh Patel

Leave a Reply

Be the First to Comment!

Notify of