php - SQL Execution tooks too long -
php - SQL Execution tooks too long -
i'm working on project needs "similar series" panel. have table series , 1 of genres. need select movies to the lowest degree 4 genres in mutual selected movie.
i came query:
select s_id,stitle,sdesc s_genre inner bring together series on s_genre.s_id=series.id s_id in ( select s_id s_genre inner bring together (select g_id s_genre s_id = $mid) using (g_id) grouping s_id having count(s_id)>3 ) , s_id != $mid order rand() limit 5
it works, takes 20 seconds load :(
any ideas how can cut down loading time? suggestions appreciated :)
thanks in advance.looks problem cause "order rand()" ... removing cut down loading time 0.5s
while order rand() seems major problem, might worth recoding query bring together against sub query:-
select s_genre.s_id, series.stitle, series.sdesc s_genre inner bring together series on s_genre.s_id = series.id inner bring together ( select a.s_id s_genre inner bring together s_genre b on a.g_id = b.g_id b.s_id = $mid grouping a.s_id having count(a.s_id) > 3 ) sub0 on s_genre.s_id = sub0.s_id s_genre.s_id != $mid order rand() limit 5
there techniques select random records, doing query bit messy. rely on having evenly distributed unique identifier rows, , (while assume s_genre.s_id unique id) query have generated holes in range of these , doubtless have holes in range.
php mysql optimization long-integer
Comments
Post a Comment