mysql - How to speed up SQL query -


i need advise if adjustment possible.

table:

create table util_day (   compid varchar(15) collate utf8_czech_ci not null,   testplanid int(10) unsigned not null default '0',   fromdate datetime not null default '0000-00-00 00:00:00',   todate datetime not null default '0000-00-00 00:00:00',   interval int(11) not null default '0',   variant varchar(25) collate utf8_czech_ci default null,   wo_id int(11) default null,   saptime int(5) default null,   usetime int(5) not null,   measurecount int(10) unsigned not null,   key compid (compid),   key testplanid (testplanid),   key wo_id (wo_id),   key fromdate (fromdate),   key variant (variant) ) engine=innodb default charset=utf8 collate=utf8_czech_ci; 

the current query :

update util_day uday set testplanid = (select testplanid                                         (select ud_u.variant,ud_u.wo_id,vs.testplanid                                               (select ud.variant,ud.wo_id                                                     util_day ud substr(compid,1,3) <> 'aoi'                                                     group ud.variant,ud.wo_id) ud_u                                               join variants v on ud_u.variant = v.variant                                               join variant_status vs on v.variantid = vs.variantid                                               join testplans_wo_id tw on ud_u.wo_id = tw.wo_id                                               vs.testplanid = tw.testplanid                                               group ud_u.variant,ud_u.wo_id ) tp                                         tp.variant = uday.variant , tp.wo_id = uday.wo_id) 

and update temporary table:

create temporary table util_day_temp ( variant varchar(25) collate 'utf8_czech_ci' not null, wo_id int unsigned not null, testplanid int unsigned not null, primary key variant_wo_id (variant, wo_id)) comment='' engine='innodb' collate 'utf8_czech_ci'; insert ignore util_day_tmp (select ud_u.variant,ud_u.wo_id,vs.testplanid                  (select ud.variant,ud.wo_id              util_day ud substr(compid,1,3) <> 'aoi'              group ud.variant,ud.wo_id) ud_u        join variants v on ud_u.variant = v.variant        join variant_status vs on v.variantid = vs.variantid        join testplans_wo_id tw on ud_u.wo_id = tw.wo_id        vs.testplanid = tw.testplanid        group ud_u.variant,ud_u.wo_id);  update util_day uday set testplanid = (select testplanid                                          util_day_temp tp                                           tp.variant = uday.variant , tp.wo_id = uday.wo_id); 

this improvement accelerated query on 2milion rows 400%. improvement has same result? thank answers.

first, use

explain command mysql.

after that, figure out if indexes (warning: not create indexes out of control) also, check documentation composite indexes on mysql


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -