Optimize task queries using EXPLAIN