Rechercher dans le manuel MySQL
B.4.5 Optimizer-Related Issues
MySQL uses a cost-based optimizer to determine the best way to resolve a query. In many cases, MySQL can calculate the best possible query plan, but sometimes MySQL does not have enough information about the data at hand and has to make “educated” guesses about the data.
For the cases when MySQL does not do the "right" thing, tools that you have available to help MySQL are:
Use the
EXPLAIN
statement to get information about how MySQL processes a query. To use it, just add the keywordEXPLAIN
to the front of yourSELECT
statement:EXPLAIN
is discussed in more detail in Section 13.8.2, “EXPLAIN Syntax”.Use
ANALYZE TABLE
to update the key distributions for the scanned table. See Section 13.7.3.1, “ANALYZE TABLE Syntax”.tbl_name
Use
FORCE INDEX
for the scanned table to tell MySQL that table scans are very expensive compared to using the given index:USE INDEX
andIGNORE INDEX
may also be useful. See Section 8.9.4, “Index Hints”.Global and table-level
STRAIGHT_JOIN
. See Section 13.2.10, “SELECT Syntax”.You can tune global or thread-specific system variables. For example, start mysqld with the
--max-seeks-for-key=1000
option or useSET max_seeks_for_key=1000
to tell the optimizer to assume that no key scan causes more than 1,000 key seeks. See Section 5.1.8, “Server System Variables”.
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-optimizer-issues.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.