Mysql- Optimizer working principle
The MySQL optimizer can decide not to use an index, if it can perceive that loading the index into memory would be more expensive than any possible savings that the index can provide.
For instance, if 100% of the rows match the condition surface_time >= '2006-04-07' and surface_time <= '2006-05-02', then what's the use of the index?
For instance, if 100% of the rows match the condition surface_time >= '2006-04-07' and surface_time <= '2006-05-02', then what's the use of the index?
Even if it's more like 97% of the rows, that could still mean that it's more efficient to simply read the extra 3% of rows, than to load the index and do indexed lookups. The query optimizer is designed to make this analysis.
what is the total no. of records in the table.Index will be used , if the query selects between 5 to 10% of the totalrecords in the table.If its more than that then, optimizer will doing ALL scan, as it assumesdoing ALL scan is faster than an INDEX SCAN.
So based on this we can conclude that as long as the number of rows processed in a query is less than the threshold of the mysql optimizer it uses all the indexes in an efficient way.
No comments:
Post a Comment