QUERY PLAN
GroupAggregate (cost=23.64..576.10 rows=1 width=509)
Group Key: p.id
-> Nested Loop Left Join (cost=23.64..575.99 rows=1 width=573)
Join Filter: (p.id = t_5.project_id)
-> Nested Loop Left Join (cost=17.04..555.20 rows=1 width=541)
Join Filter: (p.id = sc_1.from_project)
-> Nested Loop Left Join (cost=16.77..545.60 rows=1 width=509)
Join Filter: (p.id = cpc_1.project_id)
-> Nested Loop Left Join (cost=16.48..536.20 rows=1 width=477)
Join Filter: (p.id = sc.from_project)
-> Nested Loop Left Join (cost=8.17..33.33 rows=1 width=445)
Join Filter: (p.id = t_1.project_id)
-> Nested Loop Left Join (cost=8.17..30.41 rows=1 width=413)
Join Filter: (p.id = t.project_id)
-> Index Scan using tbl_projects_pkey on tbl_projects p (cost=0.28..8.30 rows=1 width=349)
Index Cond: (id = 4103)
-> GroupAggregate (cost=7.89..22.09 rows=1 width=68)
Group Key: t.project_id
-> Hash Right Join (cost=7.89..22.05 rows=3 width=14)
Hash Cond: (eipss.erp_sales_outbound_id = t.id)
-> Seq Scan on tbl_erp_inventory_product_spents eipss (cost=0.00..12.65 rows=565 width=14)
-> Hash (cost=7.88..7.88 rows=1 width=8)
-> Seq Scan on tbl_erp_sales_outbounds t (cost=0.00..7.88 rows=1 width=8)
Filter: ((project_id IS NOT NULL) AND (status = 2) AND (project_id = 4103))
-> GroupAggregate (cost=0.00..2.90 rows=1 width=36)
Group Key: t_1.project_id
-> Seq Scan on tbl_erp_cost_tickets t_1 (cost=0.00..2.88 rows=1 width=9)
Filter: ((project_id IS NOT NULL) AND (status = 2) AND (project_id = 4103))
-> GroupAggregate (cost=8.31..502.85 rows=1 width=36)
Group Key: sc.from_project
-> Nested Loop Left Join (cost=8.31..502.83 rows=1 width=9)
Join Filter: (cpc.erp_cash_cost_ticket_id = t_2.id)
Filter: (cpc.id IS NULL)
-> Hash Join (cost=8.31..501.48 rows=5 width=13)
Hash Cond: (t_2.sales_contract_id = sc.id)
-> Seq Scan on tbl_erp_cash_cost_tickets t_2 (cost=0.00..470.94 rows=8465 width=13)
Filter: (status = 2)
-> Hash (cost=8.30..8.30 rows=1 width=8)
-> Index Scan using tbl_sales_contracts_from_project_idx on tbl_sales_contracts sc (cost=0.28..8.30 rows=1 width=8)
Index Cond: ((from_project IS NOT NULL) AND (from_project = 4103))
-> Materialize (cost=0.00..1.06 rows=4 width=8)
-> Seq Scan on tbl_erp_cash_cost_ticket_client_project_costs cpc (cost=0.00..1.04 rows=4 width=8)
-> GroupAggregate (cost=0.29..9.37 rows=1 width=36)
Group Key: cpc_1.project_id
-> Nested Loop (cost=0.29..9.36 rows=1 width=9)
-> Seq Scan on tbl_erp_cash_cost_ticket_client_project_costs cpc_1 (cost=0.00..1.05 rows=1 width=13)
Filter: ((project_id IS NOT NULL) AND (project_id = 4103))
-> Index Scan using tbl_erp_cash_cost_tickets_pkey on tbl_erp_cash_cost_tickets t_3 (cost=0.29..8.30 rows=1 width=4)
Index Cond: (id = cpc_1.erp_cash_cost_ticket_id)
Filter: (status = 2)
-> GroupAggregate (cost=0.28..9.58 rows=1 width=36)
Group Key: sc_1.from_project
-> Nested Loop (cost=0.28..9.56 rows=1 width=10)
Join Filter: (t_4.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.30 rows=1 width=8)
Index Cond: ((from_project IS NOT NULL) AND (from_project = 4103))
-> Seq Scan on tbl_erp_cost_convert_tickets t_4 (cost=0.00..1.14 rows=10 width=10)
Filter: (status = 2)
-> GroupAggregate (cost=6.59..20.77 rows=1 width=36)
Group Key: t_5.project_id
-> Hash Right Join (cost=6.59..20.74 rows=3 width=14)
Hash Cond: (eipss_1.erp_sales_gift_id = t_5.id)
-> Seq Scan on tbl_erp_inventory_product_spents eipss_1 (cost=0.00..12.65 rows=565 width=14)
-> Hash (cost=6.58..6.58 rows=1 width=8)
-> Seq Scan on tbl_erp_sales_gifts t_5 (cost=0.00..6.58 rows=1 width=8)
Filter: ((project_id IS NOT NULL) AND (status = 2) AND (project_id = 4103))