当前位置:网站首页>JSON format execution plan (6) - MySQL execution plan (52)
JSON format execution plan (6) - MySQL execution plan (52)
2022-07-26 13:07:00 【User 9919783】
We said that before extra, This mainly shows additional information , For example, if you don't fill in the form , Will be displayed no table, The index will show using index, Full table scanning or back table , Is displayed using where, If mysql Optimizer to internal query , It will also show the strategy of internal query selection , For example, internal connection temporary table to duplicate value query , For example, loose query , For example, the most principled method , Circular query .
Extra(5)—mysql Implementation plan ( Fifty-one )
If we were explain Add a format=JSON What will happen ? At this time, we can get json data ,
mysql> EXPLAIN FORMAT=JSON SELECT * FROM s1 INNER JOIN s2 ON s1.key1 = s2.key2 WHERE s1.common_field = 'a'\G
*************************** 1. row ***************************
EXPLAIN: {
"query_block": {
"select_id": 1, # Whole select only one id It means
"cost_info": {
"query_cost": "3197.16" # The whole inquiry cost is estimated to be 3197.16
},
"nested_loop": [ # Nested loop join queries are used between several tables
# The following is information about the tables involved in the nested loop join algorithm
{
"table": {
"table_name": "s1", # s1 A table is a driver table
"access_type": "ALL", # The access method is ALL, It means using a full table scan to access
"possible_keys": [ # Possible indexes
"idx_key1"
],
"rows_examined_per_scan": 9688, # Check once s1 The table needs to be scanned roughly 9688 Bar record
"rows_produced_per_join": 968, # The driver table s1 The fan out is 968
"filtered": "10.00", # condition filtering Represents the percentage of
"cost_info": {
"read_cost": "1840.84", # Explain later
"eval_cost": "193.76", # Explain later
"prefix_cost": "2034.60", # Single query s1 The total cost of the table
"data_read_per_join": "1M" # Amount of data read
},
"used_columns": [ # Execute the columns involved in the query
"id",
"key1",
"key2",
"key3",
"key_part1",
"key_part2",
"key_part3",
"common_field"
],
# Yes s1 Table access conditions for single table queries
"attached_condition": "((`xiaohaizi`.`s1`.`common_field` = 'a') and (`xiaohaizi`.`s1`.`key1` is not null))"
}
},
{
"table": {
"table_name": "s2", # s2 A table is a driven table
"access_type": "ref", # The access method is ref, It means using index equivalent matching
"possible_keys": [ # Possible indexes
"idx_key2"
],
"key": "idx_key2", # Actual index used
"used_key_parts": [ # Index column used
"key2"
],
"key_length": "5", # key_len
"ref": [ # And key2 Column the objects to be equivalently matched
"xiaohaizi.s1.key1"
],
"rows_examined_per_scan": 1, # Check once s2 The table needs to be scanned roughly 1 Bar record
"rows_produced_per_join": 968, # Was the driver table s2 The fan out is 968( Because there is no extra table to join , So this value doesn't work )
"filtered": "100.00", # condition filtering Represents the percentage of
# s2 Table search criteria for queries using indexes
"index_condition": "(`xiaohaizi`.`s1`.`key1` = `xiaohaizi`.`s2`.`key2`)",
"cost_info": {
"read_cost": "968.80", # Explain later
"eval_cost": "193.76", # Explain later
"prefix_cost": "3197.16", # Word query s1, Multiple queries s2 Total cost
"data_read_per_join": "1M" # Amount of data read
},
"used_columns": [ # Execute the columns involved in the query
"id",
"key1",
"key2",
"key3",
"key_part1",
"key_part2",
"key_part3",
"common_field"
]
}
}
]
}
}
1 row in set, 2 warnings (0.00 sec)Let's take a look at the driver table first S1 Of cost_info
Inside read_cost It's made up of two parts
1、 yes I/O cost
2、 testing rows * (1 - filter) Record cost of article (rows It is the output column of our previous execution plan ,rows stay json What the data shows is rows_examined_per_scan,filtered unchanged )
eval_cost: testing rows * filter Cost records .
prefix_cost It's a separate query s1 Cost of tables : read_cost + eval_cost.
data_read_per_join It represents the number of reads .
S2 Of cost_info Actually sum s1 almost , But because the driven table has the opportunity to be accessed many times , therefore read_cost and eval_cost It is accumulated by multiple visits , and prefix_cost yes s1 The cost and s2 The total cost of .
Extented Explain
in addition , When we run out explain after , And then you can use show warnings You can also see some extended information .
mysql> EXPLAIN SELECT s1.key1, s2.key1 FROM s1 LEFT JOIN s2 ON s1.key1 = s2.key1 WHERE s2.common_field IS NOT NULL;
+----+-------------+-------+------------+------+---------------+----------+---------+-------------------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+----------+---------+-------------------+------+----------+-------------+
| 1 | SIMPLE | s2 | NULL | ALL | idx_key1 | NULL | NULL | NULL | 9954 | 90.00 | Using where |
| 1 | SIMPLE | s1 | NULL | ref | idx_key1 | idx_key1 | 303 | xiaohaizi.s2.key1 | 1 | 100.00 | Using index |
+----+-------------+-------+------------+------+---------------+----------+---------+-------------------+------+----------+-------------+
2 rows in set, 1 warning (0.00 sec)
mysql> SHOW WARNINGS\G
*************************** 1. row ***************************
Level: Note
Code: 1003
Message: /* select#1 */ select `xiaohaizi`.`s1`.`key1` AS `key1`,`xiaohaizi`.`s2`.`key1` AS `key1` from `xiaohaizi`.`s1` join `xiaohaizi`.`s2` where ((`xiaohaizi`.`s1`.`key1` = `xiaohaizi`.`s2`.`key1`) and (`xiaohaizi`.`s2`.`common_field` is not null))
1 row in set (0.00 sec)There are three fields ,level,code,message
code by 1003 when ,message Express sql Optimized statement , such as in Turn into half connection , Turn left connection into inner connection, etc .( Be careful , here message Just for reference , You can't run it directly )
边栏推荐
- About the copy of picture address links
- Create EOS account action
- [typescript] typescript common types (Part 2)
- A super easy-to-use artifact apifox, throw swagger a few streets... (glory Collection Edition)
- Display inline+calc realizes left, middle and right layout, and the middle is adaptive
- Kubernetes----Kubernetes常用插件简介
- LCD notes (7) LCD driver framework_ Configure clock
- B+树(4)联合索引 --mysql从入门到精通(十六)
- [applet] why can't the onreachbottom event be triggered? (one second)
- 基于BERT的情感分析模型
猜你喜欢

基于Bézier曲线的三维造型与渲染

【5G】5G中的CU和DU是什么?

Kubernetes - Introduction to PV and PVC of advanced storage

Food safety | are sterile eggs really completely sterile?

基于WebRTC和WebSocket实现的聊天系统

Elementary notes of binary tree

PXE principle and configuration

Code error reporting and problem solving experience II: test error reporting in yolov5

C#把Type当做泛型T,来作为方法的泛型进行使用

食品安全 | 微波炉什么食品都能加热?这些安全隐患要知道
随机推荐
How to remove underline and color when there is focus in the shutter textfield
父组件访问子组件的方法或参数 (子组件暴漏出方法defineExpose)
Redisson distributed lock usage example (I)
Display inline+calc realizes left, middle and right layout, and the middle is adaptive
基于C#开放式TCP通信建立与西门子PLC的socket通信示例
B+树(4)联合索引 --mysql从入门到精通(十六)
C regards type as generic type T and uses it as generic type of method
Guys, how can CDC Oracle set the reading from the specified SCN number, or how to set the read-only full archive, not to read fast
今日睡眠质量记录75分
最好的工程师,就是这样被你“逼”走的!
New function | intelligent open search online customized word weight model
The best engineer was "forced" away by you like this!
Reflection, an implementation of automatic repeated call interface
【TypeScript】TypeScript常用类型(下篇)
如何面对科技性失业?
Kubernetes -- Introduction to common plug-ins of kubernetes
PostgreSQL official website download error
Shell variables and references
Kubelet CRI container runtime
MySQL data directory (2) -- table data structure (XXV)