Fix raw queries and count queries to add indexes.