QUERY PLAN
Limit (cost=562.03..562.05 rows=7 width=133)
-> Sort (cost=562.03..562.05 rows=7 width=133)
Sort Key: r.created_at DESC
-> Append (cost=488.17..561.93 rows=7 width=133)
-> Group (cost=488.17..488.20 rows=4 width=109)
Group Key: r.id, sc.from_project
-> Sort (cost=488.17..488.18 rows=4 width=96)
Sort Key: r.id
-> Hash Join (cost=67.90..488.13 rows=4 width=96)
Hash Cond: (r.sales_contract_id = sc.id)
-> Seq Scan on tbl_erp_cash_cost_tickets r (cost=0.00..400.68 rows=7445 width=96)
Filter: (status = 2)
-> Hash (cost=67.89..67.89 rows=1 width=8)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..67.89 rows=1 width=8)
Filter: (from_project = 3883)
-> Group (cost=1.24..1.24 rows=1 width=103)
Group Key: r_1.id
-> Sort (cost=1.24..1.24 rows=1 width=90)
Sort Key: r_1.id
-> Seq Scan on tbl_erp_cost_tickets r_1 (cost=0.00..1.23 rows=1 width=90)
Filter: ((status = 2) AND (project_id = 3883))
-> Group (cost=69.27..69.28 rows=1 width=141)
Group Key: r_2.id, sc_1.from_project
-> Sort (cost=69.27..69.28 rows=1 width=128)
Sort Key: r_2.id
-> Nested Loop (cost=0.00..69.26 rows=1 width=128)
Join Filter: (r_2.sales_contract_id = sc_1.id)
-> Seq Scan on tbl_sales_contracts sc_1 (cost=0.00..67.89 rows=1 width=8)
Filter: (from_project = 3883)
-> Seq Scan on tbl_erp_cost_convert_tickets r_2 (cost=0.00..1.19 rows=15 width=128)
Filter: (status = 2)
-> HashAggregate (cost=3.12..3.14 rows=1 width=257)
Group Key: r_3.id
-> Hash Right Join (cost=1.19..3.07 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..1.68 rows=68 width=13)
-> Hash (cost=1.18..1.18 rows=1 width=176)
-> Seq Scan on tbl_erp_sales_gifts r_3 (cost=0.00..1.18 rows=1 width=176)
Filter: ((project_id = 3883) AND (status = 2))