QUERY PLAN
Aggregate (cost=545.55..545.56 rows=1 width=8)
-> Sort (cost=545.48..545.49 rows=5 width=289)
Sort Key: "*SELECT* 1".created_at DESC
-> Result (cost=502.61..545.42 rows=5 width=289)
-> Append (cost=502.61..545.37 rows=5 width=8)
-> Subquery Scan on "*SELECT* 1" (cost=502.61..502.68 rows=1 width=8)
-> Group (cost=502.61..502.67 rows=1 width=289)
Group Key: r.id, sc.from_project
-> Merge Left Join (cost=502.61..502.67 rows=1 width=16)
Merge Cond: (r.id = cpc.erp_cash_cost_ticket_id)
Filter: (cpc.id IS NULL)
-> Sort (cost=501.53..501.55 rows=5 width=16)
Sort Key: r.id
-> Hash Join (cost=8.31..501.48 rows=5 width=16)
Hash Cond: (r.sales_contract_id = sc.id)
-> Seq Scan on tbl_erp_cash_cost_tickets r (cost=0.00..470.94 rows=8465 width=16)
Filter: (status = 2)
-> Hash (cost=8.29..8.29 rows=1 width=8)
-> Index Scan using tbl_sales_contracts_from_project_idx on tbl_sales_contracts sc (cost=0.28..8.29 rows=1 width=8)
Index Cond: (from_project = 4103)
-> Sort (cost=1.08..1.09 rows=4 width=8)
Sort Key: cpc.erp_cash_cost_ticket_id
-> Seq Scan on tbl_erp_cash_cost_ticket_client_project_costs cpc (cost=0.00..1.04 rows=4 width=8)
-> Subquery Scan on "*SELECT* 2" (cost=9.37..9.39 rows=1 width=8)
-> Group (cost=9.37..9.38 rows=1 width=293)
Group Key: cpc_1.id, r_1.id
-> Sort (cost=9.37..9.37 rows=1 width=16)
Sort Key: cpc_1.id, r_1.id
-> Nested Loop (cost=0.29..9.36 rows=1 width=16)
-> Seq Scan on tbl_erp_cash_cost_ticket_client_project_costs cpc_1 (cost=0.00..1.05 rows=1 width=8)
Filter: (project_id = 4103)
-> Index Scan using tbl_erp_cash_cost_tickets_pkey on tbl_erp_cash_cost_tickets r_1 (cost=0.29..8.30 rows=1 width=12)
Index Cond: (id = cpc_1.erp_cash_cost_ticket_id)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 3" (cost=2.89..2.91 rows=1 width=8)
-> Group (cost=2.89..2.90 rows=1 width=289)
Group Key: r_2.id
-> Sort (cost=2.89..2.90 rows=1 width=16)
Sort Key: r_2.id
-> Seq Scan on tbl_erp_cost_tickets r_2 (cost=0.00..2.88 rows=1 width=16)
Filter: ((status = 2) AND (project_id = 4103))
-> Subquery Scan on "*SELECT* 4" (cost=9.57..9.59 rows=1 width=8)
-> Group (cost=9.57..9.58 rows=1 width=289)
Group Key: r_3.id, sc_1.from_project
-> Sort (cost=9.57..9.57 rows=1 width=16)
Sort Key: r_3.id
-> Nested Loop (cost=0.28..9.56 rows=1 width=16)
Join Filter: (r_3.sales_contract_id = sc_1.id)
-> Index Scan using tbl_sales_contracts_from_project_idx on tbl_sales_contracts sc_1 (cost=0.28..8.29 rows=1 width=8)
Index Cond: (from_project = 4103)
-> Seq Scan on tbl_erp_cost_convert_tickets r_3 (cost=0.00..1.14 rows=10 width=16)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 5" (cost=20.76..20.80 rows=1 width=8)
-> GroupAggregate (cost=20.76..20.79 rows=1 width=289)
Group Key: r_4.id
-> Sort (cost=20.76..20.77 rows=3 width=12)
Sort Key: r_4.id
-> Hash Right Join (cost=6.59..20.74 rows=3 width=12)
Hash Cond: (eipss.erp_sales_gift_id = r_4.id)
-> Seq Scan on tbl_erp_inventory_product_spents eipss (cost=0.00..12.65 rows=565 width=4)
-> Hash (cost=6.58..6.58 rows=1 width=12)
-> Seq Scan on tbl_erp_sales_gifts r_4 (cost=0.00..6.58 rows=1 width=12)
Filter: ((project_id = 4103) AND (status = 2))