mysql - COUNT() comments each time vs cache in count_comments column vs use another type of cache -
i have common doubt.
guess creating social network or blog posts, , each post has comments.
if want paginate , filter lists of posts , show amount of comments of each post
should add count_comments column posts table (like wp does) , cache amount of comments there (i.e. every time comments add 1 if deletes comment sub 1 count_comments column)
should perform subselect count amount of comments every time , cache result form or caching
or recommend?
in short words: both work, , both variants have advantages , disadvantages.
you'll have arguments both ways.
if need comment count frequently, , takes alot of system/application ressources value simple sql statement (p.e. sorting value pain), storing value in field wordpress way it.
if don't need comment count frequently, and/or doesn't take alot of ressources values (select count(*) yourcommenttable yourpostid = whatever shouldn't tough systems), possibly benefit more while avoiding issues keeping value in sync actual comments in posts.
Comments
Post a Comment