QUERY PLAN
HashAggregate (cost=530.37..537.89 rows=188 width=144)
Group Key: ex.id, sub.product_brand
Filter: (sum(sub.amount) <> '0'::numeric)
-> Hash Right Join (cost=519.75..525.20 rows=188 width=112)
Hash Cond: (ex.id = sub.product_brand)
-> Seq Scan on tbl_product_brands ex (cost=0.00..4.93 rows=193 width=12)
-> Hash (cost=517.40..517.40 rows=188 width=100)
-> Subquery Scan on sub (cost=512.23..517.40 rows=188 width=100)
-> HashAggregate (cost=512.23..515.52 rows=188 width=100)
Group Key: p.product_brand
-> Hash Left Join (cost=420.89..492.83 rows=1940 width=76)
Hash Cond: (p.id = sub_1.product_id)
-> Seq Scan on tbl_products p (cost=0.00..64.40 rows=1940 width=8)
-> Hash (cost=420.55..420.55 rows=27 width=76)
-> Subquery Scan on sub_1 (cost=419.27..420.55 rows=27 width=76)
-> GroupAggregate (cost=419.27..420.28 rows=27 width=80)
Group Key: ppr.product_id
-> Sort (cost=419.27..419.33 rows=27 width=18)
Sort Key: ppr.product_id
-> Hash Join (cost=371.79..418.62 rows=27 width=18)
Hash Cond: (ppr.project_id = project.id)
-> Seq Scan on tbl_project_product_rels ppr (cost=0.00..41.88 rows=1884 width=22)
Filter: ((amount IS NOT NULL) AND (cost IS NOT NULL) AND (number IS NOT NULL))
-> Hash (cost=371.25..371.25 rows=43 width=4)
-> Bitmap Heap Scan on tbl_projects project (cost=74.85..371.25 rows=43 width=4)
Recheck Cond: (created_by = ANY ('{5301,5209,5026,5293,5309,5356,5329,5299,5303,5302,5332,5096,5448,5420,1001,5087,1008,5230,5088,5208,1003,5294,5357,5076,5300,5089,5311,5364,5295,1013,5128,5203,1004,5072,5359,5412,5409,5229,1005,5304,5449,5358,1006,5093}'::integer[]))
Filter: ((bargain_date >= '2025-01-01'::date) AND (bargain_date <= '2025-12-31'::date) AND (((budget > collected) AND (project_status = ANY ('{3,-1}'::integer[]))) OR ((budget <= collected) AND (project_status = 3))))
-> Bitmap Index Scan on tbl_projects_created_by_idx (cost=0.00..74.84 rows=1955 width=0)
Index Cond: (created_by = ANY ('{5301,5209,5026,5293,5309,5356,5329,5299,5303,5302,5332,5096,5448,5420,1001,5087,1008,5230,5088,5208,1003,5294,5357,5076,5300,5089,5311,5364,5295,1013,5128,5203,1004,5072,5359,5412,5409,5229,1005,5304,5449,5358,1006,5093}'::integer[]))