QUERY PLAN
Limit (cost=231.98..231.99 rows=1 width=158)
-> Sort (cost=231.98..231.99 rows=1 width=158)
Sort Key: (CASE c.user_status WHEN 3 THEN 1 WHEN 1 THEN 0 ELSE c.user_status END) DESC, c.updated_at DESC
-> GroupAggregate (cost=231.94..231.97 rows=1 width=158)
Group Key: c.id
-> Sort (cost=231.94..231.95 rows=1 width=154)
Sort Key: c.id
-> Nested Loop (cost=148.73..231.93 rows=1 width=154)
-> Hash Right Join (cost=148.45..223.63 rows=1 width=154)
Hash Cond: (cm.contact_id = c.id)
-> Seq Scan on tbl_contact_mobiles cm (cost=0.00..74.43 rows=285 width=8)
Filter: (mp_open_id IS NOT NULL)
-> Hash (cost=148.44..148.44 rows=1 width=150)
-> Seq Scan on tbl_contacts c (cost=0.00..148.44 rows=1 width=150)
Filter: (client_id = 1661)
-> Index Only Scan using tbl_clients_pkey on tbl_clients client (cost=0.28..8.29 rows=1 width=4)
Index Cond: (id = 1661)