EnjoY | Database Research And Development: MySQL: SELECT with Index Hint option to Optimize the Query

Thursday, November 26, 2020

MySQL: SELECT with Index Hint option to Optimize the Query

This article is half-done without your Comment! *** Please share your thoughts via Comment ***


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.

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:

Using USE INDEX:

Using IGNORE INDEX:

Using FORCE INDEX:

No comments:

Post a Comment

It’s all about friendly conversation here at small review :) I’d love to be hear your thoughts!

Be sure to check back again because I do make every effort to reply to your comments here.

Featured Post

SQL Server : SELECT all columns to be good or bad in database system

This article is half-done without your Comment! *** Please share your thoughts via Comment *** In this post, I am going to write about one o...

Popular Posts