QUERY PLAN
Aggregate (cost=30.15..30.16 rows=1 width=8)
-> Sort (cost=30.13..30.14 rows=1 width=2975)
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=30.08..30.12 rows=1 width=2975)
Group Key: c.id
-> Sort (cost=30.08..30.09 rows=6 width=16)
Sort Key: c.id
-> Nested Loop (cost=10.40..30.00 rows=6 width=16)
-> Index Only Scan using tbl_clients_pkey on tbl_clients client (cost=0.14..8.15 rows=1 width=4)
Index Cond: (id = 1)
-> Hash Right Join (cost=10.26..21.79 rows=6 width=20)
Hash Cond: (cm.contact_id = c.id)
-> Seq Scan on tbl_contact_mobiles cm (cost=0.00..11.20 rows=119 width=4)
Filter: (mp_open_id IS NOT NULL)
-> Hash (cost=10.25..10.25 rows=1 width=20)
-> Seq Scan on tbl_contacts c (cost=0.00..10.25 rows=1 width=20)
Filter: (client_id = 1)