Optimize query for found messages

pull/178/head
M66B 5 years ago
parent 20b724818a
commit 46341ea458

@ -78,10 +78,9 @@ public interface DaoMessage {
" AND message.thread IN" + " AND message.thread IN" +
" (SELECT DISTINCT mm.thread FROM folder ff" + " (SELECT DISTINCT mm.thread FROM folder ff" +
" JOIN message mm ON mm.folder = ff.id" + " JOIN message mm ON mm.folder = ff.id" +
" WHERE (:found" + " WHERE ((:type IS NULL AND ff.unified) OR (:type IS NOT NULL AND ff.type = :type))" +
" OR (:type IS NULL AND ff.unified)" + " AND (NOT mm.ui_hide OR :debug)" +
" OR (:type IS NOT NULL AND ff.type = :type))" + " AND (NOT :found OR mm.ui_found))" +
" AND (NOT mm.ui_hide OR :debug))" +
" GROUP BY account.id, CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" + " GROUP BY account.id, CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" +
" HAVING (NOT :filter_seen OR SUM(1 - message.ui_seen) > 0)" + " HAVING (NOT :filter_seen OR SUM(1 - message.ui_seen) > 0)" +
" AND (NOT :filter_unflagged OR COUNT(message.id) - SUM(1 - message.ui_flagged) > 0)" + " AND (NOT :filter_unflagged OR COUNT(message.id) - SUM(1 - message.ui_flagged) > 0)" +
@ -142,7 +141,8 @@ public interface DaoMessage {
" AND message.thread IN" + " AND message.thread IN" +
" (SELECT DISTINCT mm.thread FROM message mm" + " (SELECT DISTINCT mm.thread FROM message mm" +
" WHERE mm.folder = :folder" + " WHERE mm.folder = :folder" +
" AND (NOT mm.ui_hide OR :debug))" + " AND (NOT mm.ui_hide OR :debug)" +
" AND (NOT :found OR mm.ui_found))" +
" GROUP BY CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" + " GROUP BY CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" +
" HAVING (NOT :filter_seen OR SUM(1 - message.ui_seen) > 0 OR " + is_outbox + ")" + " HAVING (NOT :filter_seen OR SUM(1 - message.ui_seen) > 0 OR " + is_outbox + ")" +
" AND (NOT :filter_unflagged OR COUNT(message.id) - SUM(1 - message.ui_flagged) > 0 OR " + is_outbox + ")" + " AND (NOT :filter_unflagged OR COUNT(message.id) - SUM(1 - message.ui_flagged) > 0 OR " + is_outbox + ")" +

Loading…
Cancel
Save