QUERY PLAN
Aggregate (cost=18.27..18.28 rows=1 width=8)
-> Sort (cost=18.03..18.07 rows=16 width=546)
Sort Key: sub.wrote_date DESC
-> Result (cost=0.00..17.71 rows=16 width=546)
-> Append (cost=0.00..17.55 rows=16 width=4)
-> Subquery Scan on sub (cost=0.00..0.02 rows=1 width=4)
-> HashAggregate (cost=0.00..0.01 rows=1 width=546)
Group Key: id
-> Result (cost=0.00..0.00 rows=0 width=8)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 2" (cost=17.19..17.53 rows=15 width=4)
-> HashAggregate (cost=17.19..17.38 rows=15 width=546)
Group Key: r.id
Filter: (sum(eip.inventory) > '0'::numeric)
-> Hash Join (cost=2.71..17.07 rows=24 width=11)
Hash Cond: (rp.erp_purchase_gift_id = r.id)
-> Hash Right Join (cost=1.27..15.56 rows=24 width=7)
Hash Cond: (eip.erp_purchase_gift_product_id = rp.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..12.97 rows=497 width=11)
-> Hash (cost=1.26..1.26 rows=1 width=8)
-> Seq Scan on tbl_erp_purchase_gift_products rp (cost=0.00..1.26 rows=1 width=8)
Filter: (product_id = 2177)
-> Hash (cost=1.25..1.25 rows=15 width=8)
-> Seq Scan on tbl_erp_purchase_gifts r (cost=0.00..1.25 rows=15 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))