QUERY PLAN
Limit (cost=4013.85..4013.85 rows=1 width=556)
-> Sort (cost=4013.85..4013.85 rows=1 width=556)
Sort Key: p.bargain_date DESC
-> Nested Loop Left Join (cost=3896.23..4013.84 rows=1 width=556)
Join Filter: (wl.project_id = p.id)
-> Nested Loop Left Join (cost=2237.38..2339.48 rows=1 width=468)
Join Filter: (c_2.project_id = p.id)
-> Nested Loop Left Join (cost=1792.39..1866.06 rows=1 width=444)
Join Filter: (c_1.project_id = p.id)
-> Nested Loop Left Join (cost=1002.34..1069.01 rows=1 width=412)
Join Filter: (c.project_id = p.id)
-> Nested Loop Left Join (cost=260.14..298.37 rows=1 width=388)
Join Filter: (r.project_id = p.id)
-> Index Scan using tbl_projects_client_id_idx on tbl_projects p (cost=0.28..12.12 rows=1 width=356)
Index Cond: (client_id = 2115)
Filter: ((collected < budget) AND (project_status = 3) AND (created_by = ANY ('{1001,5049,5301,5022,5209,5026,5293,5309,5356,5329,5299,5303,5302,5332,5047,1026,5096,5070,5448,5420,1029,5037,5087,1008,5048,5043,5045,5230,5031,5088,5208,1003,5294,5357,5044,1030,5076,5300,5027,5089,5311,5066,5069,5364,1009,5295,1013,5128,5203,1025,5032,5075,1004,5072,5033,5359,5412,5409,5229,1005,5304,5449,5358,1006,5093}'::integer[])))
-> HashAggregate (cost=259.86..269.29 rows=754 width=36)
Group Key: r.project_id
-> Seq Scan on tbl_reimbursements r (cost=0.00..222.94 rows=7385 width=9)
Filter: (status = ANY ('{2,3}'::integer[]))
-> HashAggregate (cost=742.20..750.95 rows=875 width=28)
Group Key: c.project_id
-> Hash Left Join (cost=347.72..677.03 rows=6517 width=24)
Hash Cond: (ir.case_id = c.id)
-> Seq Scan on tbl_implement_records ir (cost=0.00..312.19 rows=6517 width=24)
Filter: (NOT is_draft)
-> Hash (cost=248.43..248.43 rows=7943 width=8)
-> Seq Scan on tbl_cases c (cost=0.00..248.43 rows=7943 width=8)
-> HashAggregate (cost=790.06..792.56 rows=200 width=36)
Group Key: c_1.project_id
-> HashAggregate (cost=571.62..670.91 rows=7943 width=40)
Group Key: c_1.id
-> Hash Right Join (cost=347.72..531.65 rows=7994 width=16)
Hash Cond: (ca.case_id = c_1.id)
-> Seq Scan on tbl_case_assignments ca (cost=0.00..162.94 rows=7994 width=12)
-> Hash (cost=248.43..248.43 rows=7943 width=8)
-> Seq Scan on tbl_cases c_1 (cost=0.00..248.43 rows=7943 width=8)
-> HashAggregate (cost=444.98..453.73 rows=875 width=28)
Group Key: c_2.project_id
-> Hash Right Join (cost=105.48..429.22 rows=1576 width=24)
Hash Cond: (c_2.id = ps.case_id)
-> Seq Scan on tbl_cases c_2 (cost=0.00..248.43 rows=7943 width=8)
-> Hash (cost=85.78..85.78 rows=1576 width=24)
-> Seq Scan on tbl_pre_sales ps (cost=0.00..85.78 rows=1576 width=24)
Filter: (NOT is_draft)
-> HashAggregate (cost=1658.85..1663.61 rows=476 width=28)
Group Key: wl.project_id
-> Seq Scan on tbl_work_logs wl (cost=0.00..1652.65 rows=620 width=24)
Filter: ((NOT is_draft) AND (location_in_id IS NOT NULL) AND (location_out_id IS NOT NULL) AND (client_id IS NOT NULL))