mysql Senior Review

MySQL is the official definition of the index: the index (Index) to help MySQL efficiently get the data structure of the data.
Nature can get index: The index is a data structure that can be simply understood as a "fast lookup data structure sorted."

Addition to the data itself, the database also maintains a data structure to meet specific search algorithm, these data point to data structures in some way,
so that you can achieve the advanced search algorithm on the basis of these data structure, this data structure is indexed.

The general index itself is also great, can not all be stored in memory, so the index is often stored in the form of an index file of the disk
we usually say the index, if not specified, refer to the B-tree (Multiple search tree, not necessarily a binary index structure of the organization)

B-tree (Balance Tree and more balanced search tree)

Index is divided into three kinds:

1. Single index values: i.e., contain only a single column index, a table can have multiple separate index
2. unique index: index column value must be unique, but allow nulls
3. Composite Index: i.e. comprising a plurality of index row

 

 

Explain
the use of simulation and optimization EXPLAIN keyword can perform SQL queries, so they know MySQL is
how to deal with your SQL statement. Analysis of performance bottlenecks in your query or table structure.

Action:
to know the sequence table read, the data reading operation of the operation type, which indexes can be used, which indexes are actually used, the references between tables, how many rows of each table is a query optimizer

Explain + SQL statement can be analyzed

Each field:

id
the same 1.id, execution order from top to bottom
different 2.id, if a sub-query, the number is incremented id, id value the greater the higher the priority, the first to be executed
3.id if the same can be considered a group sequentially performed from the downward;, id value is larger in all groups, the higher the priority, the first execution

SELECT_TYPE ( the type of query is mainly used to distinguish between normal query, the union query, sub query complex queries)

1.SIMPLE: simple select query, the query does not contain subqueries or UNION
2.PRIMARY: If the query contains any complex sub-section, the outermost query were marked
3.SUBQUERY: included in the SELECT list or WHERE subqueries
4.DERIVED: subquery contained in the FROM list is marked dERIVED (derivative), MySQL will recursively these sub-queries, the results in a temporary table.
5.UNION: If after the second SELECT appears UNION, were labeled UNION; UNION if included in the FROM clause of a query, the outer layer is labeled SELECT: DERIVED
6.UNION the RESULT: table obtained from UNION SELECT results

table
displaying data on this line is what tables of

type
show what type of query uses,
from best to worst order is:
System> const> eq_ref> ref> the Range> index> ALL

possible_keys
display index in this table may be applied, one or more.
Queries related to the field if there is an index, the index will be listed, but not necessarily the actual query

key
index actually used. If NULL, then do not use the index

key_len
maximum possible length values of the index fields displayed key_len, not actual length, i.e. calculated on the basis key_len table definition is not retrieved by the inner

ref
display column index which is used, if possible, is a constant. Which columns or constants are used to find the value of the index column

rows
the number of rows in accordance with selection index information and the statistical table, the rough estimate of the desired record is found to be read

Extra (unsuitable for display in the other columns but additional information is very important)
1.Using filesort internal sorting
2.Using temporary create a temporary table
3.USING index USING index using where if there is at the same time, shows that the index is used to perform key index Find value;
if no using where at the same time, shows that the index is used to read data rather than performing a lookup operation.


 

Index failure (should be avoided)

1. All values match my favorites
2. Best left-prefix rule
3 does not do anything on a column index (calculated, function (automatic or manual) type conversion), the index will lead to failure of the steering full table scan
4. Storage engine not use the index range condition in the right column
5. make use of a covering index (an index query access only (column index and query uniform)), reduction * SELECT
6. the use MySQL not equal (! = or <>) of sometimes when not using the index will lead to a full table scan
7. Note null / not null index may affect
8. like to begin with wildcard characters ( '% abc ...') mysql index will become invalid operating table scan sake of
9 string failure without single quotation marks index
10. less or, the index will fail when it is used to connect

Guess you like

Origin www.cnblogs.com/liuyi13535496566/p/12214568.html