当前位置:网站首页>A strange execution plan. One table in the association query is not associated with any other tables
A strange execution plan. One table in the association query is not associated with any other tables
2022-06-28 09:13:00 【Fisherman database notes】
1. Database version :
8.0.13
2. Problem finding
Monitoring found that a concurrent query caused the database to cpu High utilization rate , I found the sql See if there is room for optimization , But after looking at the implementation plan , It's strange to find this implementation plan , Let's send it to you for a look .
We found that the execution plan shows that we visited first g surface , Then I visited a surface , The problem is g Table and a stay sql There is no associated field in , that g How does the table match a Table Association ?
Execution plan common version :
# The table name is desensitized
mysql> explain SELECT any_value(b.id) AS id, b.sub_order_no, any_value(b.order_no) AS order_no
-> , any_value(b.status) AS status, any_value(b.c_m_mount) AS c_m_mount
-> , any_value(b.c_delivery_m_fee) AS c_delivery_m_fee, any_value(b.c_i_mount) AS c_i_mount
-> , any_value(b.c_delivery_i_fee) AS c_delivery_i_fee, any_value(c.publish_id) AS publish_id
-> , any_value(c.publish_version_id) AS publish_version_id, any_value(c.product_version_id) AS product_version_id
-> , any_value(c.sku_id) AS sku_id, any_value(c.num) AS num
-> , any_value(d.delivery_no) AS delivery_no, any_value(d.delivery_status) AS delivery_status
-> , any_value(d.delivery_code) AS delivery_code, any_value(d.delivery_com) AS delivery_com
-> , any_value(h.pay_type) AS pay_type, any_value(h.pay_channel) AS pay_channel
-> , any_value(g.shop_no) AS shop_no, any_value(a.create_time) AS create_time
-> , any_value(t.id) AS user_id, any_value(e.imp_price) AS imp_price
-> , any_value(a.address) AS address, any_value(a.tmp_order_no) AS tmp_order_no
-> , any_value(g.shop_type) AS shop_type, any_value(t.usertype) AS source
-> , any_value(f.pd_type) AS pd_type, any_value(e.cost_price) AS cost_price
-> , any_value(e.market_price) AS market_price, any_value(f.source) AS product_source
-> FROM test_od_suborder b
-> LEFT JOIN test_od_order a ON a.order_no = b.order_no
-> LEFT JOIN test_od_order_detail c ON b.sub_order_no = c.sub_order_no
-> LEFT JOIN test_od_delivery d ON d.sub_order_no = b.sub_order_no
-> LEFT JOIN test_pd_product_standard e ON e.id = c.sku_id
-> LEFT JOIN test_pd_product f ON f.product_no = e.product_no
-> LEFT JOIN test_pd_shop g ON f.shop_no = g.shop_no
-> LEFT JOIN m_ac_pay h
-> ON h.order_no = b.order_no
-> AND h.direction = '01'
-> LEFT JOIN b_channel_user t ON ac_userid = a.user_id
-> WHERE a.is_delete = '0'
-> AND g.shop_no = 'xxxxxxx'
-> AND b.status IN ('1', '2', '3')
-> GROUP BY b.sub_order_no
-> ORDER BY any_value(a.create_time) DESC
-> LIMIT 10;
+----+-------------+-------+------------+--------+----------------------------------------------------+--------------------+---------+------------------------+-------+----------+---------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+--------+----------------------------------------------------+--------------------+---------+------------------------+-------+----------+---------------------------------+
| 1 | SIMPLE | g | NULL | const | PRIMARY | PRIMARY | 130 | const | 1 | 100.00 | Using temporary; Using filesort |
| 1 | SIMPLE | a | NULL | ALL | PRIMARY | NULL | NULL | NULL | 82171 | 10.00 | Using where |
| 1 | SIMPLE | b | NULL | ref | sub_order_no,idx_status_orderno,idx_orderno_status | idx_orderno_status | 163 | fd_mall.a.order_no | 1 | 96.17 | Using index condition |
| 1 | SIMPLE | c | NULL | ref | sub_order_no | sub_order_no | 163 | fd_mall.b.sub_order_no | 1 | 100.00 | NULL |
| 1 | SIMPLE | e | NULL | eq_ref | PRIMARY,product_no | PRIMARY | 130 | fd_mall.c.sku_id | 1 | 100.00 | Using where |
| 1 | SIMPLE | f | NULL | eq_ref | PRIMARY,shop_no | PRIMARY | 202 | fd_mall.e.product_no | 1 | 5.00 | Using where |
| 1 | SIMPLE | h | NULL | ref | order_no,idx_orderno_amount_paychannel | order_no | 163 | fd_mall.b.order_no | 1 | 100.00 | Using where |
| 1 | SIMPLE | t | NULL | ref | ac_userid | ac_userid | 163 | fd_mall.a.user_id | 1 | 100.00 | NULL |
| 1 | SIMPLE | d | NULL | ref | sub_order_no | sub_order_no | 131 | fd_mall.b.sub_order_no | 1 | 100.00 | Using where |
+----+-------------+-------+------------+--------+----------------------------------------------------+--------------------+---------+------------------------+-------+----------+---------------------------------+
9 rows in set, 1 warning (0.01 sec)
json edition (explain format = json select ....;)
| {
"query_block": {
"select_id": 1,
"cost_info": {
"query_cost": "32590.78"
},
"ordering_operation": {
"using_filesort": true,
"grouping_operation": {
"using_temporary_table": true,
"using_filesort": false,
"nested_loop": [
{
"table": {
"table_name": "g",
"access_type": "const",
"possible_keys": [
"PRIMARY"
],
"key": "PRIMARY",
"used_key_parts": [
"shop_no"
],
"key_length": "130",
"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": "7K"
},
"used_columns": [
"shop_no",
"shop_type"
]
}
},
{
"table": {
"table_name": "a",
"access_type": "ALL",
"possible_keys": [
"PRIMARY"
],
"rows_examined_per_scan": 82171,
"rows_produced_per_join": 8217,
"filtered": "10.00",
"cost_info": {
"read_cost": "8381.14",
"eval_cost": "821.71",
"prefix_cost": "9202.85",
"data_read_per_join": "5M"
},
"used_columns": [
"order_no",
"tmp_order_no",
"create_time",
"address",
"user_id",
"is_delete"
],
"attached_condition": "((`fd_mall`.`a`.`is_delete` = '0') and (`fd_mall`.`a`.`order_no` is not null))"
}
},
{
"table": {
"table_name": "b",
"access_type": "ref",
"possible_keys": [
"sub_order_no",
"idx_status_orderno",
"idx_orderno_status"
],
"key": "idx_orderno_status",
"used_key_parts": [
"order_no"
],
"key_length": "163",
"ref": [
"fd_mall.a.order_no"
],
"rows_examined_per_scan": 1,
"rows_produced_per_join": 7903,
"filtered": "96.18",
"index_condition": "((`fd_mall`.`b`.`status` in ('1','2','3')) and (`fd_mall`.`a`.`order_no` = `fd_mall`.`b`.`order_no`))",
"cost_info": {
"read_cost": "2054.28",
"eval_cost": "790.31",
"prefix_cost": "12078.84",
"data_read_per_join": "6M"
},
"used_columns": [
"id",
"sub_order_no",
"order_no",
"c_m_mount",
"c_i_mount",
"c_delivery_m_fee",
"c_delivery_i_fee",
"status"
]
}
},
{
"table": {
"table_name": "c",
"access_type": "ref",
"possible_keys": [
"sub_order_no"
],
"key": "sub_order_no",
"used_key_parts": [
"sub_order_no"
],
"key_length": "163",
"ref": [
"fd_mall.b.sub_order_no"
],
"rows_examined_per_scan": 1,
"rows_produced_per_join": 7903,
"filtered": "100.00",
"cost_info": {
"read_cost": "1975.78",
"eval_cost": "790.31",
"prefix_cost": "14844.93",
"data_read_per_join": "40M"
},
"used_columns": [
"id",
"sub_order_no",
"publish_id",
"publish_version_id",
"product_version_id",
"sku_id",
"num"
]
}
},
{
"table": {
"table_name": "e",
"access_type": "eq_ref",
"possible_keys": [
"PRIMARY",
"product_no"
],
"key": "PRIMARY",
"used_key_parts": [
"id"
],
"key_length": "130",
"ref": [
"fd_mall.c.sku_id"
],
"rows_examined_per_scan": 1,
"rows_produced_per_join": 7903,
"filtered": "100.00",
"cost_info": {
"read_cost": "7723.11",
"eval_cost": "790.31",
"prefix_cost": "23358.35",
"data_read_per_join": "45M"
},
"used_columns": [
"id",
"product_no",
"imp_price",
"market_price",
"cost_price"
],
"attached_condition": "(`fd_mall`.`e`.`id` = `fd_mall`.`c`.`sku_id`)"
}
},
{
"table": {
"table_name": "f",
"access_type": "eq_ref",
"possible_keys": [
"PRIMARY",
"shop_no"
],
"key": "PRIMARY",
"used_key_parts": [
"product_no"
],
"key_length": "202",
"ref": [
"fd_mall.e.product_no"
],
"rows_examined_per_scan": 1,
"rows_produced_per_join": 395,
"filtered": "5.00",
"cost_info": {
"read_cost": "7182.06",
"eval_cost": "39.52",
"prefix_cost": "31330.73",
"data_read_per_join": "1M"
},
"used_columns": [
"product_no",
"source",
"shop_no",
"pd_type"
],
"attached_condition": "((`fd_mall`.`f`.`shop_no` = 'GYS100195') and (`fd_mall`.`f`.`product_no` = `fd_mall`.`e`.`product_no`))"
}
},
{
"table": {
"table_name": "h",
"access_type": "ref",
"possible_keys": [
"order_no",
"idx_orderno_amount_paychannel"
],
"key": "idx_orderno_amount_paychannel",
"used_key_parts": [
"order_no"
],
"key_length": "163",
"ref": [
"fd_mall.b.order_no"
],
"rows_examined_per_scan": 1,
"rows_produced_per_join": 395,
"filtered": "100.00",
"cost_info": {
"read_cost": "391.75",
"eval_cost": "39.52",
"prefix_cost": "31761.99",
"data_read_per_join": "564K"
},
"used_columns": [
"pay_no",
"order_no",
"direction",
"pay_type",
"pay_channel"
],
"attached_condition": "<if>(is_not_null_compl(h), (`fd_mall`.`h`.`direction` = '01'), true)"
}
},
{
"table": {
"table_name": "t",
"access_type": "ref",
"possible_keys": [
"ac_userid"
],
"key": "ac_userid",
"used_key_parts": [
"ac_userid"
],
"key_length": "163",
"ref": [
"fd_mall.a.user_id"
],
"rows_examined_per_scan": 1,
"rows_produced_per_join": 405,
"filtered": "100.00",
"cost_info": {
"read_cost": "382.46",
"eval_cost": "40.51",
"prefix_cost": "32184.96",
"data_read_per_join": "2M"
},
"used_columns": [
"id",
"usertype",
"ac_userid"
]
}
},
{
"table": {
"table_name": "d",
"access_type": "ref",
"possible_keys": [
"sub_order_no"
],
"key": "sub_order_no",
"used_key_parts": [
"sub_order_no"
],
"key_length": "131",
"ref": [
"fd_mall.b.sub_order_no"
],
"rows_examined_per_scan": 1,
"rows_produced_per_join": 481,
"filtered": "100.00",
"cost_info": {
"read_cost": "357.63",
"eval_cost": "48.19",
"prefix_cost": "32590.78",
"data_read_per_join": "3M"
},
"used_columns": [
"delivery_no",
"sub_order_no",
"delivery_code",
"delivery_status",
"delivery_com"
],
"attached_condition": "<if>(is_not_null_compl(d), (`fd_mall`.`d`.`sub_order_no` = `fd_mall`.`b`.`sub_order_no`), true)"
}
}
]
}
}
}
} |边栏推荐
- Valentine's Day - VBS learning (sentences, love words)
- Android studio interview preparation
- Postman interface test
- Common tools for interface testing --postman
- Copy & Deepcopy
- Zhejiang energy online monitoring and management system
- Apache Doris becomes the top project of Apache
- Application of energy management system in iron and steel enterprises
- 两道面试小Demo
- Apiccloud, together with 360 Tianyu, helps enterprises keep the "first pass" of APP security
猜你喜欢

