QUERY PLAN
GroupAggregate (cost=24.65..24.70 rows=2 width=76)
Group Key: gb.id
-> Sort (cost=24.65..24.65 rows=2 width=22)
Sort Key: gb.id
-> Nested Loop Left Join (cost=9.07..24.64 rows=2 width=22)
-> Nested Loop (cost=8.93..24.29 rows=2 width=14)
-> Nested Loop (cost=8.65..22.81 rows=2 width=14)
-> Hash Join (cost=8.37..22.04 rows=2 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=384 width=18)
Filter: (erp_sales_outbound_spent_product_id IS NOT NULL)
-> Hash (cost=8.36..8.36 rows=1 width=4)
-> Seq Scan on tbl_erp_sales_outbounds t (cost=0.00..8.36 rows=1 width=4)
Filter: ((created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2025-07-09 23:59:59+08'::timestamp with time zone) AND (status = 2))
-> Index Scan using tbl_erp_sales_outbound_spent_products_pkey on tbl_erp_sales_outbound_spent_products sp (cost=0.28..0.39 rows=1 width=8)
Index Cond: (id = eipss.erp_sales_outbound_spent_product_id)
-> Index Scan using tbl_products_pkey on tbl_products prod (cost=0.28..0.74 rows=1 width=8)
Index Cond: (id = sp.product_id)
-> Index Scan using tbl_product_brands_pkey on tbl_product_brands gb (cost=0.14..0.17 rows=1 width=12)
Index Cond: (id = prod.product_brand)