QUERY PLAN
Aggregate (cost=14.91..14.92 rows=1 width=96)
-> Hash Join (cost=10.16..14.89 rows=2 width=72)
Hash Cond: (tbl_erp_inventory_product_spents.erp_inventory_product_id = e.id)
-> GroupAggregate (cost=5.79..9.67 rows=66 width=76)
Group Key: tbl_erp_inventory_product_spents.erp_inventory_product_id
-> Sort (cost=5.79..5.96 rows=68 width=29)
Sort Key: tbl_erp_inventory_product_spents.erp_inventory_product_id
-> Seq Scan on tbl_erp_inventory_product_spents (cost=0.00..3.72 rows=68 width=29)
Filter: (CASE WHEN (erp_inventory_build_spent_id IS NOT NULL) THEN ('1'::text || ((erp_inventory_build_spent_id)::character varying)::text) WHEN (erp_sales_outbound_id IS NOT NULL) THEN ('2'::text || ((erp_sales_outbound_id)::character varying)::text) WHEN (erp_sales_gift_id IS NOT NULL) THEN ('3'::text || ((erp_sales_gift_id)::character varying)::text) WHEN (erp_inventory_lost_id IS NOT NULL) THEN ('4'::text || ((erp_inventory_lost_id)::character varying)::text) ELSE NULL::text END IS NOT NULL)
-> Hash (cost=4.34..4.34 rows=3 width=4)
-> Seq Scan on tbl_erp_inventory_products e (cost=0.00..4.34 rows=3 width=4)
Filter: (product_id = 2095)