QUERY PLAN
GroupAggregate (cost=119.86..121.50 rows=41 width=80)
Group Key: (GREATEST((CURRENT_DATE - date(eip.created_at)), 0)), gb.id
-> Sort (cost=119.86..119.96 rows=41 width=29)
Sort Key: (GREATEST((CURRENT_DATE - date(eip.created_at)), 0)), gb.id
-> Nested Loop Left Join (cost=96.94..118.76 rows=41 width=29)
-> Hash Join (cost=96.80..111.30 rows=41 width=25)
Hash Cond: (eip.product_id = prod.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..14.39 rows=41 width=25)
Filter: (((erp_purchase_inbound_id IS NOT NULL) OR (erp_purchase_gift_id IS NOT NULL) OR (erp_inventory_build_id IS NOT NULL) OR (erp_inventory_disassemble_id IS NOT NULL) OR (erp_inventory_start_id IS NOT NULL)) AND (inventory > '0'::numeric))
-> Hash (cost=70.80..70.80 rows=2080 width=8)
-> Seq Scan on tbl_products prod (cost=0.00..70.80 rows=2080 width=8)
-> 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)