Home >Backend Development >PHP Tutorial >MySQL Manual Version 5.0.20-MySQL Optimization (2) (1)_PHP Tutorial

MySQL Manual Version 5.0.20-MySQL Optimization (2) (1)_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:03:29842browse

7.2.1 EXPLAIN syntax (get SELECT related information)


EXPLAIN tbl_name

or:


EXPLAIN The SELECT select_options

EXPLAIN statement can be used as a synonym for DESCRIBE, and can also be used to obtain information about a SELECT statement to be executed by MySQL.


EXPLAIN tbl_name syntax is the same as DESCRIBE tbl_name or SHOW COLUMNS FROM tbl_name.


When the keyword EXPLAIN is used before a SELECT statement, MYSQL will explain how to run the SELECT statement. It shows how the tables are connected, the order of the connections, and other information.


This chapter mainly describes the second usage of EXPLAIN.


With the help of EXPLAIN, you will know when to add an index to the table to use the index to find records and make SELECT run faster.


If there are some problems caused by improper use of indexes, you can run ANALYZE TABLE to update the statistics of the table, such as the cardinality of the keys, which can help you make optimization decisions Better choice. See "14.5.2.1 ANALYZE TABLE Syntax" for details.


You can also see whether the optimizer joins the data tables in the best order. In order for the optimizer to join in the order of table names in the SELECT statement, you can use SELECT STRAIGHT_JOIN at the beginning of the query instead of just SELECT.


EXPLAIN returns a row of records, which includes information about each table used in the SELECT statement. The tables are listed in the results in the order they are read in the query MySQL is about to execute. MySQL uses a method of scanning multiple connections (single-sweep, multi-join) to solve connections. This means that MySQL reads a record from the first table, then looks up the corresponding record in the second table, then looks it up in the third table, and so on. When all tables have been scanned, it outputs the selected fields and backtracks through all tables until it is not found, because there may be multiple matching records in some tables. The next record will be read from this table, and then from the next A table begins to continue processing.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630973.htmlTechArticle7.2.1 EXPLAIN syntax (get SELECT related information) EXPLAIN tbl_name or: EXPLAIN SELECT select_options The EXPLAIN statement can be used as Used as a synonym for DESCRIBE, you can also use...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn