MySQL has two ways to find tune execution of particular query.
First is MySQL Hints, such as SQL_BIG_RESULT, STRAIGHT_JOIN,
FORCE INDEX etc. You place these directly into the query to
change how query is executed for example
SELECT STRAIGHT_JOIN * FROM A FORCE INDEX(A) JOIN B
The other part is session variable. If you know query is going to require large sort you can do SET sort_buffer_size=50000000 before executing query and SET sort_buffer_size=DEFAULT after executing the query.
I noticed in production hints are used much more frequently than setting session variables for given query execution even though it also can be quite helpful and I believe the problem is it is more complicated. It also requires more round trips to the server but it is not that critical as it is complicated queries which normally need special values.
Especially if you're patching third party application it is much …
[Read more]