From 292676b69418cbf9687c935c8e5d74512b557086 Mon Sep 17 00:00:00 2001 From: Ske Date: Sat, 13 Jun 2020 02:45:06 +0200 Subject: [PATCH] Optimize last message search in member list view --- PluralKit.Core/Database/views.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PluralKit.Core/Database/views.sql b/PluralKit.Core/Database/views.sql index 928e397f..0f0714a2 100644 --- a/PluralKit.Core/Database/views.sql +++ b/PluralKit.Core/Database/views.sql @@ -9,7 +9,8 @@ from systems create view member_list as select members.*, -- Find last message ID - (select max(messages.mid) from messages where messages.member = members.id) as last_message, + -- max(mid) does full table scan, order by/limit uses index (dunno why, but it works!) + (select mid from messages where messages.member = members.id order by mid desc nulls last limit 1) as last_message, -- Find last switch timestamp (