옵티마이저가 수립한 실행 계획을 확인할 수 있는 명령어 : EXPLAIN
explain format=json select * from lesson as l
inner join lesson_member_conn as lmc on l.id = lmc.lesson_id
inner join member as m on lmc.member_id = m.id
where m.id = 1;
{
"query_block": {
"select_id": 1,
"cost_info": {
"query_cost": "0.70"
},
"nested_loop": [
{
"table": {
"table_name": "m",
"access_type": "const",
"possible_keys": [
"PRIMARY"
],
"key": "PRIMARY",
"used_key_parts": [
"id"
],
"key_length": "8",
"ref": [
"const"
],
"rows_examined_per_scan": 1,
"rows_produced_per_join": 1,
"filtered": "100.00",
"cost_info": {
"read_cost": "0.00",
"eval_cost": "0.10",
"prefix_cost": "0.00",
"data_read_per_join": "800"
},
"used_columns": [
"id",
"age",
"name",
"create_time",
"update_date"
]
}
},
{
"table": {
"table_name": "lmc",
"access_type": "ALL",
"rows_examined_per_scan": 1,
"rows_produced_per_join": 1,
"filtered": "100.00",
"cost_info": {
"read_cost": "0.25",
"eval_cost": "0.10",
"prefix_cost": "0.35",
"data_read_per_join": "48"
},
"used_columns": [
"id",
"last_updated_attendance",
"last_updated_payment",
"lesson_id",
"member_id",
"create_time",
"update_date"
],
"attached_condition": "((`aom`.`lmc`.`member_id` = 1) and (`aom`.`lmc`.`lesson_id` is not null))"
}
},
{
"table": {
"table_name": "l",
"access_type": "eq_ref",
"possible_keys": [
"PRIMARY"
],
"key": "PRIMARY",
"used_key_parts": [
"id"
],
"key_length": "8",
"ref": [
"aom.lmc.lesson_id"
],
"rows_examined_per_scan": 1,
"rows_produced_per_join": 1,
"filtered": "100.00",
"cost_info": {
"read_cost": "0.25",
"eval_cost": "0.10",
"prefix_cost": "0.70",
"data_read_per_join": "3K"
},
"used_columns": [
"id",
"name",
"day",
"date",
"month",
"start_time",
"end_time",
"year",
"time",
"create_time",
"update_date"
]
}
}
]
}
}
-> Nested loop inner join (cost=0.70 rows=1) (actual time=0.049..0.064 rows=2 loops=1)
-> Filter: ((lmc.member_id = 1) and (lmc.lesson_id is not null)) (cost=0.35 rows=1) (actual time=0.024..0.036 rows=2 loops=1)
-> Table scan on lmc (cost=0.35 rows=1) (actual time=0.021..0.031 rows=2 loops=1)
-> Single-row index lookup on l using PRIMARY (id=lmc.lesson_id) (cost=0.35 rows=1) (actual time=0.012..0.012 rows=1 loops=2)
8.0.18 버전부터는 쿼리의 실행 계획과 단계별 소요된 시간 정보를 확인할 수 있다.