mysql performance optimization strategy

mysql

MySQL optimization
is important to follow the association table when querying large table small table-driven principle;
when using query where conditions allowed function, otherwise the index will fail;
the use of single-table queries, try not to use the same field OR, because it may lead to failure of the index such as: SELECT * FROM table WHERE name = ' phone' OR name = 'computer', you can use UNION alternative;
the lIKE statement is not allowed at the beginning%, otherwise the index will fail;
composite index must follow the principle left to right, or else the index will fail; example: SELECT * FROM table wHERE name = ' Joe Smith' AND age = 18, then the combination index must be a name, age form;
index not too much, according to the actual situation determined as not more than 10;
each tables must have a primary key, the purpose of accelerating query efficiency;
points table, the table can achieve the purpose of sub-bit mantissa in the business field or ten or one hundred (and so on) do according to the table name;
sub-libraries, can be according to the purpose of a business field bit mantissa or ten or one hundred (and so on) do achieve sub-library library name;
table partitions, similar to a hard disk partition Data for a period of time can be placed partition, speed up queries, can be used with sub-table + partition table used in combination;

MySQL EXPLAIN statement

EXPLAIN shows how MySQL uses indexes to deal with the SELECT statement and connection table. You can help choose a better index and write more optimized queries.

Use, plus you can before EXPLAIN SELECT statement, such as:

The FROM tb_item the WHERE the SELECT * EXPLAIN the IN CID (the FROM tb_item_ the SELECT ID)
ID: the identifier of the SELECT. This is a SELECT query sequence number

select_type: SELECT type, may be any of the following

SIMPLE: Simple SELECT (not using UNION or subqueries)
PRIMARY: The outermost SELECT
UNION: UNION in the second or later SELECT statement
DEPENDENT UNION: UNION in the second or later SELECT statement, depending on the outside query
UNION rESULT: UNION results
sUBQUERY: a first sub-query the SELECT
DEPENDENT sUBQUERY: first subquery SELECT, depending on the outside of the query
dERIVED: SELECT export table (FROM clause subquery)
table: output line table referenced

partitions: Partition Table

type: connection type. Various types of coupling are given below, in accordance with the type ordered from best to worst type

system: only one line of table (= system table). This is a special case of the const join type.
const: Table at most one matching row, which will be read at the start of the query. Because only one row, column values in this row may be considered to optimize the remaining portion is constant. const table quickly, because they are only read once!
eq_ref: For each combination of rows from the front of the table, reads a line from the table. This is probably the best connection type, except const type.
ref: For each combination of rows from the preceding table, all rows matching the index values read from this table.
ref_or_null: The connection type as ref, but added the line MySQL can search specifically contain NULL values.
index_merge: the coupling type indication index combined optimization method.
unique_subquery: The type of the alternative form of ref IN subqueries of the following: value IN (SELECT primary_key FROM single_table WHERE some_expr) unique_subquery is an index lookup function, can completely replace the subquery, more efficient.
index_subquery: This type is similar to the coupling unique_subquery. IN subqueries can be replaced, but only for the sub-queries in the form of a non-unique index: value IN (the WHERE SINGLE_TABLE the some_expr the SELECT key_column the FROM)
Range: retrieve only to the line given range, using an index to select the rows.
index: the coupling with ALL the same type, except that only the index tree is scanned. This is usually faster than ALL, because the index file is usually smaller than the data file.
ALL: For each combination of rows from the previous table, a full table scan.
possible_keys: indicates which indexes MySQL could use to find the rows in the table

key: display key (index) MySQL actually decided to use. If you do not select an index, the key is NULL.

key_len: Display MySQL decided to use key lengths. If the key is NULL, the length is NULL.

ref: shows which columns or constants are selected together with a key from a table using the row.

rows: show the number of rows MySQL believes it must examine the query execution. Of data between a plurality of lines can be estimated by multiplying the number of rows to be processed.

filtered: it shows the percentage of the estimated number of rows filtered through conditions.

Extra: This column contains detailed information about how MySQL resolves the query

Distinct: MySQL found after a matching line for the current row combination stop searching for more rows.
Not exists: MySQL LEFT JOIN able to query optimization, after a match was found LEFT JOIN standard line, no more rows in the check table of the foregoing combinations of rows.
range checked for each record (index map : #): MySQL found no good index may be used, but if the value found from the front of the column of the table is known, the index portion may be used.
Using filesort: MySQL requires additional one pass to find out how to retrieve the rows in sorted order.
Using index: from the use of only information in the index tree without having to search further reads the actual line to retrieve column information in the table.
Using temporary: in order to solve the query, MySQL needs to create a temporary table to hold the result.
Using where: WHERE clause restricts a row which matches the next table or sent to a client.
Using sort_union (...), Using union (...), Using intersect (...): illustrate how these functions merge type join index_merge index scan.
Using index for group-by: Using index similar to the way a table is accessed, Using index for group-by expressed MySQL found an index that can be used to query all the columns GROUP BY or DISTINCT query, rather than the actual hard disk access additional search table.

Original link large column  https://www.dazhuanlan.com/2019/07/15/mysqlperformanceoptimizationstrategy/

Guess you like

Origin www.cnblogs.com/chinatrump/p/11416187.html