InnoDB
InnoDB
InnoDB
InnoDB
InnoDB
InnoDB
/*! */
SELECT
SELECT
CREATE
TABLE...AS SELECT
INSERT
INTO...SELECT
DELETE
SELECT ... WHERE
WHERE
EXPLAIN
SELECT
ANALYZE TABLE
InnoDB
InnoDB
EXPLAIN
EXPLAIN
InnoDB
MyISAM
WHERE
SELECT
DELETE
UPDATE
((a AND b) AND c OR (((a AND b) AND (c AND d)))) -> (a AND b AND c) OR (a AND b AND c AND d)
(a<b AND b=c) AND a=5 -> b>5 AND b=c AND a=5
(B>=5 AND B=5) OR (B=6 AND 5=5) OR (B=7 AND 5=6) -> B=5 OR B=6
COUNT(*)
MyISAM
NOT NULL
SELECT
WHERE
WHERE
UNIQUE
SELECT * FROM t WHEREprimary_key
=1; SELECT * FROM t1,t2 WHERE t1.primary_key
=1 AND t2.primary_key
=t1.id;
ORDER BY
ORDER BY
ORDER BY
SQL_SMALL_RESULT
HAVING
SELECT COUNT(*) FROMtbl_name
; SELECT MIN(key_part1
),MAX(key_part1
) FROMtbl_name
; SELECT MAX(key_part2
) FROMtbl_name
WHEREkey_part1
=constant
; SELECT ... FROMtbl_name
ORDER BYkey_part1
,key_part2
,... LIMIT 10; SELECT ... FROMtbl_name
ORDER BYkey_part1
DESC,key_part2
DESC, ... LIMIT 10;
SELECTkey_part1
,key_part2
FROMtbl_name
WHEREkey_part1
=val
; SELECT COUNT(*) FROMtbl_name
WHEREkey_part1
=val1
ANDkey_part2
=val2
; SELECTkey_part2
FROMtbl_name
GROUP BYkey_part1
;
SELECT ... FROMtbl_name
ORDER BYkey_part1
,key_part2
,... ; SELECT ... FROMtbl_name
ORDER BYkey_part1
DESC,key_part2
DESC, ... ;
range
WHERE
WHERE
SELECT * FROM T1的地方 key_col
> 1 key_col
< 10;SELECT * FROM t1 WHEREkey_col
= 1 ORkey_col
在(15,18,20);选择*从T1的地方 key_col
像“AB %”或 key_col
“酒吧”和“foo”;
WHERE
key1
SELECT * FROM t1 WHERE (key1 < 'abc' AND (key1 LIKE 'abcde%' OR key1 LIKE '%b')) OR (key1 < 'bar' AND nonkey = 4) OR (key1 < 'uux' AND key1 > 'z');
key1
WHERE
(key1 < 'abc' AND (key1 LIKE 'abcde%' OR key1 LIKE '%b')) OR(key1 < 'bar' AND nonkey = 4) OR(key1 < 'uux' AND key1 > 'z')
nonkey = 4
TRUE
(key1 < 'abc' AND (key1 LIKE 'abcde%' OR TRUE)) OR (key1 < 'bar' AND TRUE) OR (key1 < 'uux' AND key1 > 'z')
(key1 LIKE 'abcde%' OR TRUE)
(key1 < 'uux' AND key1 >
'z')
(key1 < 'abc' AND TRUE) OR (key1 < 'bar' AND TRUE) OR (FALSE)
TRUE
(key1 < 'abc') OR (key1 < 'bar')
(key1 < 'bar')
WHERE
AND
OR
range
UNION
SELECT
SELECT
key1(
key_part1
,
key_part2
,
key_part3
)
key_part1
key_part2
key_part3
ABC是空1空1 XYZ Foo是空2 1 1 1 1 XYZ的ABC ABC 1 2 2 1是AAA
key_part1
= 1
(1,-inf,-inf) <= (key_part1
, key_part2
, key_part3
) < (1,+inf,+inf)
key_part3
=
'abc'
HASH
key_part1
cmp
const1
和 key_part2
cmp
const2
和…和 key_partN
cmp
constN
;
const1
const2
cmp
=
<=>
IS NULL
N
N
key_part1
= 1 ANDkey_part2
IS NULL ANDkey_part3
= 'foo'
BTREE
AND
=
<=>
IS NULL
>
<
>=
<=
!=
<>
BETWEEN
LIKE
'
pattern
'pattern
<>
!=
=
<=>
IS NULL
>
<
>=
<=
!=
<>
BETWEEN
LIKE
=
>=
key_part1
= 'foo' ANDkey_part2
>= 10 ANDkey_part3
> 10
('foo',10,-inf) < (key_part1
,key_part2
,key_part3
) < ('foo',+inf,+inf)
('foo',
11, 0)
OR
AND
( key_part1
= 1 ANDkey_part2
< 2) OR (key_part1
> 5)
(1,-inf) < (key_part1
,key_part2
) < (1,2) (5,-inf) < (key_part1
,key_part2
)
key_len
EXPLAIN
key_len
key_part1
key_part2
key_len
key_part1
>= 1 ANDkey_part2
< 2
key_part1
>= 1 ANDkey_part2
IS NOT NULL
col_name
col_name
在( val1
,…, valN
) col_name
=val1
或或 col_name
=valN
col_name
col_name
col_name
col_name
IN (10, 20,
30)
eq_range_index_dive_limit
N
eq_range_index_dive_limit
N
N
eq_range_index_dive_limit
ANALYZE TABLE
eq_range_index_dive_limit
FORCE INDEX
FULLTEXT
DISTINCT
ORDER BY
EXPLAIN FOR
CONNECTION
rows
NULL
rows_examined_per_scan
skip_index_dive_due_to_force
FOR CONNECTION
EXPLAIN
INFORMATION_SCHEMA.OPTIMIZER_TRACE
skipped_due_to_force_index
CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL, PRIMARY KEY(f1, f2)); INSERT INTO t1 VALUES (1,1), (1,2), (1,3), (1,4), (1,5), (2,1), (2,2), (2,3), (2,4), (2,5); INSERT INTO t1 SELECT f1, f2 + 5 FROM t1; INSERT INTO t1 SELECT f1, f2 + 10 FROM t1; INSERT INTO t1 SELECT f1, f2 + 20 FROM t1; INSERT INTO t1 SELECT f1, f2 + 40 FROM t1; ANALYZE TABLE t1; EXPLAIN SELECT f1, f2 FROM t1 WHERE f2 > 40;
f2 > 40
f1
f1
f2 > 40
f1 = 1
f1 = 1 AND f2 > 40
f1 = 2
f1 = 2 AND f2 > 40
k
m
n
GROUP BY
k
IN()
AND
(
cond1
(key_part1
)
OR
cond2
(key_part1
))
AND
(cond1
(key_part2
)
OR ...) AND ...
EXPLAIN
Using index for skip scan
possible_keys
"skip scan"
“跳过扫描“{”:“跳跃式”_扫描”,“指标”: index_used_for_skip_scan
,“key_parts_used_for_access”:[ key_parts_used_for_access
],”前缀范围”:[ prefix_ranges
“范围”:[ ], range
] }
skip_scan
optimizer_switch
on
off
optimizer_switch
SELECT ... FROM t1 WHERE ( col_1, col_2 ) IN (( 'a', 'b' ), ( 'c', 'd' ));
SELECT ... FROM t1 WHERE ( col_1 = 'a' AND col_2 = 'b' ) OR ( col_1 = 'c' AND col_2 = 'd' );
range_optimizer_max_mem_size
N
range_optimizer_max_mem_size
警告3170内存容量 N
“range_optimizer_max_mem_size字节的突破。范围不该查询做了优化。
range_optimizer_max_mem_size
OR
SELECT COUNT(*) FROM tWHERE a=1 OR a=2 OR a=3 OR .. . a=N
;
AND
SELECT COUNT(*) FROM tWHERE a=1 AND b=1 AND c=1 ...N
;
IN()
select count(*)从那里有一个在(1,2,…, M
和B)和(1,2,…, N
);
IN()
OR
IN()
OR
OR
M
N
range
SELECT * FROMtbl_name
WHEREkey1
= 10 ORkey2
= 20; SELECT * FROMtbl_name
WHERE (key1
= 10 ORkey2
= 20) ANDnon_key
= 30; SELECT * FROM t1, t2 WHERE (t1.key1
IN (1,2) OR t1.key2
LIKE 'value
%') AND t2.key1
= t1.some_col
; SELECT * FROM t1, t2 WHERE t1.key1
= 1 AND (t2.key1
= t1.some_col
OR t2.key2
= t1.some_col2
);
EXPLAIN
index_merge
key
Extra
EXPLAIN
Using intersect(...)
Using union(...)
Using sort_union(...)
WHERE
AND
N
N
key_part1
=const1
和 key_part2
=const2
…和 key_partN
=constN
InnoDB
SELECT * FROMinnodb_table
WHEREprimary_key
< 10 ANDkey_col1
= 20; SELECT * FROMtbl_name
WHEREkey1_part1
= 1 ANDkey1_part2
= 2 ANDkey2
= 2;
EXPLAIN
Extra
SELECT COUNT(*) FROM t1 WHERE key1 = 1 AND key2 = 1;
InnoDB
WHERE
OR
N
N
key_part1
=const1
和 key_part2
=const2
…和 key_partN
=constN
InnoDB
SELECT * FROM t1 WHEREkey1
= 1 ORkey2
= 2 ORkey3
= 3; SELECT * FROMinnodb_table
WHERE (key1
= 1 ANDkey2
= 2) OR (key3
= 'foo' ANDkey4
= 'bar') ANDkey5
= 5;
WHERE
OR
SELECT * FROMtbl_name
WHEREkey_col1
< 10 ORkey_col2
< 20; SELECT * FROMtbl_name
WHERE (key_col1
> 10 ORkey_col2
= 20) ANDnonkey_col
= 30;
index_merge
index_merge_union
optimizer_switch
on
off
optimizer_switch
NDB
NDB
NDBCLUSTER
CREATE TABLE t1 ( a INT, b INT, KEY(a) ) ENGINE=NDB;
SELECT a, b FROM t1 WHERE b = 10;
EXPLAIN
MySQL的> EXPLAIN SELECT a,b FROM t1 WHERE b = 10\G
*************************** 1。行***************************编号:1 select_type:简单表:T1型:allpossible_keys:空键:空key_len:零号:空10行:额外的:使用与推条件
SELECT a,b FROM t1 WHERE a = 10; SELECT a,b FROM t1 WHERE b + 1 = 10;
a
b + 1 =
10
b = 9
WHERE
>
<
mysql> EXPLAIN SELECT a, b FROM t1 WHERE a < 2\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t1
type: range
possible_keys: a
key: a
key_len: 5
ref: NULL
rows: 2
Extra: Using where with pushed condition
column
[NOT] LIKE
pattern
pattern
column
IS [NOT]
NULL
column
IN
(value_list
)
value_list
column
BETWEEN
constant1
AND
constant2
constant1
constant2
optimizer_switch
[mysqld] optimizer_switch=engine_condition_pushdown=off
SET optimizer_switch='engine_condition_pushdown=off';
NDB
EXPLAIN
WHERE
WHERE
range
ref
eq_ref
ref_or_null
InnoDB
InnoDB
InnoDB
WHERE
WHERE
WHERE
EXPLAIN
Extra
INDEX (zipcode, lastname, firstname)
SELECT * FROM people WHERE zipcode='95054' AND lastname LIKE '%etrunia%' AND address LIKE '%Main Street%';
zipcode='95054'
zipcode='95054'
lastname LIKE '%etrunia%'
lastname
optimizer_switch
SET optimizer_switch = 'index_condition_pushdown=off'; SET optimizer_switch = 'index_condition_pushdown=on';
t1
t3
表连接typet1 ranget2 reft3所有
for each row in t1 matching range { for each row in t2 matching reference key { for each row in t3 { if row satisfies join conditions, send to client } } }
ALL
index
range
join_buffer_size
for each row in t1 matching range { for each row in t2 matching reference key { store used columns from t1, t2 in join buffer if buffer is full { for each row in t3 { for each t1, t2 combination in join buffer { if row satisfies join conditions, send to client } } empty join buffer } } } if buffer is not empty { for each row in t3 { for each t1, t2 combination in join buffer { if row satisfies join conditions, send to client } } }
S
t2
C
(S
*C
)/join_buffer_size + 1
t3
join_buffer_size
join_buffer_size
table_factor
table_reference
table_reference
SELECT * FROM t1 LEFT JOIN (t2, t3, t4) ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)
SELECT * FROM t1 LEFT JOIN (t2 CROSS JOIN t3 CROSS JOIN t4) ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)
CROSS JOIN
INNER JOIN
CROSS JOIN
t1 LEFT JOIN (t2 LEFT JOIN t3 ON t2.b=t3.b OR t2.b IS NULL) ON t1.a=t2.a
(t1 LEFT JOIN t2 ON t1.a=t2.a) LEFT JOIN t3 ON t2.b=t3.b OR t2.b IS NULL
t1
t3
t1
(2)
t2
t3
(1,1,101,101)
(1,1,101,101)
mysql>SELECT *
FROM t1
LEFT JOIN
(t2 LEFT JOIN t3 ON t2.b=t3.b OR t2.b IS NULL)
ON t1.a=t2.a;
+------+------+------+------+ | a | a | b | b | +------+------+------+------+ | 1 | 1 | 101 | 101 | | 2 | NULL | NULL | NULL | +------+------+------+------+ mysql>SELECT *
FROM (t1 LEFT JOIN t2 ON t1.a=t2.a)
LEFT JOIN t3
ON t2.b=t3.b OR t2.b IS NULL;
+------+------+------+------+ | a | a | b | b | +------+------+------+------+ | 1 | 1 | 101 | 101 | | 2 | NULL | NULL | 101 | +------+------+------+------+
t1 LEFT JOIN (t2, t3) ON t1.a=t2.a
t1 LEFT JOIN t2 ON t1.a=t2.a, t3
mysql>SELECT *
FROM t1 LEFT JOIN (t2, t3) ON t1.a=t2.a;
+------+------+------+------+ | a | a | b | b | +------+------+------+------+ | 1 | 1 | 101 | 101 | | 2 | NULL | NULL | NULL | +------+------+------+------+ mysql>SELECT *
FROM t1 LEFT JOIN t2 ON t1.a=t2.a, t3;
+------+------+------+------+ | a | a | b | b | +------+------+------+------+ | 1 | 1 | 101 | 101 | | 2 | NULL | NULL | 101 | +------+------+------+------+
(t1,t2) LEFT JOIN t3 ON P(t2.b,t3.b)
t1,t2,t3
t2.b
t1, t2 LEFT JOIN t3 ON P(t2.b,t3.b)
join_table
SELECT * FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON t2.b=t3.b) ON t1.a=t2.a WHERE t1.a > 1SELECT * FROM t1 LEFT JOIN (t2, t3) ON t1.a=t2.a WHERE (t2.b=t3.b OR t2.b IS NULL) AND t1.a > 1
t2 LEFT JOIN t3 ON t2.b=t3.b t2, t3
(t2,
t3)
ON
T1,T2,T3
SELECT * FROM T1内P1(T1、T2和T2)内加入T3(T2,T3),P2 P(T1,T2,T3)
P1(T1,T2)
P(T1,T2,T3)
FOR each row t1 in T1 { FOR each row t2 in T2 such that P1(t1,t2) { FOR each row t3 in T3 such that P2(t2,t3) { IF P(t1,t2,t3) { t:=t1||t2||t3; OUTPUT t; } } } }
t1||t2||t3
t2
NULL
t1||t2||NULL
t2
t3
SELECT * FROM T1 LEFT JOIN (T2 LEFT JOIN T3 ON P2(T2,T3)) ON P1(T1,T2) WHERE P(T1,T2,T3)
FOR each row t1 in T1 { BOOL f1:=FALSE; FOR each row t2 in T2 such that P1(t1,t2) { BOOL f2:=FALSE; FOR each row t3 in T3 such that P2(t2,t3) { IF P(t1,t2,t3) { t:=t1||t2||t3; OUTPUT t; } f2=TRUE; f1=TRUE; } IF (!f2) { IF P(t1,t2,NULL) { t:=t1||t2||NULL; OUTPUT t; } f1=TRUE; } } IF (!f1) { IF P(t1,NULL,NULL) { t:=t1||NULL||NULL; OUTPUT t; } } }
NULL
(T2 LEFT JOIN T3 ON P2(T2,T3))
FOR each row t3 in T3 { FOR each row t2 in T2 such that P2(t2,t3) { FOR each row t1 in T1 such that P1(t1,t2) { IF P(t1,t2,t3) { t:=t1||t2||t3; OUTPUT t; } } } }
T1
T3
T3
SELECT * T1(T2、T3)左连接在P1(T1,T2)和P2(T1,T3),P(T1,T2,T3)
T2
FOR each row t1 in T1 { BOOL f1:=FALSE; FOR each row t2 in T2 such that P1(t1,t2) { FOR each row t3 in T3 such that P2(t1,t3) { IF P(t1,t2,t3) { t:=t1||t2||t3; OUTPUT t; } f1:=TRUE } } IF (!f1) { IF P(t1,NULL,NULL) { t:=t1||NULL||NULL; OUTPUT t; } } }
T3
FOR each row t1 in T1 { BOOL f1:=FALSE; FOR each row t3 in T3 such that P2(t1,t3) { FOR each row t2 in T2 such that P1(t1,t2) { IF P(t1,t2,t3) { t:=t1||t2||t3; OUTPUT t; } f1:=TRUE } } IF (!f1) { IF P(t1,NULL,NULL) { t:=t1||NULL||NULL; OUTPUT t; } } }
WHERE
P(T1,T2,T2) = C1(T1) AND C2(T2) AND C3(T3).
FOR each row t1 in T1 such that C1(t1) { FOR each row t2 in T2 such that P1(t1,t2) AND C2(t2) { FOR each row t3 in T3 such that P2(t2,t3) AND C3(t3) { IF P(t1,t2,t3) { t:=t1||t2||t3; OUTPUT t; } } } }
C1(T1)
C3(T3)
T1
WHERE
P(T1,T2,T3)=C1(T1) AND C(T2) AND C3(T3)
FOR each row t1 in T1 such that C1(t1) { BOOL f1:=FALSE; FOR each row t2 in T2 such that P1(t1,t2) AND (f1?C2(t2):TRUE) { BOOL f2:=FALSE; FOR each row t3 in T3 such that P2(t2,t3) AND (f1&&f2?C3(t3):TRUE) { IF (f1&&f2?TRUE:(C2(t2) AND C3(t3))) { t:=t1||t2||t3; OUTPUT t; } f2=TRUE; f1=TRUE; } IF (!f2) { IF (f1?TRUE:C2(t2) && P(t1,t2,NULL)) { t:=t1||t2||NULL; OUTPUT t; } f1=TRUE; } } IF (!f1 && P(t1,NULL,NULL)) { t:=t1||NULL||NULL; OUTPUT t; } }
P1(T1,T2)
NULL
WHERE
LEFT JOIN
A
LEFT
JOIN B
join_condition
B
A
A
A
B
LEFT JOIN
B
WHERE
A
B
B
LEFT JOIN
col_name
col_name
LEFT
JOIN
RIGHT JOIN
LEFT JOIN
NULL
WHERE
NULL
SELECT * FROM t1 LEFT JOIN t2 ON (column1) WHERE t2.column2=5;
SELECT * FROM t1, t2 WHERE t2.column2=5 AND t1.column1=t2.column1;
t2
STRAIGHT_JOIN
STRAIGHT_JOIN
FROM
(T1, ...) RIGHT JOIN (T2, ...) ON P(T1, ..., T2, ...)
(T2, ...) LEFT JOIN (T1, ...) ON P(T1, ..., T2, ...)
T1 INNER JOIN
T2 ON P(T1,T2)
P(T1,T2)
R(T2)
SELECT * T1 LEFT JOIN T2 ON P1(T1,T2) WHERE P(T1,T2) AND R(T2)
T1
WHERE
UNKNOWN
T1 LEFT JOIN T2 ON T1.A=T2.A
NULL
NULL
T2.B IS NOT NULLT2.B > 3T2.C <= T1.CT2.B < 2 OR T2.C > 1
NULL
T2.B IS NULLT1.B < 3 OR T2.B IS NOT NULLT1.B < 3 OR T2.B > 3
A IS NOT NULL
UNKNOWN
WHERE
SELECT * FROM T1 LEFT JOIN T2 ON T2.A=T1.A LEFT JOIN T3 ON T3.B=T1.B WHERE T3.C > 0
WHERE
SELECT * FROM T1 LEFT JOIN T2 ON T2.A=T1.A INNER JOIN T3 ON T3.B=T1.B WHERE T3.C > 0
T1,T2,T3
SELECT * FROM T1 LEFT JOIN T2 ON T2.A=T1.A LEFT JOIN T3 ON T3.B=T2.B WHERE T3.C > 0
SELECT * FROM T1 LEFT JOIN T2 ON T2.A=T1.A INNER JOIN T3 ON T3.B=T2.B WHERE T3.C > 0
SELECT * FROM (T1 LEFT JOIN T2 ON T2.A=T1.A), T3 WHERE T3.C > 0 AND T3.B=T2.B
T3.B=T2.B
SELECT * FROM (T1 INNER JOIN T2 ON T2.A=T1.A), T3 WHERE T3.C > 0 AND T3.B=T2.B
SELECT * FROM T1 LEFT JOIN (T2 LEFT JOIN T3 ON T3.B=T2.B) ON T2.A=T1.A WHERE T3.C > 0
SELECT * FROM T1 LEFT JOIN (T2 INNER JOIN T3 ON T3.B=T2.B) ON T2.A=T1.A WHERE T3.C > 0
SELECT * FROM T1 LEFT JOIN (T2,T3) ON (T2.A=T1.A AND T3.B=T2.B) WHERE T3.C > 0
WHERE
T2.A=T1.A AND
T3.C=T1.C
SELECT * FROM T1 LEFT JOIN (T2 LEFT JOIN T3 ON T3.B=T2.B) ON T2.A=T1.A AND T3.C=T1.C WHERE T3.D > 0 OR T1.D > 0
SELECT * FROM T1 LEFT JOIN (T2, T3) ON T2.A=T1.A AND T3.C=T1.C AND T3.B=T2.B WHERE T3.D > 0 OR T1.D > 0
InnoDB
InnoDB
NDB
Extra
EXPLAIN
InnoDB
optimizer_switch
mrr
mrr_cost_based
off
on
on
read_rnd_buffer_size
read_rnd_buffer_size
NULL
VARCHAR
B1
t2
B2
B2
r
r1
r2
B2
r2
r1
B1
t2
r
r
block_nested_loop
optimizer_switch
on
off
NULL
block_nested_loop
optimizer_switch
on
EXPLAIN
Using join buffer (Block Nested
Loop)
ALL
index
range
join_buffer_size
batched_key_access
optimizer_switch
mrr
mrr_cost_based
mysql> SET optimizer_switch='mrr=on,mrr_cost_based=off,batched_key_access=on';
InnoDB
MyISAM
NDB
EXPLAIN
Using join buffer (Batched Key
Access)
ref
eq_ref
optimizer_switch
WHERE
WHERE
EXPLAIN
filtered
rows
rows
is 20%, condition filtering reduces the estimated row count of 1000 to a prefix row count of 1000 × 20% = 1000 × .2 = 200.
SELECT * FROM employee JOIN department ON employee.dept_no = department.dept_no WHERE employee.first_name = 'John' AND employee.hire_date BETWEEN '2018-01-01' AND '2018-06-01';
employee
department
dept_no
employee
employee.first_name
employee.first_name = 'John'
employee.hire_date
employee.hire_date之间的2018-01-01 '和' 2018-06-01”
employee.first_name = 'John' AND employee.hire_date BETWEEN '2018-01-01' AND '2018-06-01'
EXPLAIN
---- ------------ -------- ------------------ --------- --------- ------ ---------- | ID |表|型| possible_keys |关键| REF |行|过滤| ---- ------------ -------- ------------------ --------- --------- ------ ---------- | 1 |员工| REF |名字,h_date,系|名字| const | 8 | 100 | | 1 |部| eq_ref |初级|小学| dept_no | 1 | 100 | ---- ------------ -------- ------------------ --------- --------- ------ ----------
employee
'John'
rows
= 8 × 100% = 8.
WHERE
BETWEEN
EXPLAIN
---- ------------ -------- ------------------ --------- --------- ------ ---------- | ID |表|型| possible_keys |关键| REF |行|过滤| ---- ------------ -------- ------------------ --------- --------- ------ ---------- | 1 |员工| REF |名字,h_date,系|名字| const | 8 | 16.31 | | 1 |部| eq_ref |初级|小学| dept_no | 1 | 100 | ---- ------------ -------- ------------------ --------- --------- ------ ----------
rows
= 8 × 16.31% = 1.3, which more closely reflects actual data set.
EXPLAIN
condition_fanout_filter
optimizer_switch
STRAIGHT_JOIN
STRAIGHT_JOIN
SET optimizer_switch = 'condition_fanout_filter=off';
SELECT /*+ SET_VAR(optimizer_switch = 'condition_fanout_filter=off') */ ...
col_name
IS
NULL
col_name
=
constant_value
IS
NULL
SELECT * FROMtbl_name
WHEREkey_col
IS NULL; SELECT * FROMtbl_name
WHEREkey_col
<=> NULL; SELECT * FROMtbl_name
WHEREkey_col
=const1
ORkey_col
=const2
ORkey_col
IS NULL;
WHERE
col_name
IS
NULL
NULL
col_name
=
expr
OR
col_name
IS NULLEXPLAIN
ref_or_null
IS
NULL
a
t2
SELECT * FROM t1 WHERE t1.a=expr
OR t1.a IS NULL;SELECT * FROM t1, t2 WHERE t1.a=t2.a OR t2.a IS NULL;SELECT * FROM t1, t2 WHERE (t1.a=t2.a OR t2.a IS NULL) AND t2.b=t1.b;SELECT * FROM t1, t2 WHERE t1.a=t2.a AND (t2.b=t1.b OR t2.b IS NULL);SELECT * FROM t1, t2 WHERE (t1.a=t2.a AND t2.a IS NULL AND ...) OR (t1.a=t2.a AND t2.a IS NULL AND ...);
ref_or_null
IS
NULL
(t1.a=t2.a AND t2.a IS NULL)
b
SELECT * FROM t1, t2 WHERE (t1.a=t2.a AND t2.a IS NULL) OR (t1.b=t2.b AND t2.b IS NULL);
ORDER BY
ORDER BY
ORDER BY
ORDER BY
ORDER
BY
WHERE
(
key_part1
,
key_part2
)
(
key_part1
,
key_part2
)
SELECT * FROM T1秩序 key_part1
, key_part2
;
SELECT *
key_part1
key_part2
t1
ORDER BY
选择 pk
, key_part1
, key_part2
从T1秩序 key_part1
, key_part2
;
key_part1
key_part2
key_part1
key_part2
SELECT * FROM t1 WHEREkey_part1
=constant
ORDER BYkey_part2
;
DESC
SELECT * FROM T1秩序 key_part1
desc, key_part2
desc;SELECT * FROM T1的地方 key_part1
=constant
顺序 key_part2
desc;
ORDER BY
DESC
DESC
ASC
SELECT * FROM t1 ORDER BYkey_part1
DESC,key_part2
ASC;
key_part1
key_part2
key_part1
key_part2
key_part1
key_part2
key_part1
SELECT * FROM t1 WHEREkey_part1
>constant
ORDER BYkey_part1
ASC; SELECT * FROM t1 WHEREkey_part1
<constant
ORDER BYkey_part1
DESC;
ORDER BY
key_part1
key_part1
SELECT * FROM T1的地方 key_part1
=constant1
和 key_part2
> constant2
顺序 key_part2
;
ORDER BY
ORDER BY
SELECT * FROM T1秩序 key1
, key2
;
ORDER BY
SELECT * FROM T1的地方 key2
=constant
顺序 key1_part1
, key1_part3
;
ORDER BY
SELECT * FROM T1的地方 key2
=constant
顺序 key1
;
ORDER BY
选择从T1秩序*(ABS key
);选择*从T1秩序— key
;
ORDER BY
EXPLAIN
const
ORDER BY
ORDER BY
CHAR(20)
HASH
t1.a
t1.a
ORDER BY
SELECT a FROM t1 ORDER BY a;
a
a
t1.a
选择ABS(一)作为一个从T1的命令;
ORDER BY
a
t1.a
ABS(a)
选择ABS(一)B从T1的命令;
GROUP BY
ORDER BY
ORDER
BY
filesort
filesort
sort_buffer_size
sort_buffer_size
sort_buffer_size
filesort
filesort
SELECT ... FROMsingle_table
... ORDER BYnon_index_column
[DESC] LIMIT [M
,]N
;
SELECT col1, ... FROM t1 ... ORDER BY name LIMIT 10; SELECT col1, ... FROM t1 ... ORDER BY RAND() LIMIT 15;
ORDER BY
max_length_for_sort_data
ORDER BY
sort_buffer_size
max_sort_length
max_sort_length
sort_buffer_size
Sort_merge_passes
read_rnd_buffer_size
tmpdir
;
EXPLAIN
ORDER
BY
filesort
"filesort_summary": { "rows": 100, "examined_rows": 100, "number_of_tmp_files": 0, "peak_memory_used": 25192, "sort_mode": "<sort_key, packed_additional_fields>" }
peak_memory_used
sort_buffer_size
sort_buffer_size
sort_buffer_size
sort_buffer_size
sort_mode
<sort_key, rowid>
<sort_key, additional_fields>
<sort_key,
packed_additional_fields>
EXPLAIN
filesort
GROUP BY
GROUP BY
BTREE
GROUP BY
GROUP BY
GROUP
BY
WHERE
WHERE
range
GROUP BY
DISTINCT
(c1,c2,c3)
GROUP BY c2, c3
c4
GROUP BY
MIN()
MAX()
c1 VARCHAR(20), INDEX (c1(10))
EXPLAIN
Extra
idx(c1,c2,c3)
SELECT c1, c2 FROM t1 GROUP BY c1, c2; SELECT DISTINCT c1, c2 FROM t1; SELECT c1, MIN(c2) FROM t1 GROUP BY c1; SELECT c1, c2 FROM t1 WHERE c1 <const
GROUP BY c1, c2; SELECT MAX(c3), MIN(c3), c1, c2 FROM t1 WHERE c2 >const
GROUP BY c1, c2; SELECT c2 FROM t1 WHERE c1 <const
GROUP BY c1, c2; SELECT c1, c2 FROM t1 WHERE c3 =const
GROUP BY c1, c2;
MIN()
MAX()
AVG(DISTINCT)
SUM(DISTINCT)
COUNT(DISTINCT)
AVG(DISTINCT)
SUM(DISTINCT)
COUNT(DISTINCT)
GROUP BY
idx(c1,c2,c3)
SELECT COUNT(DISTINCT c1), SUM(DISTINCT c1) FROM t1; SELECT COUNT(DISTINCT c1, c2), COUNT(DISTINCT c2, c1) FROM t1;
GROUP BY
WHERE
GROUP BY
GROUP BY
idx(c1,c2,c3)
GROUP BY
c2 = 'a'
SELECT c1, c2, c3 FROM t1 WHERE c2 = 'a' GROUP BY c1, c3;
GROUP BY
SELECT c1, c2, c3 FROM t1 WHERE c1 = 'a' GROUP BY c2, c3;
DISTINCT
DISTINCT
ORDER BY
DISTINCT
SELECT DISTINCT c1, c2, c3 FROM t1 WHERE c1 >const
; SELECT c1, c2, c3 FROM t1 WHERE c1 >const
GROUP BY c1, c2, c3;
GROUP BY
DISTINCT
LIMIT
row_count
row_count
t1
EXPLAIN
t1
SELECT DISTINCT t1.a FROM t1, t2 where t1.a=t2.a;
LIMIT
LIMIT
row_count
LIMIT
LIMIT
row_count
row_count
row_count
ORDER BY
LIMIT
row_count
row_count
GROUP BY
row_count
SQL_CALC_FOUND_ROWS
LIMIT 0
--column-type-info
LIMIT
row_count
ORDER BY
filesort
ORDER
BY
LIMIT
LIMIT
id
mysql> SELECT * FROM ratings ORDER BY category;
+----+----------+--------+
| id | category | rating |
+----+----------+--------+
| 1 | 1 | 4.5 |
| 5 | 1 | 3.2 |
| 3 | 2 | 3.7 |
| 4 | 2 | 3.5 |
| 6 | 2 | 3.5 |
| 2 | 3 | 5.0 |
| 7 | 3 | 2.7 |
+----+----------+--------+
LIMIT
mysql> SELECT * FROM ratings ORDER BY category LIMIT 5;
+----+----------+--------+
| id | category | rating |
+----+----------+--------+
| 1 | 1 | 4.5 |
| 5 | 1 | 3.2 |
| 4 | 2 | 3.5 |
| 3 | 2 | 3.7 |
| 6 | 2 | 3.5 |
+----+----------+--------+
ORDER
BY
LIMIT
id
id
MySQL的> SELECT * FROM ratings ORDER BY category, id;
---- ---------- -------- | ID |范畴|评级| ---- ---------- -------- | 1 | 1 | 4.5 | | 5 | 1 | 3.2 | | 3 | 2 | 3.7 | | 4 | 2 | 3.5 | | 6 | 2 | 3.5 | | 2 | 3 | 5 | | 7 | 3 | 2.7 | ---- ---------- -------- MySQL > SELECT * FROM ratings ORDER BY category, id LIMIT 5;
---- ---------- -------- | ID |范畴|评级| ---- ---------- -------- | 1 | 1 | 4.5 | | 5 | 1 | 3.2 | | 3 | 2 | 3.7 | | 4 | 2 | 3.5 | | 6 | 2 | 3.5 | ---- ---------- --------
RAND()
UUID()
WHERE
RAND()
t
创建表(ID int不空主键,col_a varchar(100));
SELECT * FROM t WHERE id = POW(1,2); SELECT * FROM t WHERE id = FLOOR(1 + RAND() * 49);
SELECT
UPDATE
UPDATE t SET col_a =some_expr
WHERE id = FLOOR(1 + RAND() * 49);
id
RAND()
InnoDB
RAND()
SET @keyval = FLOOR(1 + RAND() * 49);
UPDATE t SET col_a = some_expr
WHERE id = @keyval;
WHERE
UPDATE /*+ NO_MERGE(dt) */ t, (SELECT FLOOR(1 + RAND() * 49) AS r) AS dtSET col_a =some_expr
WHERE id = dt.r;
WHERE
SELECT * FROM t WHERE partial_key=5 AND some_column=RAND();
partial_key
RAND()
WHERE
OVER
OVER
COUNT(t1.b)
SELECT * FROM t1 WHERE t1.a = (SELECT COUNT(t1.b) FROM t2);
t1.b
WHERE
mysql> SELECT * FROM t1 HAVING t1.a = (SELECT COUNT(t1.b) FROM t2);
ERROR 1140 (42000): In aggregated query without GROUP BY, expression #1
of SELECT list contains nonaggregated column 'test.t1.a'; this is
incompatible with sql_mode=only_full_group_by
COUNT(t1.b)
windowing_use_high_precision
windowing_use_high_precision
DECIMAL
windowing_use_high_precision
windowing_use_high_precision
windowing_use_high_precision
MIN()
MAX()
STDDEV_POP()
STDDEV_SAMP()
VAR_POP()
VAR_SAMP()
windowing_use_high_precision
EXPLAIN
EXPLAIN
FORMAT=JSON
SELECT * FROM t1 WHERE (column1,column2) = (1,1); SELECT * FROM t1 WHERE column1 = 1 AND column2 = 1;
(c1, c2, c3)
create table T1(int,int,C1,C2,C3,C4 int,char(100),primary key(C1,C2,C3));
WHERE
key_len=4
mysql>EXPLAIN SELECT * FROM t1
WHERE c1=1 AND (c2,c3) > (1,1)\G
*************************** 1. row *************************** id: 1 select_type: SIMPLE table: t1 partitions: NULL type: ref possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: const rows: 3 filtered: 100.00 Extra: Using where
(c2,c3) > (1,1) c2 > 1 OR ((c2 = 1) AND (c3 > 1))
key_len=12
MySQL的> EXPLAIN SELECT * FROM t1
WHERE c1 = 1 AND (c2 > 1 OR ((c2 = 1) AND (c3 > 1)))\G
*************************** 1。行***************************编号:1 select_type:简单表:T1分区:null类型:rangepossible_keys:主键:主要key_len:12编号:零排:3:100:使用额外的过滤
AND
OR
IN()
EXPLAIN
ALL
ON
ANALYZE TABLE
tbl_name
FORCE INDEX
SELECT * FROM T1、T2力量指数( index_for_column
在T1) col_name
=t2.col_name
;
--max-seeks-for-key=1000
SET max_seeks_for_key=1000
IN
=ANY
EXISTS
NOT IN
<>ALL
EXISTS
class
SELECT class.class_num, class.class_name FROM class INNER JOIN roster WHERE class.class_num = roster.class_num;
class_num
SELECT
DISTINCT
SELECT class_num, class_name FROM class WHERE class_num IN (SELECT class_num FROM roster);
IN
class
DISTINCT
ORDER BY
optimizer_switch
semijoin
semijoin
loosescan
materialization
duplicateweedout
duplicateweedout
optimizer_prune_level=0
STRAIGHT_JOIN
CREATE VIEW v AS SELECT * FROM t1 WHERE a IN (SELECT b FROM t2); SELECT STRAIGHT_JOIN * FROM t3 JOIN v ON t3.x = v.a;
IN
EXPLAIN
EXPLAIN
SHOW WARNINGS
WHERE
Start temporary
Extra
EXPLAIN
End temporary
FirstMatch(
tbl_name
)
LooseScan(
m
..n
)m
n
select_type
table
<subquery
N
IN
where_condition
t1
SELECT * FROM t1where T1,T2在(选择B从T2的地方。 where_condition
);
EXISTS
SELECT * FROM t1where存在(选择B从T2,T2。 where_condition
AND t1.a=t2.b);
optimizer_switch
materialization
ON
HAVING
oe_i
ie_i
N
( oe_1
, oe_2
,…, oe_N
[不]在(选择) ie_1
, i_2
,…, ie_N
…)
oe
ie
oe
[不]在(选择 ie
…)
IN
UNKNOWN
FALSE
UNKNOWN
where_condition
t1
SELECT * FROM t1
WHERE t1.a IN (SELECT t2.b FROM t2 WHERE where_condition
);
IN
FALSE
t2.b
SELECT * FROM t1where(T1,T1,T2(B)没有选择,B从T2,T2。 where_condition
);
BLOB
EXPLAIN
DEPENDENT SUBQUERY
EXPLAIN
SHOW
WARNINGS
materialized-subquery
SELECT * FROM (SELECT * FROM t1) AS derived_t1;
SELECT * FROM t1;
SELECT * FROM t1 JOIN (SELECT t2.f1 FROM t2) AS derived_t2 ON t1.f2=derived_t2.f1 WHERE t1.f1 > 0;
SELECT t1.*, t2.f1 FROM t1 JOIN t2 ON t1.f2=t2.f1 WHERE t1.f1 > 0;
derived_t1
ORDER BY
DISTINCT
ORDER BY
FROM
ORDER
BY
MERGE
derived_merge
optimizer_switch
ER_UPDATE_TABLE_USED
derived_merge
ER_UPDATE_TABLE_USED
ALGORITHM=TEMPTABLE
derived_merge
EXPLAIN
SELECT
解释查询(SELECT * FROM T1)作为derived_t1;
SELECT
EXPLAIN
FROM
SELECT * FROM t1 JOIN (SELECT t2.f1 FROM t2) AS derived_t2 ON t1.f2=derived_t2.f1 WHERE t1.f1 > 0;
t1
ref
SELECT * FROM t1 JOIN (SELECT DISTINCT f1 FROM t2) AS derived_t2 ON t1.f1=derived_t2.f1;
f1
ref
ref
MERGE
cte1
WITH cte1 AS (SELECT a, b FROM table1), cte2 AS (SELECT c, d FROM table2) SELECT /*+ MERGE(cte1) NO_MERGE(cte2) */ cte1.b, cte2.d FROM cte1 JOIN cte2 WHERE cte1.a = cte2.c;
ALGORITHM
CREATE VIEW
WITH
SELECT
CREATE ALGORITHM={TEMPTABLE|MERGE} VIEW v1 AS WITH ... SELECT ...
ALGORITHM
SELECT
WITH
MyISAM
internal_tmp_disk_storage_engine=MYISAM
creating_tmp_table
materialized_from_subquery
materialized_from_subquery
EXPLAIN
IN
=ANY
NULL
outer_expr
IN (SELECTinner_expr
FROM ... WHEREsubquery_where
)
outer_expr
inner_expr
outer_expr
EXISTS (SELECT 1 FROM ... WHEREsubquery_where
ANDouter_expr
=inner_expr
)
N
N
oe_i
ie_i
( oe_1
,…, oe_N
在(选择) ie_1
,…, ie_N
从…哪里 subquery_where
)
EXISTS (SELECT 1 FROM ... WHEREsubquery_where
ANDoe_1
=ie_1
AND ... ANDoe_N
=ie_N
)
NULL
outer_expr
outer_expr
=inner_expr
outer_expr
outer_expr
=
inner_expr
inner_expr
EXISTS (SELECT 1 FROM ... WHEREsubquery_where
AND (outer_expr
=inner_expr
ORinner_expr
IS NULL))
IS
NULL
ref_or_null
MySQL的> EXPLAIN
SELECT
outer_expr
IN (SELECT t2.maybe_null_keyFROM t2, t3 WHERE ...)
FROM t1;
*************************** 1。行*************************** ID:1 select_type:主表:T1…*************************** 2。行***************************编号:2 select_type:相关子查询表:T2型:ref_or_nullpossible_keys:maybe_null_key关键:maybe_null_key key_len:5号:功能:2行:使用额外使用指数…
unique_subquery
index_subquery
NULL
OR ... IS NULL
outer_expr
NULL
NULL IN (SELECT
inner_expr
...)
SELECT
outer_expr
=inner_expr
outer_expr
outer_expr
outer_expr
SELECT
空(选择 inner_expr
从…哪里 subquery_where
)
SELECT
outer_expr
outer_expr
IN (SELECTinner_expr
FROM ... WHEREsubquery_where
)
EXISTS (SELECT 1 FROM ... WHEREsubquery_where
ANDouter_expr
=inner_expr
)
outer_expr
IN (SELECTinner_expr
FROM ... WHEREsubquery_where
)
EXISTS (SELECT 1 FROM ... WHEREsubquery_where
AND trigcond(outer_expr
=inner_expr
))
(oe_1
, ...,oe_N
) IN (SELECTie_1
, ...,ie_N
FROM ... WHEREsubquery_where
)
EXISTS (SELECT 1 FROM ... WHEREsubquery_where
AND trigcond(oe_1
=ie_1
) AND ... AND trigcond(oe_N
=ie_N
) )
trigcond(
X
)
X
oe_i
TRUE
oe_i
CREATE
TRIGGER
trigcond()
X
trigcond(
X
=Y
[OR Y
IS NULL])ref
eq_ref
ref_or_null
trigcond(
X
=Y
)unique_subquery
index_subquery
EXPLAIN
Extra
MySQL的> EXPLAIN SELECT t1.col1,
t1.col1 IN (SELECT t2.key1 FROM t2 WHERE t2.col2=t1.col2) FROM t1\G
*************************** 1。行***************************编号:1 select_type:主表:2 *************************** T1。行***************************编号:2 select_type:相关子查询表:T2型:index_subquerypossible_keys:KEY1键:key1 key_len:5号:功能:2行:使用额外的地方;在空键全扫描
EXPLAIN
SHOW WARNINGS
*************************** 1. row *************************** Level: Note Code: 1003Message: select `test`.`t1`.`col1` AS `col1`, <in_optimizer>(`test`.`t1`.`col1`, <exists>(<index_lookup>(<cache>(`test`.`t1`.`col1`) in t2 on key1 checking NULL where (`test`.`t2`.`col2` = `test`.`t1`.`col2`) having trigcond(<is_not_null_test>(`test`.`t2`.`key1`))))) AS `t1.col1 IN (select t2.key1 from t2 where t2.col2=t1.col2)` from `test`.`t1`
NULL IN (SELECT ...)
NULL IN
(SELECT ...)
NULL
NOT NULL
NULL
outer_expr
IN (SELECTinner_expr
FROM ...)
(outer_expr
IS NOT NULL) AND (outer_expr
IN (SELECTinner_expr
FROM ...))
NULL IN (SELECT ...)
AND
EXISTS (SELECTinner_expr
FROM ... WHEREinner_expr
=outer_expr
)
NULL
EXISTS
subquery_materialization_cost_based
optimizer_switch
EXISTS
INFORMATION_SCHEMA
INFORMATION_SCHEMA
INFORMATION_SCHEMA
INFORMATION_SCHEMA
character_setscollationscollation_character_set_applicabilitycolumnseventsfilesinnodb_columnsinnodb_datafilesinnodb_fieldsinnodb_foreigninnodb_foreign_colsinnodb_indexesinnodb_tablesinnodb_tablespacesinnodb_tablespaces_briefinnodb_tablestatskey_column_usageparameterspartitionsreferential_constraintsresource_groupsroutinesschematastatisticstablestable_constraintstriggersviewsview_routine_usageview_table_usage
INFORMATION_SCHEMA
INFORMATION_SCHEMA
statistics.cardinalitytables.auto_incrementtables.avg_row_lengthtables.checksumtables.check_timetables.create_timetables.data_freetables.data_lengthtables.index_lengthtables.max_data_lengthtables.table_rowstables.update_time
mysql.index_stats
mysql.index_stats
information_schema_stats_expiry
ANALYZE TABLE
mysql.index_stats
information_schema_stats_expiry
read_only
super_read_only
transaction_read_only
innodb_read_only
information_schema_stats_expiry
innodb_read_only
ANALYZE
TABLE
ANALYZE
TABLE
information_schema_stats_expiry=0
INFORMATION_SCHEMA
EXPLAIN
SHOW WARNINGS
EXPLAIN
utf8mb4
MySQL的> SELECT COLLATION_NAME
FROM INFORMATION_SCHEMA.COLLATION_CHARACTER_SET_APPLICABILITY
WHERE CHARACTER_SET_NAME = 'utf8mb4';
| ---------------------------- collation _ name | ---------------------------- | utf8mb4 _通用_我们| | utf8mb4 _仓| | utf8mb4 _ Unicode版本_我们| | utf8mb4 _ _我们| | utf8mb4 _ latvian _我们| | utf8mb4 _罗马尼亚_我们| | utf8mb4 _ slovenian _ |我们……
EXPLAIN
MySQL的> EXPLAIN SELECT COLLATION_NAME
FROM INFORMATION_SCHEMA.COLLATION_CHARACTER_SET_APPLICABILITY
WHERE CHARACTER_SET_NAME = 'utf8mb4'\G
*************************** 1。行***************************编号:1 select_type:简单表:CS分区:null类型:constpossible_keys:小学,名字:名字key_len:194编号:const行:1过滤:额外100:使用索引*************************** 2。行***************************编号:1 select_type:简单表:西分区:null类型:refpossible_keys:character_set_id关键:character_set_id key_len:8编号:const行:68过滤:100个额外的:null2行集,1报警(0.01秒)
SHOW WARNINGS
MySQL的> SHOW WARNINGS\G
*************************** 1. row *************************** Level: Note Code: 1003Message: /* select#1 */ select `mysql`.`col`.`name` AS `COLLATION_NAME` from `mysql`.`character_sets` `cs` join `mysql`.`collations` `col` where ((`mysql`.`col`.`character_set_id` = '45') and ('utf8mb4' = 'utf8mb4'))
SHOW WARNINGS
COLLATION_CHARACTER_SET_APPLICABILITY
collations
WHERE
sys
SHOW INDEX
SHOW CREATE TABLE
MySQL的> SHOW INDEX FROM performance_schema.accounts\G
*************************** 1。行***************************表:账户:账户:0 non_unique key_name seq_in_index:1 column_name:用户整理:零基数:空sub_part:空包装:零:是的index_type:哈希评论:index_comment:可见:是的*************************** 2。行***************************表:账户:账户:0 non_unique key_name seq_in_index:2 column_name:主机整理:零基数:空sub_part:空包装:零:是的index_type:哈希评论:index_comment:可见:yesmysql > SHOW CREATE TABLE performance_schema.rwlock_instances\G
*************************** 1. row *************************** Table: rwlock_instancesCreate Table: CREATE TABLE `rwlock_instances` ( `NAME` varchar(128) NOT NULL, `OBJECT_INSTANCE_BEGIN` bigint(20) unsigned NOT NULL, `WRITE_LOCKED_BY_THREAD_ID` bigint(20) unsigned DEFAULT NULL, `READ_LOCKED_BY_COUNT` int(10) unsigned NOT NULL, PRIMARY KEY (`OBJECT_INSTANCE_BEGIN`), KEY `NAME` (`NAME`), KEY `WRITE_LOCKED_BY_THREAD_ID` (`WRITE_LOCKED_BY_THREAD_ID`)) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
EXPLAIN
MySQL的> EXPLAIN SELECT * FROM performance_schema.accounts
WHERE (USER,HOST) = ('root','localhost')\G
*************************** 1。行***************************编号:1 select_type:简单表:账户分区:零式:constpossible_keys:账号:账号:278 key_len编号:const常量行:1过滤:100个额外的:空
EXPLAIN
accounts
USER
=
<=>
ORDER
BY
INSERT
UPDATE
DELETE
INSERT
UPDATE
DELETE
N
INSERT
INSERT
bulk_insert_buffer_size
LOAD DATA
INFILE
INSERT
InnoDB
MyISAM
SELECT
MyISAM
OPTIMIZE TABLE
MyISAM
key_buffer_size
MyISAM
tbl_name
tbl_name
GRANT
columns_priv
ARCHIVE
OPTIMIZE TABLE
BLOB
InnoDB
SELECT
PRIMARY KEY
INDEX
MEMORY
InnoDB
MEMORY
WHERE
(col1, col2, col3)
(col1, col2)
VARCHAR
CHAR
CHAR(10)
CHAR(15)
utf8
1
' 1'
'01.e1'
MIN()
MAX()
key_col
key_part_N
=constant
key_col
MIN()
MAX()
选择最小( key_part2
)、马克斯( key_part2
from) tbl_name
哪里 key_part1
=10;
ORDER BY
key_part1
,
key_part2
SELECTkey_part3
FROMtbl_name
WHEREkey_part1
=1
NOT NULL
InnoDB
SPATIAL
SRID
SPATIAL
SPATIAL
SPATIAL
INSERT
UPDATE
DELETE
SPATIAL
col_name
选择不同的st_srid( col_name
从) tbl_name
;
SRID
SPATIAL
=
≤
IN
col_name
(N
)N
BLOB
TEXT
CREATE TABLE test (blob_col BLOB, INDEX(blob_col(10)));
InnoDB
COMPACT
DYNAMIC
CREATE TABLE
ALTER TABLE
CREATE INDEX
CHAR
VARCHAR
TEXT
BINARY
VARBINARY
BLOB
FULLTEXT
InnoDB
MyISAM
CHAR
VARCHAR
TEXT
FULLTEXT
FULLTEXT
FULLTEXT
WHERE
FULLTEXT
WHERE
WHERE MATCH(
text
)
AGAINST
('other_text
')
EXPLAIN
EXPLAIN
Extra
SELECT * FROMtbl_name
WHEREhash_col
=MD5(CONCAT(val1
,val2
)) ANDcol1
=val1
ANDcol2
=val2
;
CREATE TABLE test ( id INT NOT NULL, last_name CHAR(30) NOT NULL, first_name CHAR(30) NOT NULL, PRIMARY KEY (id), INDEX name (last_name,first_name) );
name
first_name
first_name
name
SELECT * FROM test WHERE last_name='Widenius';SELECT * FROM test WHERE last_name='Widenius' AND first_name='Michael';SELECT * FROM test WHERE last_name='Widenius' AND (first_name='Michael' OR first_name='Monty');SELECT * FROM test WHERE last_name='Widenius' AND first_name >='M' AND first_name < 'N';
name
SELECT * FROM test WHERE first_name='Michael'; SELECT * FROM test WHERE last_name='Widenius' OR first_name='Michael';
SELECT
SELECT * FROM tbl_name
WHERE col1=val1
AND col2=val2
;
col1
col1
(col1,
col2, col3)
(col1, col2)
SELECT
SELECT * FROM tbl_name
WHERE col1=val1
选择*; tbl_name
WHERE col1=val1
AND col2=val2
选择*; tbl_name
WHERE col2=val2
选择*; tbl_name
WHERE col2=val2
AND col3=val3
;
(col1, col2, col3)
(col2, col3)
EXPLAIN
ref
(...) JOINtbl_name
ONtbl_name
.key
=expr
SHOW INDEX
N/S
N
S
<=>
NULL <=> NULL
N
<=>N
N
=
NULL
expr1
=expr2
expr1
expr2
ref
tbl_name.key
=expr
expr
=
NULL
InnoDB
innodb_stats_method
myisam_stats_method
nulls_equal
NULL
NULL
ref
nulls_unequal
NULL
NULL
NULL
nulls_unequal
ref
nulls_ignored
<=>
=
NULL
nulls_equal
innodb_stats_method
myisam_stats_method
myisam_stats_method
MyISAM
myisam_stats_method
ANALYZE TABLE
innodb_stats_method
myisam_stats_method
ALTER TABLE
innodb_stats_method
myisam_stats_method
InnoDB
nulls_equal
MEMORY
=
>
>=
<
<=
BETWEEN
LIKE
LIKE
SELECT
SELECT * FROM tbl_name
哪里 key_col
像“帕特里克%;select * from tbl_name
哪里 key_col
像Pat _ck % %;
'Patrick'
<=
key_col
<
'Patricl''Pat' <=
key_col
< 'Pau'
SELECT
SELECT * FROM tbl_name
哪里 key_col
像“%帕特里克%;select * from tbl_name
哪里 key_col
喜欢 other_col
;
LIKE
LIKE
... LIKE
'%
string
%'string
col_name
IS
NULLcol_name
AND
AND
WHERE
…哪里 index_part1
=1 ANDindex_part2
=2 ANDother_column
=3 /*index
= 1 ORindex
= 2 */... WHEREindex
=1 OR A=10 ANDindex
=2 /* optimized like "index_part1
='hello'" */... WHEREindex_part1
='hello' ANDindex_part3
=5 /* Can use index onindex1
但不在 index2
或 index3
* /……where index1
=1 ANDindex2
=2 ORindex1
=3 ANDindex3
=3;
WHERE
/*index_part1
is not used */ ... WHEREindex_part2
=1 ANDindex_part3
=2 /* Index is not used in both parts of the WHERE clause */ ... WHEREindex
=1 OR A=10 /* No index spans all rows */ ... WHEREindex_part1
=1 ORindex_part2
=10
LIMIT
InnoDB
CREATE TABLE t1 ( i1 INT NOT NULL DEFAULT 0, i2 INT NOT NULL DEFAULT 0, d DATE DEFAULT NULL, PRIMARY KEY (i1, i2), INDEX k_d (d)) ENGINE = InnoDB;
(i1,
i2)
(d)
(d, i1, i2)
ref
index_merge
MIN()
MAX()
t1
INSERT INTO t1 VALUES(1, 1, '1998-01-01'), (1, 2, '1999-01-01'),(1, 3, '2000-01-01'), (1, 4, '2001-01-01'),(1, 5, '2002-01-01'), (2, 1, '1998-01-01'),(2, 2, '1999-01-01'), (2, 3, '2000-01-01'),(2, 4, '2001-01-01'), (2, 5, '2002-01-01'),(3, 1, '1998-01-01'), (3, 2, '1999-01-01'),(3, 3, '2000-01-01'), (3, 4, '2001-01-01'),(3, 5, '2002-01-01'), (4, 1, '1998-01-01'),(4, 2, '1999-01-01'), (4, 3, '2000-01-01'),(4, 4, '2001-01-01'), (4, 5, '2002-01-01'),(5, 1, '1998-01-01'), (5, 2, '1999-01-01'),(5, 3, '2000-01-01'), (5, 4, '2001-01-01'),(5, 5, '2002-01-01');
EXPLAIN SELECT COUNT(*) FROM t1 WHERE i1 = 3 AND d = '2000-01-01'
(i1, i2)
k_d
k_d
EXPLAIN
MySQL的> EXPLAIN SELECT COUNT(*) FROM t1 WHERE i1 = 3 AND d = '2000-01-01'\G
*************************** 1。行***************************编号:1 select_type:简单表:T1型:refpossible_keys:小学、k_d关键:k_d key_len:4编号:const行:额外5:使用;使用索引
k_d
(d,
i1)
MySQL的> EXPLAIN SELECT COUNT(*) FROM t1 WHERE i1 = 3 AND d = '2000-01-01'\G
*************************** 1。行***************************编号:1 select_type:简单表:T1型:refpossible_keys:小学、k_d关键:k_d key_len:8编号:const常量行:额外1:使用索引
key
EXPLAIN
key_len
i1
ref
const,const
rows
Extra
Using index
SHOW
STATUS
FLUSH TABLE t1;FLUSH STATUS;SELECT COUNT(*) FROM t1 WHERE i1 = 3 AND d = '2000-01-01';SHOW STATUS LIKE 'handler_read%'
FLUSH
TABLES
FLUSH STATUS
SHOW
STATUS
----------------------- ------- | variable_name |价值| ----------------------- ------- | handler_read_first | 0 | | handler_read_key | 1 | | handler_read_last | 0 | | handler_read_next | 5 | | handler_read_prev | 0 | | handler_read_rnd | 0 | | handler_read_rnd_next | 0 | ----------------------- -------
SHOW
STATUS
Handler_read_next
----------------------- ------- | variable_name |价值| ----------------------- ------- | handler_read_first | 0 | | handler_read_key | 1 | | handler_read_last | 0 | | handler_read_next | 1 | | handler_read_prev | 0 | | handler_read_rnd | 0 | | handler_read_rnd_next | 0 | ----------------------- -------
use_index_extensions
optimizer_switch
use_index_extensions
SET optimizer_switch = 'use_index_extensions=off';
CREATE TABLE t1 (f1 INT, gc INT AS (f1 + 1) STORED, INDEX (gc));
gc
WHERE
SELECT * FROM t1 WHERE gc > 9;
WHERE
GROUP BY
gc
SELECT * FROM T1在F1的9 1.;
f1 +
1
gc
EXPLAIN
MySQL的> EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > 9\G
*************************** 1。行***************************编号:1 select_type:简单表:T1分区:null类型:rangepossible_keys:GC关键:GC key_len:5编号:零排:1过滤:额外100:使用索引条件
f1
+ 1
EXPLAIN
SHOW
WARNINGS
MySQL的> SHOW WARNINGS\G
*************************** 1。行***************************水平:注意代码:1003message:/ *选择# 1 * /选择`测试`。` T1 `。` F1 `作为` F1 `,`测试`。` T1 `。` GC `作为` GC `从`测试`。` T1 `哪里(`测试` ` T1。` ` GC ` > 9)。
f1 + 1
f1 + 1
=
<
<=
>
>=
BETWEEN
IN()
BETWEEN
IN()
BETWEEN
IN()
BETWEEN
IN()
gc INT AS (f1) STORED
JSON_UNQUOTE()
doc_name文本(json_extract(JDoc,“美元。名字))存储
doc_name TEXT AS (JSON_UNQUOTE(JSON_EXTRACT(jdoc, '$.name'))) STORED
... WHERE JSON_EXTRACT(jdoc, '$.name') = 'some_string
' ... ... WHERE JSON_UNQUOTE(JSON_EXTRACT(jdoc, '$.name')) = 'some_string
' ...
JSON_UNQUOTE()
VISIBLE
CREATE TABLE
CREATE INDEX
ALTER TABLE
CREATE TABLE t1 ( i INT, j INT, k INT, INDEX i_idx (i) INVISIBLE) ENGINE = InnoDB;CREATE INDEX j_idx ON t1 (j) INVISIBLE;ALTER TABLE t1 ADD INDEX k_idx (k) INVISIBLE;
VISIBLE
ALTER TABLE ... ALTER INDEX
修改表T1改变指数i_idx无形;改变表T1改变指数i_idx可见;
INFORMATION_SCHEMA.STATISTICS
SHOW INDEX
MySQL的> SELECT INDEX_NAME, IS_VISIBLE
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'db1' AND TABLE_NAME = 't1';
有一个是一个隐形的,可见的,可见的的。
EXPLAIN
use_invisible_indexes
optimizer_switch
on
UNIQUE
CREATE TABLE t2 ( i INT NOT NULL, j INT NOT NULL, UNIQUE j_idx (j) ) ENGINE = InnoDB;
NOT NULL
mysql> ALTER TABLE t2 ALTER INDEX j_idx INVISIBLE;
ERROR 3522 (HY000): A primary key index cannot be invisible.
ALTER TABLE t2 ADD PRIMARY KEY (i);
j
MySQL的> ALTER TABLE t2 ALTER INDEX j_idx INVISIBLE;
查询行,0行受影响(0.03秒)
DESC
CREATE TABLE t ( c1 INT, c2 INT, INDEX idx1 (c1 ASC, c2 ASC), INDEX idx2 (c1 ASC, c2 DESC), INDEX idx3 (c1 DESC, c2 ASC), INDEX idx4 (c1 DESC, c2 DESC) );
ORDER BY
ORDER BY c1 ASC, c2 ASC -- optimizer can use idx1 ORDER BY c1 DESC, c2 DESC -- optimizer can use idx4 ORDER BY c1 ASC, c2 DESC -- optimizer can use idx2 ORDER BY c1 DESC, c2 ASC -- optimizer can use idx3
InnoDB
InnoDB
FTS_DOC_ID
VIRTUAL
DISTINCT
BTREE
FULLTEXT
ASC
HASH
SPATIAL
InnoDB
DYNAMIC
innodb_default_row_format
CREATE
TABLE
ALTER
TABLE
COMPACT
COMPRESSED
CHAR
utf8mb4
ROW_FORMAT=REDUNDANT
CHAR(
N
)N
InnoDB
N
N
N
ROW_FORMAT=COMPRESSED
MyISAM
MyISAM
MyISAM
VARCHAR
TEXT
BLOB
VARCHAR
CREATE TABLE
ROW_FORMAT=FIXED
InnoDB
customer
customer_name
BINARY
VARCHAR
GROUP BY
MEMORY
InnoDB
InnoDB
VARCHAR
MD5()
AND
blob_column
=
long_string_value
Uptime: 426 Running threads: 1 Questions: 11082 Reloads: 1 Open tables: 12
Open tables
MyISAM
table_open_cache
max_connections
table_open_cache
max_connections
N
N
table_open_cache
table_open_cache
MyISAM
MyISAM
--open-files-limit
table_open_cache
table_open_cache
table_open_cache
FLUSH
TABLES
MyISAM
HANDLER
tbl_name
OPENtbl_name
Opened_tables
MySQL的> SHOW GLOBAL STATUS LIKE 'Opened_tables';
变量名称和值_ ------- | | | ---------------打开表| ------- | _ 2741 | --------------- -------
FLUSH
TABLES
MyISAM
SELECT
UNION
TEMPTABLE
UNION
ORDER
BY
ORDER
BY
DISTINCT
SQL_SMALL_RESULT
INSERT ...
SELECT
SELECT
UPDATE
EXPLAIN
Using temporary
EXPLAIN
Created_tmp_tables
Created_tmp_disk_tables
UNION
EXPLAIN
UNION
UNION ALL
UNION
DISTINCT
ORDER BY
{INSERT | REPLACE} ... SELECT ...
TempTable
InnoDB
internal_tmp_mem_storage_engine
MEMORY
TempTable
VARCHAR
VARBINARY
temptable_max_ram
temptable_max_ram
tmpdir
tmpdir
mysqld
temptable_max_ram
memory/temptable/physical_ram
TempTable
memory/temptable/physical_disk
temptable_max_ram
memory_summary_global_by_event_name
MEMORY
tmp_table_size
max_heap_table_size
CREATE
TABLE
max_heap_table_size
internal_tmp_disk_storage_engine
MYISAM
MyISAM
internal_tmp_disk_storage_engine=MYISAM
internal_tmp_disk_storage_engine=INNODB
InnoDB
internal_tmp_disk_storage_engine
TempTable
VARBINARY
temptable_max_ram
MEMORY
VARBINARY
BINARY
InnoDB
internal_tmp_disk_storage_engine
MEMORY
big_tables
InnoDB
InnoDB
OPTIMIZE TABLE
OPTIMIZE TABLE
InnoDB
AUTO_INCREMENT
VARCHAR
CHAR
CHAR(
N
)N
COMPACT
utf8
CHAR(
N
)N
COMPRESSED
COMPACT
InnoDB
AUTOCOMMIT=1
SET AUTOCOMMIT=0
START
TRANSACTION
InnoDB
SELECT
InnoDB
innodb_change_buffering=all
COMMIT
innodb_force_recovery=3
innodb_change_buffering=all
innodb_flush_log_at_trx_commit
InnoDB
READ COMMITTED
REPEATABLE READ
PAGE_MAX_TRX_ID
InnoDB
TRX_ID
SELECT ... FOR UPDATE
InnoDB
START TRANSACTION
READ ONLY
MyISAM
错误1792(25006):无法执行语句在只读事务。
autocommit
SELECT
FOR
UPDATE
READ
ONLY
InnoDB
START TRANSACTION READ
ONLY
COMMIT
autocommit
START
TRANSACTION
autocommit
InnoDB
SHOW ENGINE
INNODB STATUS
InnoDB
innodb_log_file_size
innodb_log_files_in_group
innodb_log_buffer_size
innodb_log_write_ahead_size
innodb_log_write_ahead_size
innodb_log_write_ahead_size
InnoDB
innodb_page_size
innodb_log_write_ahead_size
innodb_page_size
innodb_log_write_ahead_size
innodb_page_size
innodb_log_write_ahead_size
innodb_log_wait_for_flush_spin_hwm
innodb_log_spin_cpu_abs_lwm
innodb_log_spin_cpu_pct_hwm
innodb_log_spin_cpu_pct_hwm
InnoDB
SET
autocommit
COMMIT
SET autocommit=0;... SQL import statements ...
承诺;
--opt
SET
autocommit
COMMIT
UNIQUE
SET unique_checks=0;... SQL import statements ...
SET unique_checks=1;
InnoDB
FOREIGN KEY
SET foreign_key_checks=0;... SQL import statements ...
SET foreign_key_checks=1;
INSERT
插入的热情yourtable值(1,2),(5)…………………;
InnoDB
innodb_autoinc_lock_mode
PRIMARY KEY
PRIMARY KEY
InnoDB
FTS_DOC_ID
FTS_DOC_ID_INDEX
CREATE TABLE t1 (FTS_DOC_ID BIGINT unsigned NOT NULL AUTO_INCREMENT,title varchar(255) NOT NULL DEFAULT '',text mediumtext NOT NULL,PRIMARY KEY (`FTS_DOC_ID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;CREATE UNIQUE INDEX FTS_DOC_ID_INDEX on t1(FTS_DOC_ID);
FULLTEXT
FTS_DOC_ID
FULLTEXT
INSERT
UPDATE
InnoDB
FTS_DOC_ID
CREATE
FULLTEXT INDEX
InnoDB
InnoDB
InnoDB
NULL
NULL
InnoDB
CREATE
DROP
TRUNCATE TABLE
tbl_name
DELETE
DROP TABLE
CREATE TABLE
InnoDB
CREATE TABLE
DROP
top
InnoDB
innodb_buffer_pool_size
innodb_buffer_pool_size
fsync()
innodb_flush_method
InnoDB
innodb_use_native_aio
InnoDB
InnoDB
forcedirectio
InnoDB
innodb_flush_method =
O_DIRECT
directio()
InnoDB
innodb_buffer_pool_size
forcedirectio
innodb_flush_method
convosync=direct
MyISAM
InnoDB
InnoDB
crc32
InnoDB
minimal
InnoDB
innodb_io_capacity
InnoDB
innodb_io_capacity
SHOW ENGINE
INNODB STATUS
innodb_max_dirty_pages_pct
Log sequence number - Last checkpoint
innodb_doublewrite
innodb_flush_method
InnoDB
innodb_log_compressed_pages
zlib
innodb_log_compressed_pages
InnoDB
InnoDB
InnoDB
innodb_adaptive_hash_index
InnoDB
InnoDB
InnoDB
InnoDB
InnoDB
InnoDB
InnoDB
InnoDB
innodb_thread_concurrency
innodb_concurrency_tickets
InnoDB
SELECT 1 FROM
tbl_name
LIMIT 1
innodb_stats_persistent
MyISAM
InnoDB
MyISAM
ANALYZE TABLE
SHOW INDEX FROM
tbl_name
SELECT
MyISAM
INSERT
OPTIMIZE
TABLE
concurrent_insert
MyISAM
VARCHAR
BLOB
TEXT
MyISAM
ALTER TABLE ... ORDER BY
expr1
,
expr2
, ...expr1
expr2
UPDATEtbl_name
SETcount_col
=count_col
+1 WHEREkey_col
=constant
;
MyISAM
OPTIMIZE TABLE
MyISAM
DELAY_KEY_WRITE=1
--myisam-recover-options
DELAY_KEY_WRITE
MyISAM
MyISAM
SELECT
LOAD DATA
INFILE
/path/to/db/tbl_name
LOAD DATA
INFILE
/path/to/db/tbl_name
LOAD
DATA INFILE
LOAD DATA
INFILE
LOAD
DATA INFILE
MyISAM
FLUSH TABLES
修改表 tbl_name
禁用按键;修改表 tbl_name
使钥匙;
INSERT
锁定表写;插入一个值(1,23),(2,34),(4,33);插入一个值(8,26),(6,29);解锁表;
INSERT
INSERT
INSERT
INSERT
UPDATE
DELETE
LOCK
TABLES
UNLOCK
TABLES
INSERT
LOAD DATA
INFILE
MyISAM
LOAD DATA
INFILE
INSERT
key_buffer_size
REPAIR TABLE
REPAIR TABLE
myisam_max_sort_file_size
--key_buffer_size=128M --myisam_sort_buffer_size=256M --read_buffer_size=64M --write_buffer_size=64M
key_buffer_size | key_buffer_size |
myisam_sort_buffer_size | myisam_sort_buffer_size |
read_buffer_size | read_buffer_size |
write_buffer_size |
myisam_sort_buffer_size
read_buffer_size
key_buffer_size
myisam_max_sort_file_size
key_buffer_size
key_buffer_size
key_buffer_size
REPAIR
TABLE
SET SESSION myisam_sort_buffer_size = 256*1024*1024; SET SESSION read_buffer_size = 64*1024*1024; SET GLOBAL myisam_max_sort_file_size = 100*1024*1024*1024; SET GLOBAL repair_cache.key_buffer_size = 128*1024*1024; CACHE INDEXtbl_name
IN repair_cache; LOAD INDEX INTO CACHEtbl_name
; REPAIR TABLEtbl_name
; SET GLOBAL repair_cache.key_buffer_size = 0;
REPAIR
TABLE
SET @old_myisam_sort_buffer_size = @@global.myisam_max_sort_file_size;SET GLOBAL myisam_max_sort_file_size = 100*1024*1024*1024;REPAIR TABLE tbl_name ;SET GLOBAL myisam_max_sort_file_size = @old_myisam_max_sort_file_size;
REPAIR
TABLE
[mysqld] myisam_sort_buffer_size=256M key_buffer_size=1G myisam_max_sort_file_size=100G
read_buffer_size
read_buffer_size
MEMORY
MyISAM
MEMORY
CREATE INDEX
USING HASH
BETWEEN
=
IN
USING HASH
MEMORY
WHERE
EXPLAIN
EXPLAIN
EXPLAIN
EXPLAIN
EXPLAIN
EXPLAIN
connection_id
SELECT
EXPLAIN
SHOW WARNINGS
EXPLAIN
FORMAT
FORMAT
EXPLAIN
EXPLAIN
SELECT
SELECT
STRAIGHT_JOIN
EXPLAIN
ANALYZE
TABLE
EXPLAIN
EXPLAIN
tbl_name
tbl_name
tbl_name
EXPLAIN
EXPLAIN
SELECT
DELETE
INSERT
REPLACE
UPDATE
EXPLAIN
SELECT
EXPLAIN
EXPLAIN
type
Extra
EXPLAIN
FORMAT=JSON
id | select_id | SELECT |
select_type | SELECT | |
table | table_name | |
partitions | partitions | |
type | access_type | |
possible_keys | possible_keys | |
key | key | |
key_len | key_length | |
ref | ref | |
rows | rows | |
filtered | filtered | |
Extra |
NULL
SELECT
SELECT
table
<union
M
N
M
N
SELECT
SELECT
SIMPLE
select_type | ||
---|---|---|
SIMPLE | SELECT UNION | |
PRIMARY | SELECT | |
UNION | SELECT UNION | |
DEPENDENT UNION | dependent
| SELECT UNION |
UNION RESULT | union_result | UNION |
SUBQUERY | SELECT | |
DEPENDENT SUBQUERY | dependent
| SELECT |
DERIVED | ||
MATERIALIZED | materialized_from_subquery | |
UNCACHEABLE SUBQUERY | cacheable
| |
UNCACHEABLE UNION | cacheable
| UNION
|
DEPENDENT
DEPENDENT SUBQUERY
DEPENDENT SUBQUERY
FORMAT=JSON
select_type
SELECT
materialized_from_subquery
SIMPLE
select_type
SELECT
DELETE
DELETE
<union
M
,N
>M
N
<derived
N
>N
<subquery
N
>N
NULL
EXPLAIN
possible_keys
possible_keys
EXPLAIN
NULL
EXPLAIN
SHOW INDEX
FROM
tbl_name
key
key
possible_keys
InnoDB
key
possible_keys
USE
INDEX
MyISAM
ANALYZE TABLE
key_len
key
len_len
NULL
ref
func
SHOW WARNINGS
EXPLAIN
EXPLAIN
rows
InnoDB
filtered
rows
rows
is 50.00 (50%), the number of rows to be joined with the following table is 1000 × 50% = 500.
EXPLAIN
Extra
type
EXPLAIN
The table has only one row (= system table). This is a special case of theconst
const
const
UNIQUE
tbl_name
const
SELECT * FROM tbl_name
哪里 primary_key
=1;SELECT * FROMtbl_name
哪里 primary_key_part1
=1 ANDprimary_key_part2
=2;
system
const
UNIQUE NOT
NULL
eq_ref
=
eq_ref
ref_table
SELECT * FROM ref_table
, other_table
哪里 ref_table
key_column
=other_table
column
选择*; ref_table
, other_table
哪里 ref_table
key_column_part1
=other_table
column
和 ref_table
key_column_part2
=1;
ref
UNIQUE
ref
=
<=>
ref
ref_table
SELECT * FROM ref_table
哪里 key_column
=expr
选择*; ref_table
, other_table
哪里 ref_table
key_column
=other_table
column
选择*; ref_table
, other_table
哪里 ref_table
key_column_part1
=other_table
column
和 ref_table
key_column_part2
=1;
FULLTEXT
ref
ref_or_null
ref_table
SELECT * FROM ref_table
哪里 key_column
=expr
或 key_column
是空的;
key
eq_ref
value
IN (SELECTprimary_key
FROMsingle_table
WHEREsome_expr
)
unique_subquery
unique_subquery
value
IN (SELECTkey_column
FROMsingle_table
WHEREsome_expr
)
key
ref
range
=
<>
>
>=
<
<=
IS NULL
<=>
BETWEEN
LIKE
IN()
SELECT * FROM tbl_name
哪里 key_column
= 10;SELECT * FROMtbl_name
哪里 key_column
之间的10和20;select * from tbl_name
哪里 key_column
在(30);选择* tbl_name
哪里 key_part1
= 10 ANDkey_part2
(10,20,30);
index
ALL
Extra
ALL
Uses index
const
ALL
Extra
EXPLAIN
message
Extra
Using temporary
using_filesort
true
const row not found
SELECT ... FROM
tbl_name
Deleting all rows
DELETE
MyISAM
Distinct
FirstMatch(
tbl_name
)
tbl_name
Full scan on NULL key
Impossible HAVING
HAVING
Impossible WHERE
WHERE
Impossible WHERE noticed after reading const
tables
LooseScan(
m
..n
)
m
n
No matching min/max row
SELECT MIN(...) FROM ... WHERE
condition
no matching row in const table
No matching rows after partition
pruning
No tables used
FROM
INSERT
REPLACE
EXPLAIN
SELECT
EXPLAIN INSERT INTO t SELECT 10 FROM
DUAL
Not exists
LEFT JOIN
SELECT * FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS NULL;
t2.id
t1
t1.id
t2.id
t2
t1
t2
Plan isn't ready yet
EXPLAIN FOR
CONNECTION
Range checked for each record (index map:
N
)
range
index_merge
SHOW INDEX
N
Recursive
SELECT
Scanned
N
databases
INFORMATION_SCHEMA
N
Select tables optimized away
GROUP BY
SELECT MIN(c1), MIN(c2) FROM t1;
MIN(c1)
c1
Extra
SELECT MIN(c2) FROM t1 WHERE c1 <= 10;
(c1, c2)
c1 <= 10
c2
SELECT MIN(c2) FROM t1 WHERE c1 = 10;
c1 =
10
MyISAM
Extra
WHERE
Skip_open_table
Open_full_table
INFORMATION_SCHEMA
Skip_open_table
Open_frm_only
Open_full_table
Start temporary
message
unique row not found
SELECT ... FROM
tbl_name
PRIMARY KEY
Using filesort
WHERE
Using index
InnoDB
Extra
index
PRIMARY
Using index condition
Using index for group-by
Using index
GROUP BY
Using index for skip scan
Using join buffer (Block Nested Loop)
using_join_buffer
(Block Nested Loop)
EXPLAIN
using_join_buffer
Batched Key Access
Using MRR
Using sort_union(...)
Using
intersect(...)
index_merge
Using temporary
GROUP BY
Using where
WHERE
Using where
ALL
index
Using where
WHERE
Using where with pushed condition
NDB
Zero limit
LIMIT 0
rows
EXPLAIN
max_join_size
SELECT
EXPLAIN
SELECT
EXPLAIN
EXPLAIN SELECT tt.TicketNumber, tt.TimeIn, tt.ProjectReference, tt.EstimatedShipDate, tt.ActualShipDate, tt.ClientID, tt.ServiceCodes, tt.RepetitiveID, tt.CurrentProcess, tt.CurrentDPPerson, tt.RecordVolume, tt.DPPrinted, et.COUNTRY, et_1.COUNTRY, do.CUSTNAME FROM tt, et, et AS et_1, do WHERE tt.SubmitTime IS NULL AND tt.ActualPC = et.EMPLOYID AND tt.AssignedPC = et_1.EMPLOYID AND tt.ClientID = do.CUSTNMBR;
tt | ActualPC | CHAR(10) |
tt | AssignedPC | CHAR(10) |
tt | ClientID | CHAR(10) |
et | EMPLOYID | CHAR(15) |
do | CUSTNMBR | CHAR(15) |
tt | ActualPC |
tt | AssignedPC |
tt | ClientID |
et | EMPLOYID |
do | CUSTNMBR |
tt.ActualPC
EXPLAIN
桌上型possible_keys关键key_len参考行提取所有主要零零零74do所有原零空2135et_1所有原零零零74tt所有assignedpc,零零零3872 clientId,actualpc范围检查每个记录(指数图:0x23)
type
ALL
for each table, this output indicates that MySQL is generating a Cartesian product of all the tables; that is, every combination of rows. This takes quite a long time, because the product of the number of rows in each table must be examined. For the case at hand, this product is 74 × 2135 × 74 × 3872 = 45,268,558,720 rows. If the tables were bigger, you can only imagine how long it would take.
VARCHAR
CHAR
CHAR(10)
CHAR(15)
ALTER TABLE
mysql> ALTER TABLE tt MODIFY ActualPC VARCHAR(15);
tt.ActualPC
VARCHAR(15)
EXPLAIN
桌上型possible_keys关键key_len参考行extratt所有assignedpc,零零零3872使用clientId,哪里actualpcdo所有原零零零2135范围检查每个记录(指数图:0x1)et_1所有原零零零74范围检查每个记录(指数图:0x1)等eq_ref小学15 tt.actualpc 1
rows
tt.AssignedPC =
et_1.EMPLOYID
tt.ClientID = do.CUSTNMBR
mysql>ALTER TABLE tt MODIFY AssignedPC VARCHAR(15),
MODIFY ClientID VARCHAR(15);
EXPLAIN
桌上型possible_keys关键key_len参考行提取所有主要零零零74tt REF assignedpc,actualpc 15 et.employid 52使用clientId,哪里actualpcet_1 eq_ref小学15 tt.assignedpc 1do eq_ref小学15 tt.clientid 1
tt.ActualPC
mysql> ANALYZE TABLE tt;
EXPLAIN
桌上型possible_keys关键key_len参考行extratt所有assignedpc零零零3872使用clientId,哪里actualpcet eq_ref小学15 tt.actualpc 1et_1 eq_ref小学15 tt.assignedpc 1do eq_ref小学15 tt.clientid 1
rows
EXPLAIN
STRAIGHT_JOIN
SELECT
STRAIGHT_JOIN
EXPLAIN
SELECT
EXPLAIN
EXPLAIN
SHOW WARNINGS
EXPLAIN
SELECT
DELETE
INSERT
REPLACE
UPDATE
SELECT
Message
SHOW WARNINGS
SELECT
SELECT
SHOW WARNINGS
EXPLAIN
SELECT
SHOW WARNINGS
DELETE
INSERT
REPLACE
UPDATE
EXPLAIN
MySQL的> EXPLAIN
SELECT t1.a, t1.a IN (SELECT t2.a FROM t2) FROM t1\G
*************************** 1。行*************************** ID:1 select_type:主表:T1型:indexpossible_keys:空键:主要key_len:四号:空的行数:4过滤:壹佰额外:使用索引*************************** 2。行*************************** ID:2 select_type:子查询表:T2型:indexpossible_keys:关键:一key_len:五号:空的行数:3过滤:壹佰额外:在使用指数排,1警告(0.001秒)MySQL > SHOW WARNINGS\G
*************************** 1. row *************************** Level: Note Code: 1003Message: /* select#1 */ select `test`.`t1`.`a` AS `a`, <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where 1 having 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`))))) AS `t1.a IN (SELECT t2.a FROM t2)` from `test`.`t1`1 row in set (0.00 sec)
SHOW
WARNINGS
SHOW
WARNINGS
<auto_key>
<cache>(
expr
)
<temporary
table>
<exists>(
query
fragment
)
EXISTS
<in_optimizer>(
query
fragment
)
<index_lookup>(
query
fragment
)
<if>(
condition
,
expr1
,
expr2
)
expr1
expr2
<is_not_null_test>(
expr
)
NULL
<materialize>(
query
fragment
)
`materialized-subquery`.
col_name
col_name
<primary_index_lookup>(
query
fragment
)
<ref_null_helper>(
expr
)
/* select#
N
*/
select_stmt
SELECT
EXPLAIN
N
outer_tables
semi join
(inner_tables
)
inner_tables
<temporary table>
const
system
FORMAT=JSON
const
ref
EXPLAIN [options
] FOR CONNECTIONconnection_id
;
EXPLAIN FOR CONNECTION
EXPLAIN
EXPLAIN
EXPLAIN FOR
CONNECTION
connection_id
PROCESSLIST
SHOW PROCESSLIST
PROCESS
EXPLAIN FOR CONNECTION
SELECT
DELETE
INSERT
REPLACE
UPDATE
EXPLAIN
EXPLAIN
MySQL的> SELECT CONNECTION_ID();
_;| connection ID(373);| | |;1行集(0秒)在MySQL > EXPLAIN FOR CONNECTION 373;
错误1889(hy000):连接命令解释是supportedonly选择/更新/插入/删除/替换
Com_explain_other
EXPLAIN FOR
CONNECTION
log(
row_count
) /
log(index_block_length
/ 3 * 2 /
(index_length
+
data_pointer_length
)) + 1
MEDIUMINT
=4
This index would require storage of about 500,000 * 7 * 3/2 = 5.2MB (assuming a typical index buffer fill ratio of 2/3), so you probably have much of the index in memory and so need only one or two calls to read data to find the row.
N
N
key_buffer_size
optimizer_prune_level
optimizer_prune_level=1
optimizer_prune_level=0
optimizer_search_depth
optimizer_search_depth
optimizer_search_depth
optimizer_search_depth
optimizer_search_depth
optimizer_switch
optimizer_switch
optimizer_switch
optimizer_switch
SELECT /*+ NO_RANGE_OPTIMIZATION(t3 PRIMARY, f2_idx) */ f1 FROM t3 WHERE f1 > 30 AND f1 < 33; SELECT /*+ BKA(t1) NO_BKA(t2) */ * FROM t1 INNER JOIN t2 WHERE ...; SELECT /*+ NO_ICP(t1, t2) */ * FROM t1 INNER JOIN t2 WHERE ...; SELECT /*+ SEMIJOIN(FIRSTMATCH, LOOSESCAN) */ * FROM t1 ...; EXPLAIN SELECT /*+ NO_ICP(t1) */ * FROM t1 WHERE ...; SELECT /*+ MERGE(dt) */ * FROM (SELECT * FROM t1) AS dt; INSERT /*+ SET_VAR(foreign_key_checks=OFF) */ INTO t2 VALUES(2);
BKA NO_BKA | ||
BNL NO_BNL | ||
INDEX_MERGE NO_INDEX_MERGE | ||
JOIN_FIXED_ORDER | FROM | |
JOIN_ORDER | ||
JOIN_PREFIX | ||
JOIN_SUFFIX | ||
MAX_EXECUTION_TIME | ||
MERGE NO_MERGE | ||
MRR NO_MRR | ||
NO_ICP | ||
NO_RANGE_OPTIMIZATION | ||
QB_NAME | ||
RESOURCE_GROUP | ||
SEMIJOIN NO_SEMIJOIN | ||
SKIP_SCAN NO_SKIP_SCAN | ||
SET_VAR | ||
SUBQUERY | IN
|
/*+ ... */
+
/*+ BKA(t1) */ /*+ BNL(t1, t2) */ /*+ NO_RANGE_OPTIMIZATION(t4 PRIMARY) */ /*+ QB_NAME(qb2) */
+
SELECT
UPDATE
INSERT
REPLACE
DELETE
SELECT /*+ ... */ ... INSERT /*+ ... */ ... REPLACE /*+ ... */ ... UPDATE /*+ ... */ ... DELETE /*+ ... */ ...
(SELECT /*+ ... */ ... ) (SELECT ... ) UNION (SELECT /*+ ... */ ... ) (SELECT /*+ ... */ ... ) UNION (SELECT /*+ ... */ ... ) UPDATE ... WHERE x IN (SELECT /*+ ... */ ...) INSERT ... SELECT /*+ ... */ ...
EXPLAIN
解释选择/ *…*解释更新/…在X(选择/ *…* /…)
EXPLAIN
SHOW WARNINGS
EXPLAIN
SHOW
WARNINGS
SELECT /*+ BNL(t1) BKA(t2) */ ...
SELECT /*+ BNL(t1) */ /* BKA(t2) */ ...
/*+ MRR(idx1)
MRR(idx1) */
/*+
MRR(idx1) NO_MRR(idx1) */
JOIN_FIXED_ORDER
hint_name
([ @ query_block_name
])
hint_name
([@query_block_name
]tbl_name
[,tbl_name
] ...)hint_name
(tbl_name
[@query_block_name
] [,tbl_name
[@query_block_name
]] ...)
hint_name
JOIN_FIXED_ORDER
SELECT
STRAIGHT_JOIN
JOIN_ORDER
JOIN_PREFIX
JOIN_SUFFIX
tbl_name
FROM
query_block_name
query_block_name
tbl_name
query_block_name
SELECT /*+ JOIN_PREFIX(t2, t5@subq2, t4@subq1) JOIN_ORDER(t4@subq1, t3) JOIN_SUFFIX(t1) */ COUNT(*) FROM t1 JOIN t2 JOIN t3 WHERE t1.f1 IN (SELECT /*+ QB_NAME(subq1) */ f1 FROM t4) AND t2.f1 IN (SELECT /*+ QB_NAME(subq2) */ f1 FROM t5);
subq1
t4@subq1
t4@subq1
JOIN_PREFIX
JOIN_ORDER
/*+ JOIN_PREFIX(t1) JOIN_PREFIX(t2) */
JOIN_PREFIX
/ * join_prefix(T1)join_suffix(T2)* /
/*+ JOIN_ORDER(t1, t2) JOIN_ORDER(t2, t3) */
JOIN_ORDER
SELECT /*+ JOIN_ORDER(t1, t2) JOIN_PREFIX(t2, t1) */ ... FROM t1, t2;
/*+ JOIN_ORDER(t1, t2) JOIN_PREFIX(t2, t1) */
JOIN_ORDER
t1
t1
EXPLAIN
const
const
const
如果您已经注册了,请先登录。 const_tbl
同时,_阶(T2),T1,T2)
EXPLAIN
LEFT
INNER
STRAIGHT_JOIN
SELECT /*+ JOIN_PREFIX(t1, t2) */FROM t2 LEFT JOIN t1;
LEFT
JOIN
hint_name
([@query_block_name
] [tbl_name
[,tbl_name
] ...])hint_name
([tbl_name
@query_block_name
[,tbl_name
@query_block_name
] ...])
hint_name
tbl_name
query_block_name
query_block_name
tbl_name
query_block_name
SELECT /*+ NO_BKA(t1, t2) */ t1.* FROM t1 INNER JOIN t2 INNER JOIN t3; SELECT /*+ NO_BNL() BKA(t1) */ t1.* FROM t1 INNER JOIN t2 INNER JOIN t3; SELECT /*+ NO_MERGE(dt) */ * FROM (SELECT * FROM t1) AS dt;
SELECT /*+ BNL(t2) */ FROM t1, t2;
t1
t1
t2
MERGE
derived_merge
optimizer_switch
ALGORITHM={MERGE|TEMPTABLE}
hint_name
([@query_block_name
]tbl_name
[index_name
[,index_name
] ...])hint_name
(tbl_name
@query_block_name
[index_name
[,index_name
] ...])
hint_name
INDEX_MERGE
INDEX_MERGE
NO_INDEX_MERGE
MRR
InnoDB
NO_ICP
NO_RANGE_OPTIMIZATION
SKIP_SCAN
SKIP_SCAN
NO_SKIP_SCAN
tbl_name
index_name
PRIMARY
SHOW INDEX
query_block_name
query_block_name
tbl_name
query_block_name
SELECT /*+ INDEX_MERGE(t1 f3, PRIMARY) */ f2 FROM t1 WHERE f1 = 'o' AND f2 = f3 AND f3 <= 4; SELECT /*+ MRR(t1) */ * FROM t1 WHERE f2 <= 3 AND 3 <= f3; SELECT /*+ NO_RANGE_OPTIMIZATION(t3 PRIMARY, f2_idx) */ f1 FROM t3 WHERE f1 > 30 AND f1 < 33; INSERT INTO t3(f1, f2, f3) (SELECT /*+ NO_ICP(t2) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 AND t1.f2 AND t2.f2 + 1 >= t1.f1 + 1); SELECT /*+ SKIP_SCAN(t1 PRIMARY) */ f1, f2 FROM t1 WHERE f2 > 40;
optimizer_switch
t1
b
d
i_b
a
c
SELECT /*+ INDEX_MERGE(t1 i_a, i_b, i_c)*/ * FROM t1 WHERE a = 1 AND b = 2 AND c = 3 AND d = 4;
(i_a, i_b, i_c)
SELECT /*+ INDEX_MERGE(t1 i_a, i_b, i_c)*/ * FROM t1 WHERE b = 1 AND c = 2 AND d = 3;
(i_b, i_c)
_合并/ *指数(T1 _ I,I _ B)没有_ _合并指数(T1 _ * / I B)
NO_INDEX_MERGE
/ *没有_ _合并指数(T1 _ I,I _(b)_合并指数(T1 _ * / I B)
INDEX_MERGE
INDEX_MERGE
optimizer_switch
SET optimizer_switch='index_merge_intersection=off';SELECT /*+ INDEX_MERGE(t1 i_b, i_c) */ * FROM t1WHERE b = 1 AND c = 2 AND d = 3;
optimizer_switch
SET optimizer_switch='index_merge_intersection=on'; SELECT /*+ INDEX_MERGE(t1 i_b) */ * FROM t1 WHERE b = 1 AND c = 2 AND d = 3;
optimizer_switch
SET optimizer_switch='index_merge_intersection=off'; SELECT /*+ INDEX_MERGE(t1 i_b) */ * FROM t1 WHERE b = 1 AND c = 2 AND d = 3;
optimizer_switch
USE INDEX
IGNORE INDEX
NO_INDEX_MERGE
/* INDEX_MERGE(t1 i_a, i_b, i_c) */ ... 不知道索引
IGNORE INDEX
i_a
/ * noérère index aramée(t1 ièmeème a,i?b)* /…力量指数
i_a, i_b
i_a
range
ref
IGNORE INDEX
FORCE INDEX
SELECT /*+ INDEX_MERGE(t1 i_a, i_b, i_c) */ a FROM t1 FORCE INDEX (i_a, i_b) WHERE c = 'h' AND a = 2 AND b = 'b';
(i_a, i_b)
USE
INDEX
IN
hint_name
([@query_block_name
] [strategy
[,strategy
] ...])
hint_name
SEMIJOIN
strategy
FIRSTMATCH
MATERIALIZATION
SEMIJOIN
optimizer_switch
NO_SEMIJOIN
SEMIJOIN
DUPSWEEDOUT
optimizer_prune_level=0
SELECT /*+ NO_SEMIJOIN(@subq1 FIRSTMATCH, LOOSESCAN) */ * FROM t2 WHERE t2.a IN (SELECT /*+ QB_NAME(subq1) */ a FROM t3); SELECT /*+ SEMIJOIN(@subq1 MATERIALIZATION, DUPSWEEDOUT) */ * FROM t2 WHERE t2.a IN (SELECT /*+ QB_NAME(subq1) */ a FROM t3);
IN
SUBQUERY([@query_block_name
]strategy
)
SUBQUERY
SUBQUERY
strategy
MATERIALIZATION
SELECT id, a IN (SELECT /*+ SUBQUERY(MATERIALIZATION) */ a FROM t1) FROM t2; SELECT * FROM t2 WHERE t2.a IN (SELECT /*+ SUBQUERY(INTOEXISTS) */ a FROM t1);
SUBQUERY
query_block_name
query_block_name
MAX_EXECUTION_TIME
SELECT
N
最高的执行时间 N
)
SELECT /*+ MAX_EXECUTION_TIME(1000) */ * FROM t1 INNER JOIN t2 WHERE ...
MAX_EXECUTION_TIME(
N
)N
N
max_execution_time
MAX_EXECUTION_TIME
SET_VAR
SELECT /*+ SET_VAR(sort_buffer_size = 16M) */ name FROM people ORDER BY name;INSERT /*+ SET_VAR(foreign_key_checks=OFF) */ INTO t2 VALUES(2);SELECT /*+ SET_VAR(optimizer_switch = 'mrr_cost_based=off') */ 1;
SET_VAR
set_var( var_name
=value
)
var_name
value
SET_VAR
MySQL的> SELECT @@unique_checks;
----------------- | @ @独特的_ - | ----------------- | 1 | ----------------- mysql > SELECT /*+ SET_VAR(unique_checks=OFF) */ @@unique_checks;
----------------- | @ @独特的_ - | ----------------- | 0 | ----------------- mysql > SELECT @@unique_checks;
----------------- | @ @ unique_checks | ----------------- | 1 | -----------------
SET_VAR
SET @saved_val = @@session.var_name
集@ @会议 var_name
=value
;选择设置@ @会议。 var_name
= @saved_val;
SELECT /*+ SET_VAR(var_name
=value
) ...
SET
设置会话 var_name
=value
集@ @会议 var_name
=value
;设置@ @ var_name
=value
;
SET_VAR
@@session.
SET_VAR
SET_VAR
SET_VAR
MySQL的> SELECT /*+ SET_VAR(collation_server = 'utf8') */ 1;
--- | 1 | --- | 1 | --- 1行集,1报警(0秒)MySQL > SHOW WARNINGS\G
*************************** 1。行***************************水平:报警代码:4537message:变“collation_server”不能使用set_var暗示。
SET_VAR
SELECT /*+ SET_VAR(optimizer_switch = 'mrr_cost_based=off') SET_VAR(max_heap_table_size = 1G) */ 1;
SELECT /*+ SET_VAR(max_heap_table_size = 1G) SET_VAR(max_heap_table_size = 3G) */ 1;
SET_VAR
SELECT /*+ SET_VAR(max_size = 1G) */ 1;SELECT /*+ SET_VAR(optimizer_switch = 'mrr_cost_based=yes') */ 1;
max_size
on
yes
SET_VAR
SET_VAR
RESOURCE_GROUP
RESOURCE_GROUP_ADMIN
RESOURCE_GROUP_USER
SELECT /*+ RESOURCE_GROUP(USR_default) */ name FROM people ORDER BY name; INSERT /*+ RESOURCE_GROUP(Batch) */ INTO t2 VALUES(2);
RESOURCE_GROUP
resource_group( group_name
)
group_name
RESOURCE_GROUP
INSERT
UPDATE
RESOURCE_GROUP
SET RESOURCE GROUP
QB_NAME
qb_name( name
)
QB_NAME
选择从(选择…从(选择…从…))…
QB_NAME
选择/ * * / qb_name(QB1)…从(选择/ * * / qb_name(qb2)…从(选择/ * * / qb_name(QB3)…从…))…
SELECT /*+ QB_NAME(qb1) MRR(@qb1 t1) BKA(@qb2) NO_MRR(@qb3t1 idx1, id2) */ ... FROM (SELECT /*+ QB_NAME(qb2) */ ... FROM (SELECT /*+ QB_NAME(qb3) */ ... FROM ...)) ...
MRR(@qb1 t1)
qb1
BKA(@qb2)
NO_MRR(@qb3 t1 idx1, id2)
idx2
qb3
SELECT /*+ BKA(@`my hint name`) */ ... FROM (SELECT /*+ QB_NAME(`my hint name`) */ ...) ...
ANSI_QUOTES
选择/ * BKA(@”我的暗示的名字”)* /…从(选择/ * qb_name(“我的暗示的名字”)* /…)…
optimizer_switch
off
mysql> SELECT @@optimizer_switch\G
*************************** 1. row ***************************
@@optimizer_switch: index_merge=on,index_merge_union=on,
index_merge_sort_union=on,
index_merge_intersection=on,
engine_condition_pushdown=on,
index_condition_pushdown=on,
mrr=on,mrr_cost_based=on,
block_nested_loop=on,batched_key_access=off,
materialization=on,semijoin=on,loosescan=on,
firstmatch=on,duplicateweedout=on,
subquery_materialization_cost_based=on,
use_index_extensions=on,
condition_fanout_filter=on,derived_merge=on,
use_invisible_indexes=off,skip_scan=on
optimizer_switch
SET [GLOBAL|SESSION] optimizer_switch='command
【, command
]…”;
command
default | |
| |
| |
|
default
opt_name
on
opt_name
optimizer_switch
opt_name
batched_key_access
batched_key_access
mrr
mrr_cost_based
block_nested_loop
condition_fanout_filter
derived_merge
derived_merge
derived_merge
engine_condition_pushdown
index_condition_pushdown
use_index_extensions
index_merge
index_merge_intersection
index_merge_sort_union
index_merge_union
use_invisible_indexes
mrr
mrr_cost_based
mrr=on
skip_scan
semijoin
duplicateweedout
firstmatch
loosescan
GROUP
BY
semijoin
loosescan
semijoin
firstmatch
duplicateweedout
semijoin
on
materialization
subquery_materialization_cost_based
materialization
materialization
on
subquery_materialization_cost_based
EXISTS
IN
off
EXISTS
optimizer_switch
MySQL的> SELECT @@optimizer_switch\G
*************************** 1. row ***************************@@optimizer_switch: index_merge=on,index_merge_union=on, index_merge_sort_union=on, index_merge_intersection=on, engine_condition_pushdown=on, index_condition_pushdown=on, mrr=on,mrr_cost_based=on, block_nested_loop=on,batched_key_access=off, materialization=on,semijoin=on,loosescan=on, firstmatch=on, subquery_materialization_cost_based=on, use_index_extensions=on, condition_fanout_filter=on
mysql>SET optimizer_switch='index_merge_union=off,index_merge_sort_union=off';
mysql>SELECT @@optimizer_switch\G
*************************** 1. row *************************** @@optimizer_switch: index_merge=on,index_merge_union=off, index_merge_sort_union=off, index_merge_intersection=on, engine_condition_pushdown=on, index_condition_pushdown=on, mrr=on,mrr_cost_based=on, block_nested_loop=on,batched_key_access=off, materialization=on,semijoin=on,loosescan=on, firstmatch=on, subquery_materialization_cost_based=on, use_index_extensions=on, condition_fanout_filter=on
SELECT
UPDATE
SELECT
tbl_name
[[AS]alias
] [index_hint_list
]index_hint_list
:index_hint
[index_hint
] ...index_hint
: USE {INDEX|KEY} [FOR {JOIN|ORDER BY|GROUP BY}] ([index_list
]) | IGNORE {INDEX|KEY} [FOR {JOIN|ORDER BY|GROUP BY}] (index_list
) | FORCE {INDEX|KEY} [FOR {JOIN|ORDER BY|GROUP BY}] (index_list
)index_list
:index_name
[,index_name
] ...
USE INDEX
(
index_list
)index_list
EXPLAIN
FORCE INDEX
index_list
PRIMARY
SHOW
INDEX
INFORMATION_SCHEMA.STATISTICS
index_name
SELECT * FROM table1 USE INDEX (col1_index,col2_index) WHERE col1=1 AND col2=2 AND col3=3; SELECT * FROM table1 IGNORE INDEX (col3_index) WHERE col1=1 AND col2=2 AND col3=3;
index_list
index_list
IGNORE
INDEX
FOR
FOR ORDER BY
SELECT * FROM t1 USE INDEX (i1) IGNORE INDEX FOR ORDER BY (i2) ORDER BY a;
SELECT * FROM t1 USE INDEX (i1) USE INDEX (i1,i1);
USE INDEX
SELECT * FROM t1 USE INDEX FOR JOIN (i1) FORCE INDEX FOR JOIN (i2);
FOR
不知道索引(I1)
IGNORE INDEX FOR JOIN (i1) IGNORE INDEX FOR ORDER BY (i1) IGNORE INDEX FOR GROUP BY (i1)
FOR
old
USE
IGNORE
FOR ORDER BY
SELECT * FROM t1 USE INDEX () IGNORE INDEX (i2) USE INDEX (i1) USE INDEX (i2);
SELECT * FROM t1 USE INDEX (i1,i2) IGNORE INDEX (i2);
{USE|FORCE} INDEX
IGNORE INDEX
SELECT * FROM T1使用索引(I1)忽略指数(I2)利用指数(I2);选择*从T1使用索引(I1);
FULLTEXT
IGNORE INDEX(i1)
FOR
ORDER BY
FOR
JOIN
FULLTEXT
SELECT * FROM t USE INDEX (index1) IGNORE INDEX (index1) FOR ORDER BY IGNORE INDEX (index1) FOR GROUP BY WHERE ... IN BOOLEAN MODE ... ; SELECT * FROM t USE INDEX (index1) WHERE ... IN BOOLEAN MODE ... ;
server_cost
mysql
NULL
FLUSH OPTIMIZER_COSTS
NULL
FLUSH
OPTIMIZER_COSTS
mysql
server_cost
cost_name
cost_value
NULL
NULL
NULL
FLUSH
OPTIMIZER_COSTS
last_update
comment
default_value
NULL
server_cost
cost_name
disk_temptable_create_cost
InnoDB
memory_temptable_create_cost
key_compare_cost
filesort
memory_temptable_create_cost
MEMORY
disk_temptable_create_cost
row_evaluate_cost
engine_cost
engine_name
default
device_type
cost_name
server_cost
cost_value
server_cost
last_update
server_cost
comment
server_cost
default_value
NULL
default_value
engine_cost
engine_name
cost_name
io_block_read_cost
memory_block_read_cost
io_block_read_cost
io_block_read_cost
io_block_read_cost
io_block_read_cost
io_block_read_cost
UPDATE mysql.engine_cost SET cost_value = 2.0 WHERE cost_name = 'io_block_read_cost';FLUSH OPTIMIZER_COSTS;
io_block_read_cost
INSERT INTO mysql.engine_cost VALUES ('InnoDB', 0, 'io_block_read_cost', 3.0, CURRENT_TIMESTAMP, 'Using a slower disk for InnoDB'); FLUSH OPTIMIZER_COSTS;
column_statistics
ANALYZE
TABLE
column_statistics
JSON
column_statistics
INFORMATION_SCHEMA.COLUMN_STATISTICS
COLUMN_STATISTICS
SCHEMA_NAME
COLUMN_NAME
HISTOGRAM
JSON
JSON
{“桶”:[ [ 1,0.3333333333333333 ],[ 2,0.6666666666666666 ],[ 3,1 ] ],“空值”:0,“最近更新”:“2017-03-24 13:32:40. 000000”、“采样率”:1、“直方图”型:“独生子女”、“斗指定”编号:128,“数据类型”:“int”、“整理ID”:8 }
buckets
singleton
equi-height
null-values
NULL
last-updated
YYYY-MM-DD
HH:MM:SS.hhmmss
sampling-rate
histogram-type
singleton
ANALYZE TABLE
equi-height
ANALYZE TABLE
number-of-buckets-specified
ANALYZE
TABLE
data-type
uint
decimal
string
collation-id
string
INFORMATION_SCHEMA.COLLATIONS
JSON
MySQL的> SELECT
TABLE_NAME, COLUMN_NAME,
HISTOGRAM->>'$."data-type"' AS 'data-type',
JSON_LENGTH(HISTOGRAM->>'$."buckets"') AS 'bucket-count'
FROM INFORMATION_SCHEMA.COLUMN_STATISTICS;
----------------- ------------- ----------- -------------- | table_name | column_name |数据类型|桶数| ----------------- ------------- ----------- -------------- |国|人口| int | 226 | |市|人口| int | 1024 | | countrylanguage |语言|字符串| 457 | ----------------- ------------- ----------- --------------
col_name
=constant
col_name
<>constant
col_name
!=constant
col_name
>constant
col_name
<constant
col_name
>=constant
col_name
<=constant
col_name
IS NULLcol_name
IS NOT NULLcol_name
BETWEENconstant
ANDconstant
col_name
NOT BETWEENconstant
ANDconstant
col_name
IN (constant
[,constant
] ...)col_name
NOT IN (constant
[,constant
] ...)
SELECT * FROM orders WHERE amount BETWEEN 100.0 AND 300.0; SELECT * FROM tbl WHERE col1 = 15 AND col2 > 100;
ABS()
FLOOR()
SELECT * FROM tbl WHERE col1 < ABS(-34);
ANALYZE
TABLE
ANALYZE TABLE
optimizer_switch
SET optimizer_switch='condition_fanout_filter=off';
EXPLAIN
SELECT * FROM t1 WHERE col1 < 24;
t1
col1 < 24
EXPLAIN
InnoDB
InnoDB
InnoDB
InnoDB
MyISAM
MyISAM
key_buffer_size
key_buffer_size
MyISAM
InnoDB
MyISAM
CACHE INDEX
t1
t3
mysql> CACHE INDEX t1, t2, t3 IN hot_cache;
+---------+--------------------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+---------+--------------------+----------+----------+
| test.t1 | assign_to_keycache | status | OK |
| test.t2 | assign_to_keycache | status | OK |
| test.t3 | assign_to_keycache | status | OK |
+---------+--------------------+----------+----------+
CACHE
INDEX
SET
GLOBAL
MySQL的> SET GLOBAL keycache1.key_buffer_size=128*1024;
mysql> SET GLOBAL keycache1.key_buffer_size=0;
mysql>SET GLOBAL key_buffer_size = 0;
mysql>SHOW VARIABLES LIKE 'key_buffer_size';
+-----------------+---------+ | Variable_name | Value | +-----------------+---------+ | key_buffer_size | 8384512 | +-----------------+---------+
keycache1.key_buffer_size
key_buffer_size
CACHE INDEX
CACHE INDEX
key_buffer_size = 4Ghot_cache.key_buffer_size = 2Gcold_cache.key_buffer_size = 2Ginit_file=/path
/ to
/ data-directory
/ mysqld_init.sql
mysqld_init.sql
cold_cache
db1.t1索引缓存,在缓存缓存db1.t2,db2.t3 _指数db1.t4 db2.t5热,冷,db2.t6 _缓存
key_cache_division_limit
key_cache_division_limit
key_cache_age_threshold
N
N
key_cache_division_limit
key_cache_division_limit
LOAD INDEX INTO
CACHE
t2
MySQL的> LOAD INDEX INTO CACHE t1, t2 IGNORE LEAVES;
--------- -------------- ---------- ---------- |表| OP | msg_type | msg_text | --------- -------------- ---------- ---------- | test.t1 | preload_keys |状态|好| | test.t2 | preload_keys |状态|好| --------- -------------- ---------- ----------
IGNORE LEAVES
t2
CACHE INDEX
key_cache_block_size
.MYI
--myisam-block-size
mysql> SET GLOBAL cold_cache.key_buffer_size=4*1024*1024;
key_buffer_size
key_cache_block_size
PREPARE
mysql_stmt_prepare()
max_prepared_stmt_count
stored_program_cache
INSERT
UPDATE
SELECT
PREPARE s1 FROM 'SELECT * FROM t1';
SELECT *
s1
FLUSH
TABLES
DECLARE CURSOR
IF
CASE
RETURN
SELECT *
CASE
案例 case_expr
什么时候 when_expr1
…什么时候 when_expr2
…什么时候 when_expr3
…最后的案例…
WHEN
when_expr3
case_expr
Com_stmt_reprepare
MyISAM
InnoDB
InnoDB
InnoDB
innodb_lock_wait_timeout
innodb_deadlock_detect
MyISAM
MERGE
GROUP BY
SELECT
SELECT
Table_locks_immediate
Table_locks_waited
MySQL的> SHOW STATUS LIKE 'Table%';
----------------------- --------- | variable_name |价值| ----------------------- --------- | table_locks_immediate | 1151552 | | table_locks_waited | 15324 | ----------------------- ---------
MyISAM
INSERT
SELECT
MyISAM
concurrent_insert
LOCK TABLES
READ
INSERT
SELECT
temp_t1
MySQL的> LOCK TABLES t1 WRITE, temp_t1 WRITE;
MySQL的> INSERT INTO t1 SELECT * FROM temp_t1;
MySQL的> DELETE FROM temp_t1;
MySQL的> UNLOCK TABLES;
GET_LOCK()
RELEASE_LOCK()
InnoDB
LOCK TABLES
InnoDB
InnoDB
InnoDB
CREATE TABLE ... ENGINE=INNODB
ALTER TABLE ...
ENGINE=INNODB
SELECT
--low-priority-updates
MEMORY
SELECT
SELECT
UPDATE
SELECT
low_priority_updates
SELECT
max_write_lock_count
SELECT
WRITE
INSERT
SELECT
SELECT
INSERT
SELECT
DELETE
DELETE
SQL_BUFFER_RESULT
SELECT
mysys/thr_lock.c
MyISAM
INSERT
SELECT
INSERT
SELECT
INSERT
concurrent_insert
concurrent_insert
ALWAYS
concurrent_insert
CREATE ...
SELECT
INSERT ...
SELECT
LOAD DATA
INFILE
MyISAM
LOAD DATA
LOAD
DATA
HIGH_PRIORITY
--low-priority-updates
LOCK
TABLE
READ
INSERT
LOCK_open
t
START TRANSACTION; SELECT * FROM t; SELECT * FROM nt;
t
DROP TABLE t; ALTER TABLE t ...; DROP TABLE nt; ALTER TABLE nt ...; LOCK TABLE t ... WRITE;
LOCK TABLES ...
READ
PREPARE
PREPARED
XA COMMIT
XA RECOVER
MyISAM
MyISAM
MyISAM
CHECK TABLE
REPAIR TABLE
MyISAM
skip_external_locking
--external-locking
--skip-external-locking
MyISAM
--delay-key-write=ALL
DELAY_KEY_WRITE=1
--external-locking
--delay-key-write=OFF
InnoDB
MyISAM
InnoDB
N
N
number_of_disks
N
N
N
N
-o noatime
-o
async
hard
InnoDB
CREATE
TABLE
MyISAM
SHOW VARIABLES LIKE 'datadir';
shell>mkdir /dr1/databases/test
shell>ln -s /dr1/databases/test
/path/to/datadir
db1
db1
内核> cd
/path/to/datadir
内核> ln -s db1 db2
tbl_a
tbl_a
db1.tbl_a
--symbolic-links
MyISAM
realpath()
have_symlink
显示变量的have_symlink”;
MyISAM
.MYD
DATA DIRECTORY
CREATE TABLE
DATA
DIRECTORY
data
ALTER TABLE
OPTIMIZE TABLE
REPAIR TABLE
root
ALTER TABLE
... RENAME
RENAME
TABLE
ALTER TABLE
... RENAME
RENAME
TABLE
--skip-symbolic-links
ALTER TABLE
INDEX
DIRECTORY
mydb
D:\data\mydb
mydb
C:\> cd \path\to\datadir
mydb
C:\ > mklink /d mydb D:\data\mydb
mydb
InnoDB
InnoDB
innodb_buffer_pool_size
innodb_buffer_pool_size
innodb_buffer_pool_size
innodb_buffer_pool_instances
InnoDB
MyISAM
key_buffer_size
MyISAM
N
N
BLOB
BLOB
BLOB
myisam_use_mmap
tmp_table_size
max_heap_table_size
internal_tmp_disk_storage_engine
MEMORY
CREATE TABLE
max_heap_table_size
thread_stack
net_buffer_length
net_buffer_length
net_buffer_length
max_allowed_packet
net_buffer_length
max_digest_length
read_buffer_size
read_rnd_buffer_size
BLOB
table_open_cache
table_definition_cache
FLUSH TABLES
FLUSH TABLES
GRANT
CREATE USER
CREATE SERVER
INSTALL PLUGIN
REVOKE
DROP USER
DROP SERVER
UNINSTALL PLUGIN
FLUSH PRIVILEGES
max_allowed_packet
slave_pending_jobs_size_max
rpl_read_size
binlog_transaction_dependency_history_size
max_binlog_cache_size
max_binlog_stmt_cache_size
swap -s
ENABLED
setup_instruments
code_area
instrument_name
code_area
innodb
instrument_name
setup_instruments
MySQL的> SELECT * FROM performance_schema.setup_instruments
WHERE NAME LIKE '%memory%';
InnoDB
mysql>SELECT * FROM performance_schema.setup_instruments
WHERE NAME LIKE '%memory/innodb%';
+-------------------------------------------+---------+-------+ | NAME | ENABLED | TIMED | +-------------------------------------------+---------+-------+ | memory/innodb/adaptive hash index | NO | NO | | memory/innodb/buf_buf_pool | NO | NO | | memory/innodb/dict_stats_bg_recalc_pool_t | NO | NO | | memory/innodb/dict_stats_index_map_t | NO | NO | | memory/innodb/dict_stats_n_diff_on_level | NO | NO | | memory/innodb/other | NO | NO | | memory/innodb/row_log_buf | NO | NO | | memory/innodb/row_merge_sort | NO | NO | | memory/innodb/std | NO | NO | | memory/innodb/trx_sys_t::rw_trx_ids | NO | NO | ...
performance_schema
client
myisam
memory
archive
performance-schema-instrument
performance-schema-instrument='memory/%=COUNTED'
ENABLED
setup_instruments
TIMED
setup_instruments
MySQL的> SELECT * FROM performance_schema.setup_instruments
WHERE NAME LIKE '%memory/innodb%';
------------------------------------------- --------- ------- |名字|启用|定时| ------------------------------------------- --------- ------- |记忆/会/自适应哈希索引|没有|没有| |记忆/ InnoDB / buf_buf_pool |没有|没有| |记忆/ InnoDB / dict_stats_bg_recalc_pool_t |没有|没有| |记忆/ InnoDB / dict_stats_index_map_t |没有|没有| |记忆/会/ dict_stats_n_diff_on_level |没有|没有| |记忆/会/其他|没有|没有| |记忆/ InnoDB / row_log_buf |没有|没有| |记忆/ InnoDB / row_merge_sort |没有|没有| |记忆/会/性病|没有|没有| |记忆/会/ trx_sys_t::rw_trx_ids |没有|没有|…
memory_summary_global_by_event_name
EVENT_NAME
InnoDB
mysql>SELECT * FROM performance_schema.memory_summary_global_by_event_name
WHERE EVENT_NAME LIKE 'memory/innodb/buf_buf_pool'\G
EVENT_NAME: memory/innodb/buf_buf_pool COUNT_ALLOC: 1 COUNT_FREE: 0 SUM_NUMBER_OF_BYTES_ALLOC: 137428992 SUM_NUMBER_OF_BYTES_FREE: 0 LOW_COUNT_USED: 0 CURRENT_COUNT_USED: 1 HIGH_COUNT_USED: 1 LOW_NUMBER_OF_BYTES_USED: 0 CURRENT_NUMBER_OF_BYTES_USED: 137428992 HIGH_NUMBER_OF_BYTES_USED: 137428992
sys
memory_global_by_current_bytes
MySQL的> SELECT * FROM sys.memory_global_by_current_bytes
WHERE event_name LIKE 'memory/innodb/buf_buf_pool'\G
*************************** 1。行*************************** event_name:记忆/会/ buf_buf_pool current_count:1 current_alloc:131.06 mibcurrent_avg_alloc:131.06 MIB high_count:1 high_alloc:131.06 MIB high_avg_alloc:131.06 MIB
sys
mysql>SELECT SUBSTRING_INDEX(event_name,'/',2) AS
code_area, sys.format_bytes(SUM(current_alloc))
AS current_alloc
FROM sys.x$memory_global_by_current_bytes
GROUP BY SUBSTRING_INDEX(event_name,'/',2)
ORDER BY SUM(current_alloc) DESC;
+---------------------------+---------------+ | code_area | current_alloc | +---------------------------+---------------+ | memory/innodb | 843.24 MiB | | memory/performance_schema | 81.29 MiB | | memory/mysys | 8.20 MiB | | memory/sql | 2.47 MiB | | memory/memory | 174.01 KiB | | memory/myisam | 46.53 KiB | | memory/blackhole | 512 bytes | | memory/federated | 512 bytes | | memory/csv | 512 bytes | | memory/vio | 496 bytes | +---------------------------+---------------+
sys
--super-large-pages
--skip-super-large-pages
Documentation/vm/hugetlbpage.txt
shell> cat /proc/meminfo | grep -i huge
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 4096 kB
hugetlbpage.txt
rc
# Set the number of pages to be used.# Each page is normally 2MB, so a value of 20 = 40MB.# This command actually allocates memory, so this much# memory must be available.echo 20 > /proc/sys/vm/nr_hugepages# Set the group number that is permitted to access this# memory (102 in this case). The mysql user must be a# member of this group.echo 102 > /proc/sys/vm/hugetlb_shm_group# Increase the amount of shmem permitted per segment# (12G in this case).echo 1560281088 > /proc/sys/kernel/shmmax# Increase total amount of shared memory. The value# is the number of pages. At 4KB/page, 4194304 = 16GB.echo 4194304 > /proc/sys/kernel/shmall
shmmax
/proc/meminfo
内核> cat /proc/meminfo | grep -i huge
hugepages_total:20hugepages_free:20hugepages_rsvd:0hugepages_surp:0hugepagesize:4096 KB
hugetlb_shm_group
/etc/security/limits.conf
ulimit -l unlimited
root
mysql
root
--large-pages
[mysqld] large-pages
InnoDB
/proc/meminfo
内核> cat /proc/meminfo | grep -i huge
hugepages_total:20hugepages_free:20hugepages_rsvd:2hugepages_surp:0hugepagesize:4096 KB
thread_cache_size
thread_cache_size
N
N
thread_cache_size
Threads_cached
Threads_created
max_connections
N
--thread_stack=
N
host_cache
SELECT
max_connect_errors
127.0.0.1
NULL
NULL
gethostbyaddr()
FLUSH HOSTS
FLUSH HOSTS
host_cache_size
--skip-name-resolve
--skip-name-resolve
host_cache_size
--skip-networking
Connection_errors_
xxx
Batch
INFORMATION_SCHEMA.RESOURCE_GROUPS
threads
SYSTEM
threads
SYS_default
SYS_default
RESOURCE_GROUP_ADMIN
RESOURCE_GROUP
RESOURCE_GROUP_ADMIN
RESOURCE_GROUP_USER
resource_groups
INFORMATION_SCHEMA.RESOURCE_GROUPS
RESOURCE_GROUPS
MySQL的> SELECT * FROM INFORMATION_SCHEMA.RESOURCE_GROUPS\G
*************************** 1。行*************************** resource_group_name:usr_default resource_group_type:userresource_group_enabled:1 vcpu_ids:0-3 thread_priority:0 *************************** 2。行*************************** resource_group_name:sys_default resource_group_type:systemresource_group_enabled:1 vcpu_ids:0-3 thread_priority:0
THREAD_PRIORITY
Batch
CREATE RESOURCE GROUP Batch TYPE = USER VCPU = 2-3 -- assumes a system with at least 4 CPUs THREAD_PRIORITY = 10;
RESOURCE_GROUPS
MySQL的> SELECT * FROM INFORMATION_SCHEMA.RESOURCE_GROUPS
WHERE RESOURCE_GROUP_NAME = 'Batch'\G
*************************** 1。行*************************** resource_group_name:批resource_group_type:userresource_group_enabled:1 vcpu_ids:2-3 thread_priority:10
THREAD_PRIORITY
Batch
设置资源组批 thread_id
;
Batch
Batch
设置资源组批;
Batch
Batch
INSERT /*+ RESOURCE_GROUP(Batch) */ INTO t2 VALUES(2);
Batch
ALTER RESOURCE GROUP Batch VCPU = 3 THREAD_PRIORITY = 19;
ALTER RESOURCE GROUP Batch VCPU = 0-3 THREAD_PRIORITY = 0;
mysql>ALTER RESOURCE GROUP abc THREAD_PRIORITY = 10;
Query OK, 0 rows affected, 1 warning (0.18 sec) mysql>SHOW WARNINGS;
+---------+------+-------------------------------------------------------------+ | Level | Code | Message | +---------+------+-------------------------------------------------------------+ | Warning | 4560 | Attribute thread_priority is ignored (using default value). | +---------+------+-------------------------------------------------------------+
CAP_SYS_NICE
CAP_SYS_NICE
shell>sudo setcap cap_sys_nice+ep ./bin/mysqld
shell>getcap ./bin/mysqld
./bin/mysqld = cap_sys_nice+ep
THREAD_PRIORITY_HIGHEST | |
THREAD_PRIORITY_ABOVE_NORMAL | |
THREAD_PRIORITY_NORMAL | |
THREAD_PRIORITY_BELOW_NORMAL | |
THREAD_PRIORITY_LOWEST |
InnoDB
BENCHMARK()
BENCHMARK(
loop_count
,expression
)
mysql> SELECT BENCHMARK(1000000,1+1);
+------------------------+
| BENCHMARK(1000000,1+1) |
+------------------------+
| 0 |
+------------------------+
1 row in set (0.32 sec)
BENCHMARK()
performance_schema
SHOW [FULL] PROCESSLIST
INFORMATION_SCHEMA
PROCESSLIST
threads
threads
INFORMATION_SCHEMA.PROCESSLIST
SHOW PROCESSLIST
threads
INFORMATION_SCHEMA.PROCESSLIST
SHOW PROCESSLIST
threads
PROCESS
Id
User
db
Command
Time
SET
TIMESTAMP =
value
Info
SHOW FULL
PROCESSLIST
sys
processlist
threads
sys
session
processlist
Command
Command
State
MyISAM
ANALYZE TABLE
MEMORY
ALTER
TABLE
ORDER BY
ALTER TABLE
ALTER TABLE ... ENABLE
KEYS
SELECT
Copying to tmp table on
disk
committing alter table to storage engine
ALTER TABLE
deleting from reference tables
ALTER TABLE ... DISCARD
TABLESPACE
ALTER TABLE
CREATE VIEW
DELETE
INSERT
SELECT
UPDATE
init_command
cleaning up
ALTER TABLE
DELETE
INSERT
SELECT
UPDATE
end
KILL
SHOW
PROCESSLIST
ALTER TABLE
LOCK
TABLE
table_open_cache
Opening system
tables
freeing items
SELECT
DISTINCT
SELECT
ALTER
TABLE
ALTER TABLE
MyISAM
Repair by
sorting
MyISAM
AUTO_INCREMENT
UPDATE
Sending data
SELECT
ALTER
TABLE
GROUP
BY
ORDER
BY
MyISAM
SELECT
mysql_lock_tables()
InnoDB
LOCK TABLES
MyISAM
--skip-external-locking
SHOW PROFILE
Locking system
tables
GET_LOCK()
SHOW PROFILE
SLEEP()
FLUSH TABLES WITH READ LOCK
FLUSH TABLES WITH READ LOCK
read_only
FLUSH TABLES
tbl_name
ALTER TABLE
RENAME TABLE
REPAIR TABLE
ANALYZE TABLE
OPTIMIZE TABLE
FLUSH
TABLES
FLUSH TABLES
tbl_name
ALTER TABLE
RENAME TABLE
REPAIR TABLE
ANALYZE TABLE
OPTIMIZE TABLE
THR_LOCK
lock_type
THR_LOCK
Waiting for table level lock
Waiting for event metadata lock
Waiting for global read lock
Waiting for schema metadata lock
Waiting for stored function metadata
lock
Waiting for stored procedure metadata
lock
Waiting for table metadata lock
Waiting for trigger metadata lock
State
Binlog Dump
Finished reading one binlog; switching to next
binlog
Master has sent all binlog to slave; waiting for
more updates
Waiting to finalize termination
State
SHOW SLAVE
STATUS
Queueing master event to the relay log
Reconnecting after a failed binlog dump
request
Reconnecting after a failed master event
read
Waiting for master to send event
Waiting for its turn to commit
slave_preserve_commit_order
Waiting for master to send event
slave_net_timeout
Connecting to
master
Waiting for slave mutex on exit
Waiting for the slave SQL thread to free enough
relay log space
relay_log_space_limit
Waiting to reconnect after a failed binlog dump
request
CHANGE MASTER TO
Waiting to reconnect after a failed master event
read
CHANGE MASTER TO
State
STOP SLAVE
Making temporary file (append) before replaying
LOAD DATA INFILE
LOAD DATA
INFILE
Making temporary file (create) before replaying
LOAD DATA INFILE
LOAD DATA
INFILE
LOAD DATA
INFILE
Reading event from the relay log
Slave has read all relay log; waiting for more
updates
Waiting for an event from Coordinator
slave_parallel_workers
Waiting for slave mutex on exit
Waiting for Slave Workers to free pending
events
slave_pending_jobs_size_max
slave_parallel_workers
Waiting for the next event in relay log
Reading event from the
relay log
Waiting until MASTER_DELAY seconds after master
executed event
MASTER_DELAY
CHANGE MASTER TO
Info
CHANGE
MASTER TO
STOP SLAVE
Creating table from master
dump
Reading master dump table data
Opening master dump
table
Rebuilding the index on master dump table
Reading master dump table
data