mysql - Query taking very long the first time it runs -
my website has serious issues during peak visit times. after doing troubleshooting have figured out problem database.
i have main query runs on index retrieves table of data.
on busy day site takes between 30 , 45 seconds load first time every time after loads 5 minutes after slows down again , site goes down due load.
i tested query directly on database , performs same.
would more query or mysql config?
it works fine small return result on busy day when lists big slows down , kills site.
edit:
thank suggestions.
i have reworked query , did ammendments db because of names not sensible.
after suggestions have modified query remove wildcard searches , redundant requests table no longer necessary.
here query itself:
select g.id, g.`name`, g.scores, g.sportfk, g.`desc`, g.`date`, s.id streamid games g left join streams s on s.gamefk = g.id (g.date >= '" . $date . "' , g.date <= '" . $newdate . "') , g.sportfk in (" . $sportfk . ") order g.date asc"
after testing first performance of query still running @ 33s , every subsequent execution running @ 0.04s sugegsts effect on site same when peak time comes.
i have prepared requested information explain
.
this 'games' table
games table: size: 6mb rows: 14841 type: innodb
this 'streams' table
streams table: size: 80mb rows: 135296 type: myisam
edit: martin thank making point write. db populated source @ quite regular interval there constant read , write operations happening. have little more research this.
what happening time first time query runs spent compiling query , developing execution plan. stays cached awhile , happens again.
the solution put query stored procedure.
Comments
Post a Comment