Improve books table query for smart categories