Discussion on the practice of fire emergency lighting system in the field of building electrical design

Decision table method for basic content learning of software testing (2)

Almost union find (weighted union search)

图解MySQL的binlog、redo log和undo log

Rman Backup Report Ora - 19809 Ora - 19804
![[.Net6] GRP server and client development cases, as well as the access efficiency duel between the minimum API service, GRP service and traditional webapi service](/img/19/296f124becb87461accf8b73b0a8bc.png)
[.Net6] GRP server and client development cases, as well as the access efficiency duel between the minimum API service, GRP service and traditional webapi service

For the development of short video app, the elder warned me to choose the open source code

Which is a better ERP management system for electronic component sales?

学习阿里如何进行数据指标体系的治理

"Jianzhi offer" -- Interview Question 4: finding two-dimensional arrays
随机推荐
Is it safe for CICC fortune to open an account? How much do you charge?
The private attribute of this class can be used directly? New() in use!!!
買賣股票費用計算
Discussion on safety management of centralized maintenance construction site of substation under the mode of operation and maintenance
Potential safety hazards in elderly care facilities
网上炒股开户安不安全?
High rise building fire prevention
数据挖掘建模实战
Is it safe to open an account for online stock speculation?
Loggerfactory uses log4j Parameter introduction of properties
The constructor is never executed immediately after new()!!!!!
基于宽表的数据建模
SQL 优化经历:从 30248秒到 0.001秒的经历
[share OpenGL tutorial]
Implementation of single sign on
Lilda low code data large screen, leveling the threshold of data application development
手机炒股开户安不安全?
静态代码块永远先执行? 格局小了!!!
Rman Backup Report Ora - 19809 Ora - 19804
SQL injection file read / write