Home > database > Mysql left the join query is slow
Mysql left the join query is slow
Time:10-01
Using mysql, recently met with two tables associated query, checked some data didn't also can solve, fans users than table 4 w, fan label table of more than 2000 data, a query down to 19 seconds, be don't bird,,, and master the way, Wx_fans table, openid is a primary key, subscribetime keyword index is the full text, the other for the common information fields; Wx_fans_tag_r table, openid is full-text keyword indexing, this table is only two fields, openid and tagId (is also more than a pair, one fan has multiple tags) Below is the query:
The SELECT t.o penid subscribetime, createtime, subscribeStatus, nickname, nicknameStr, gender, country, province, city, headimgurl, STATUS, remark, groupId, r.t agId FROM wx_fans t ON the LEFT OUTER JOIN wx_fans_tag_r r t.o penid=r.o penid WHERE 1=1 The ORDER BY subscribetime DESC LIMIT 0, 20
The following is the result of the EXPLAIN SQL:
Here is SHOW the INDEX FROM wx_fans results:
Here is SHOW the INDEX FROM wx_fans_tag_r results:
Seek advice!!!!!!!!!!
CodePudding user response:
Create two index The alter table wx_fans add key (subscribetime, the opened); The alter table wx_fans_tag_r add key (the opened)