


In the latter case, the thread will spend a lot of time in Statistics state, and adding this hint will reduce the search space for the optimizer. This acts like USE INDEX (key_list) but with the addition that a table scan is assumed to be very expensive. The STRAIGHTJOIN hint is useful when MySQL doesn’t choose a good join order, or when the optimizer takes a long time to decide on a join order. These hints are useful if the SQL optimizer is using the wrong index from the list of possible indexes.įrom MySQL version 4.0.9 on, one can also use FORCE INDEX. The alternative negative hint IGNORE INDEX (key_list) can be used to tell MySQL to not use some particular index. By specifying USE INDEX (index_list) as the index hint, one can tell MySQL to use only one of the possible indexes to find rows like this: One can give hints about which index MySQL should use when fetching rows from a table. In MySQL, these hints are referred to as index hints. SELECT group_id, empl_id, dept_id FROM tab1 WHERE group_id = 1

Below is an example which force optimizer to use index tab1_idx3 on table tab1: The database structure is very crucial in performance optimization. Informix has four types of query optimizers: Access Plan Directive, Join Order Drective, Join Plan Directive, and Optimization Goal Directive.Īccess Plan Directive will tell optimizer which index to use, which index to avoid, perform full table scan, or avoid full table scan. In Informix, these hints are referred to as Query Directives. Optimizing database performance and MySQL query execution are crucial for maximizing system performance. There are times when even the best optimized schema and smartest query optimizer will need hints on how it should execute a query. I do prefer to give it for that statement alone.
Mysql optimizer hint how to#
