简体   繁体   中英

How to know what is slowing down a MySql left join

I created a view that is a join between two tables a.2_9 (18.483 rows) and b.2_10 (5700 rows)

it is a very simple join:

 Create view v_2_9_join_2_10 AS
 Select *
 FROM 2_9 AS a
 LEFT JOIN 2_10 b
   ON a.2_9_tid = b.2_10_tid
   AND a.2_9_region = b.2_10_region
   AND a.n_2 = b.n_2

I to create the view and count the rows (18483) but for some reason it takes forever when I try to use the view, count or export or just browse and it is slowing down the database in PHP too much.

Any ideas of how I can look for the reason(s) of the slowing down or optimize the join?

To know why a query is being slow you can issue the query you used to create the view with the EXPLAIN keyword, this will show a little table with data that explains how MySQL executed the query so you can identify the bottlenecks there.

HERE you can find a little tutorial on how to understand the output of EXPLAIN .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM