QUERY PLAN
Aggregate (cost=178.72..178.73 rows=1 width=8)
-> Sort (cost=178.71..178.71 rows=1 width=324)
Sort Key: p.is_draft DESC, p.end_at DESC
-> Group (cost=178.69..178.70 rows=1 width=324)
Group Key: p.id
-> Sort (cost=178.69..178.69 rows=1 width=13)
Sort Key: p.id
-> Nested Loop Left Join (cost=87.66..178.68 rows=1 width=13)
Filter: ((NOT client.deleted) OR (ca.client_id IS NULL))
-> Nested Loop (cost=87.38..171.04 rows=1 width=21)
-> Hash Right Join (cost=87.10..113.19 rows=6 width=21)
Hash Cond: (pt.pre_sales_id = p.id)
-> Seq Scan on tbl_pre_sales_product_types pt (cost=0.00..23.15 rows=1115 width=4)
-> Hash (cost=87.03..87.03 rows=6 width=21)
-> Seq Scan on tbl_pre_sales p (cost=0.00..87.03 rows=6 width=21)
Filter: ((NOT is_draft) AND (created_by = 1000))
-> Index Scan using tbl_cases_pkey on tbl_cases ca (cost=0.28..8.31 rows=1 width=12)
Index Cond: (id = p.case_id)
Filter: ((project_id = 3811) AND (client_id = 2815))
-> Index Scan using tbl_clients_pkey on tbl_clients client (cost=0.28..7.63 rows=1 width=21)
Index Cond: (id = p.client_id)