Get the App
SLTechnology News&Howtos  ›  Database  › 

The method for mysql to get the execution plan

Shulou Source: shulou.com Published: 2022-06-01 09:45:19 10月03日 Update

Mysql gets the execution plan method:

1. View the execution plan of sql through explain

two。 View the execution plan of the sql through the sql that the thread is executing

It is relatively easy for explain to view the execution plan of sql, and it is also very easy to view the execution plan through the sql that the thread is executing, so why do you need a second way? Because daily work will find that a lot of sql is executing all the time, and there is an exception in execution, if we take out the sql and execute it very quickly, we want to get the execution plan of the sql when the execution is abnormal. At the same time, because the data changes from time to time, the statistical information may also change, which may lead to a change in the execution plan. Fortunately, mysql5.7 can already view the execution plan of the sql through the thread that is executing. You don't need to take out the sql to execute the acquisition execution plan, so you can restore the truth very well:

Show processlist; or select * from information_schema.PROCESSLIST where info is not null order by time desc; check.

Mysql > select from information_schema.PROCESSLIST where info is not null

+- -- +

| | ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO |

+- -- +

| | 17 | root | localhost | NULL | Query | 0 | executing | select from information_schema.PROCESSLIST where info is not null | |

| | 178 | root | localhost:60124 | app1 | Query | 560 | Sending data | select count (*) from t, t_adress where t.adress = t_adress.adress |

+- -- +

2 rows in set (0.00 sec)

Mysql > EXPLAIN FOR CONNECTION 178

+- -- +

| | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |

+- -- +

| | 1 | SIMPLE | t_adress | NULL | ALL | NULL | NULL | NULL | NULL | 200096 | 100.00 | NULL |

| | 1 | SIMPLE | t | NULL | ALL | NULL | NULL | NULL | NULL | 309664 | 100.00 | Using where; Using join buffer (Block Nested Loop) |

+- -- +

2 rows in set (0.01sec)

Isn't it convenient to use?

One last word:

I feel very suffocated today. I went to sleep.

Tags: Thread change method suffocation information can be passed at the same time Tianxin work meeting soon data way time moment truth work statistics Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Tech Info Apple Microsoft MariaDB