View the mysql execution plan bitsCN.com
View the execution plan of mysql. the SQL statement is executed for 4 minutes, and the message_message contains 1000 million data. the execution plan of mysql is learned.
Select * from message_message where id in (select message_id
From message_message_tags where messagetag_id = 59885) and (category = 9 or category = 1)
Order by sum (like_count, favorite_count) desc limit 15,
If a developer is often at a loss or is directly handed over to the DBA to handle the problem, you are lucky to have a DBA,
However, if you do not have a DBA, the only possible solution is to view the execution plan.
(You can also directly use explain SQL to analyze ...): By default, Mysql's profiling is disabled. Therefore, you must first enable the profiling SQL code set profiling = "ON" mysql> show variables like "% profi % "; + ---------------------- + ------- + | Variable_name | Value | + ------------------------ + ------- + | profiling | ON | show processlist; view the list of all processes currently running, the only thing we need in the process list is ID mysql> show processlist; + ---- + ------ + ---------------- + ----------- + --------- + ------ + ------- + ------------- + | Id | User | Host | db | Command | Time | State | Info | + ---- + ------ + ---------------- + ----------- + --------- + ------ + ------- + ------------- ----- + | 3 | root | localhost: 2196 | click_log | Query | 0 | NULL | show process list | + ---- + ------ + ---------------- + ----------- + --------- + ------ + ------- + ------------- mysql> show profile cpu, memory for query 3; + metric + ------------ + ---------- + ------------ + | Status | Duration | CPU_user | CPU_system | + metric + ------------ + ---------- + ------------ + | freeing items | 0.00001375 | NULL | logging slow query | 0.00001375 | NULL | cleaning up | 0.00000050 | NULL | + -------------------- + ------------ + ---------- + ------------ + show profiles Syntax: show profile [type [, type]...] [for query n] [LIMIT row_count [OFFSET offset] type: ALL | block io | context switches | CPU | IPC | MEMORY | page faults | SOURCE | SWAPS author san_yunbitsCN.com
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.