you don't cache the number stars on the posts table? just +1 on an insert to post_stars and -1 when you're removing a star. you can even use a trigger if you want (i usually do it in the app)