QUERY PLAN
Aggregate (cost=2106.08..2106.09 rows=1 width=8)
-> Sort (cost=2105.37..2105.49 rows=47 width=1067)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=2103.83..2104.07 rows=47 width=1067)
Group Key: c.id
-> Sort (cost=2103.83..2103.95 rows=47 width=16)
Sort Key: c.id
-> Hash Left Join (cost=1471.13..2102.53 rows=47 width=16)
Hash Cond: (client.sales_rep = sgr.sales_id)
-> Hash Right Join (cost=1469.50..2100.26 rows=47 width=20)
Hash Cond: (cs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships cs (cost=0.00..624.51 rows=1640 width=4)
Filter: (object_type = 105)
-> Hash (cost=1468.92..1468.92 rows=47 width=20)
-> Hash Right Join (cost=840.03..1468.92 rows=47 width=20)
Hash Cond: (rs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships rs (cost=0.00..624.51 rows=1149 width=4)
Filter: (object_type = 106)
-> Hash (cost=839.45..839.45 rows=47 width=20)
-> Hash Right Join (cost=214.71..839.45 rows=47 width=20)
Hash Cond: (vs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships vs (cost=0.00..624.51 rows=58 width=4)
Filter: (object_type = 107)
-> Hash (cost=214.12..214.12 rows=47 width=20)
-> Hash Right Join (cost=168.29..214.12 rows=47 width=20)
Hash Cond: (sci2.contract_id = c.id)
-> Seq Scan on tbl_sales_contract_invoices sci2 (cost=0.00..38.45 rows=1845 width=4)
-> Hash (cost=167.79..167.79 rows=40 width=20)
-> Hash Join (cost=102.82..167.79 rows=40 width=20)
Hash Cond: (c.client_id = client.id)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..60.86 rows=1560 width=24)
Filter: (from_project IS NOT NULL)
-> Hash (cost=102.19..102.19 rows=51 width=8)
-> Bitmap Heap Scan on tbl_clients client (cost=14.48..102.19 rows=51 width=8)
Recheck Cond: (sales_rep = 1001)
-> Bitmap Index Scan on tbl_clients_sales_rep_idx (cost=0.00..4.71 rows=58 width=0)
Index Cond: (sales_rep = 1001)
-> Hash (cost=1.61..1.61 rows=1 width=4)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.61 rows=1 width=4)
Filter: (sales_id = 1001)