Two composite indexes might be helpful. CREATE INDEX PAW_IDX2099075689 ON comment(USER_ID,DELETED,NEWS_ID,PICTURE_ID,TOPIC_ID); CREATE INDEX PAW_IDX0500726826 ON comment(NEWS_ID,PICTURE_ID,TOPIC_ID,DELETED); PAWSQL_IDX2099075689 can be used in outer block to do a index LOOKUP with condition(`comment.user_id = '1' and comment.deleted = 0`), and SORT AVOIDANCE for (`group by comment.topic_id, comment.picture_id, comment.news_id`). PAWSQL_IDX0500726826 can be used in the subquery to do a index LOOKUP with condition(`p1.topic_id = p2.topic_id and p1.picture_id = p2.picture_id and p1.news_id = p2.news_id and p1.deleted = 0`).