Optimize last message search in member list view
This commit is contained in:
parent
d246c9bf33
commit
292676b694
@ -9,7 +9,8 @@ from systems
|
|||||||
create view member_list as
|
create view member_list as
|
||||||
select members.*,
|
select members.*,
|
||||||
-- Find last message ID
|
-- 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
|
-- Find last switch timestamp
|
||||||
(
|
(
|
||||||
|
Loading…
Reference in New Issue
Block a user