QUERY PLAN
Limit (cost=363.34..363.36 rows=8 width=165)
-> Sort (cost=363.34..363.36 rows=8 width=165)
Sort Key: r.created_at DESC
-> Append (cost=339.75..363.22 rows=8 width=165)
-> Group (cost=339.75..339.79 rows=5 width=109)
Group Key: r.id, sc.from_project
-> Sort (cost=339.75..339.77 rows=5 width=96)
Sort Key: r.id
-> Hash Join (cost=65.14..339.70 rows=5 width=96)
Hash Cond: (r.sales_contract_id = sc.id)
-> Seq Scan on tbl_erp_cash_cost_tickets r (cost=0.00..254.32 rows=7704 width=96)
Filter: (status = 2)
-> Hash (cost=65.12..65.12 rows=1 width=8)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..65.12 rows=1 width=8)
Filter: (from_project = 3956)
-> Group (cost=1.21..1.21 rows=1 width=257)
Group Key: r_1.id
-> Sort (cost=1.21..1.21 rows=1 width=244)
Sort Key: r_1.id
-> Seq Scan on tbl_erp_cost_tickets r_1 (cost=0.00..1.20 rows=1 width=244)
Filter: ((status = 2) AND (project_id = 3956))
-> Group (cost=17.35..17.36 rows=1 width=257)
Group Key: r_2.id, sc_1.from_project
-> Sort (cost=17.35..17.36 rows=1 width=244)
Sort Key: r_2.id
-> Nested Loop (cost=0.28..17.34 rows=1 width=244)
-> Seq Scan on tbl_erp_cost_convert_tickets r_2 (cost=0.00..1.02 rows=1 width=244)
Filter: (status = 2)
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts sc_1 (cost=0.28..8.30 rows=1 width=8)
Index Cond: (id = r_2.sales_contract_id)
Filter: (from_project = 3956)
-> HashAggregate (cost=4.75..4.77 rows=1 width=257)
Group Key: r_3.id
-> Hash Right Join (cost=1.30..4.71 rows=6 width=185)
Hash Cond: (eipss.erp_sales_gift_id = r_3.id)
-> Seq Scan on tbl_erp_inventory_product_spents eipss (cost=0.00..3.11 rows=111 width=13)
-> Hash (cost=1.28..1.28 rows=1 width=176)
-> Seq Scan on tbl_erp_sales_gifts r_3 (cost=0.00..1.28 rows=1 width=176)
Filter: ((project_id = 3956) AND (status = 2))