开发者

mysql improve performmance by create new table

the code below is work but it take long time to run sometime the php code stop but it work well with mysql graphical tool (becase it can wait) . Are there any method to make it faster I use index in some column it help Are there any method to create table if I create table i think it will improve performance but this table it must be update maybe one a week what is the good practice please suggest

SELECT member.own, member.provincecode, province.PROVINCE_NAME, member.amphurecode,
    amphur.AMPHUR_NAME, member.Sname, member.Ssurname, member.Hno, m开发者_如何学编程ember.Moo,
    member.Sex, member.tambol, member.dateofbirth, member.migratedate,
    Year( Current_Date( ) ) -  Year( member.dateofbirth ) AS y, 
    Year( Current_Date( ) ) - Year( member.migratedate ) AS m
FROM member
LEFT JOIN amphur ON ( member.amphurecode
COLLATE utf8_general_ci = amphur.AMPHUR_CODE )
LEFT JOIN province ON member.provincecode
COLLATE utf8_general_ci = province.PROVINCE_CODE


Collate is an expensive operation. So assuming that member has more rows thanprovince, try to collate the table with the smaller number of rows:

LEFT JOIN province ON member.provincecode
= province.PROVINCE_CODE COLLATE <collation of member.provincecode>

It would be even better to give all columns in all tables the same collation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