QUERY PLAN
Aggregate (cost=179.21..179.22 rows=1 width=8)
-> Sort (cost=178.50..178.62 rows=47 width=546)
Sort Key: sub.wrote_date DESC
-> Result (cost=38.08..177.20 rows=47 width=546)
-> Append (cost=38.08..176.73 rows=47 width=4)
-> Subquery Scan on sub (cost=38.08..38.35 rows=9 width=4)
-> GroupAggregate (cost=38.08..38.26 rows=9 width=546)
Group Key: r.id
Filter: (sum(eip.inventory) > '0'::numeric)
-> Sort (cost=38.08..38.10 rows=9 width=11)
Sort Key: r.id
-> Hash Join (cost=23.62..37.94 rows=9 width=11)
Hash Cond: (rp.erp_purchase_inbound_id = r.id)
-> Hash Right Join (cost=12.48..26.76 rows=10 width=7)
Hash Cond: (eip.erp_purchase_inbound_product_id = rp.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..12.97 rows=497 width=11)
-> Hash (cost=12.35..12.35 rows=10 width=8)
-> Seq Scan on tbl_erp_purchase_inbound_products rp (cost=0.00..12.35 rows=10 width=8)
Filter: (product_id = 2177)
-> Hash (cost=8.65..8.65 rows=200 width=8)
-> Seq Scan on tbl_erp_purchase_inbounds r (cost=0.00..8.65 rows=200 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Subquery Scan on "*SELECT* 2" (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* 3" (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* 4" (cost=18.73..18.78 rows=2 width=4)
-> GroupAggregate (cost=18.73..18.76 rows=2 width=546)
Group Key: r_1.id
Filter: (max(build_in.inventory) > '0'::numeric)
-> Sort (cost=18.73..18.73 rows=2 width=40)
Sort Key: r_1.id
-> Hash Left Join (cost=17.66..18.72 rows=2 width=40)
Hash Cond: (r_1.id = build_out.erp_inventory_build_id)
Filter: ((build_in.erp_inventory_build_id IS NOT NULL) OR (build_out.erp_inventory_build_id IS NOT NULL))
-> Hash Left Join (cost=16.60..17.64 rows=2 width=44)
Hash Cond: (r_1.id = build_in.erp_inventory_build_id)
-> Seq Scan on tbl_erp_inventory_builds r_1 (cost=0.00..1.03 rows=2 width=8)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> Hash (cost=16.59..16.59 rows=1 width=36)
-> Subquery Scan on build_in (cost=16.56..16.59 rows=1 width=36)
-> HashAggregate (cost=16.56..16.58 rows=1 width=164)
Group Key: rp_1.erp_inventory_build_id
-> Hash Right Join (cost=1.04..15.32 rows=248 width=7)
Hash Cond: (eip_1.erp_inventory_build_product_id = rp_1.id)
-> Seq Scan on tbl_erp_inventory_products eip_1 (cost=0.00..12.97 rows=497 width=11)
-> Hash (cost=1.02..1.02 rows=1 width=8)
-> Seq Scan on tbl_erp_inventory_build_products rp_1 (cost=0.00..1.02 rows=1 width=8)
Filter: (product_id = 2177)
-> Hash (cost=1.05..1.05 rows=1 width=4)
-> Subquery Scan on build_out (cost=1.03..1.05 rows=1 width=4)
-> HashAggregate (cost=1.03..1.04 rows=1 width=68)
Group Key: tbl_erp_inventory_build_spent_products.erp_inventory_build_id
-> Seq Scan on tbl_erp_inventory_build_spent_products (cost=0.00..1.02 rows=1 width=4)
Filter: (product_id = 2177)
-> Subquery Scan on "*SELECT* 5" (cost=55.18..55.40 rows=3 width=4)
-> GroupAggregate (cost=55.18..55.37 rows=3 width=546)
Group Key: r_2.id
Filter: (max((sum(eip_2.inventory))) > '0'::numeric)
-> Merge Left Join (cost=55.18..55.32 rows=3 width=40)
Merge Cond: (r_2.id = rp_2.erp_inventory_disassemble_id)
Filter: ((rp_2.erp_inventory_disassemble_id IS NOT NULL) OR (tbl_erp_inventory_disassemble_spent_products.erp_inventory_disassemble_id IS NOT NULL))
-> Merge Left Join (cost=28.38..28.46 rows=3 width=12)
Merge Cond: (r_2.id = tbl_erp_inventory_disassemble_spent_products.erp_inventory_disassemble_id)
-> Sort (cost=12.50..12.51 rows=3 width=8)
Sort Key: r_2.id
-> Seq Scan on tbl_erp_inventory_disassembles r_2 (cost=0.00..12.47 rows=3 width=8)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> GroupAggregate (cost=15.88..15.92 rows=2 width=68)
Group Key: tbl_erp_inventory_disassemble_spent_products.erp_inventory_disassemble_id
-> Sort (cost=15.88..15.89 rows=2 width=4)
Sort Key: tbl_erp_inventory_disassemble_spent_products.erp_inventory_disassemble_id
-> Seq Scan on tbl_erp_inventory_disassemble_spent_products (cost=0.00..15.88 rows=2 width=4)
Filter: (product_id = 2177)
-> Materialize (cost=26.80..26.84 rows=1 width=36)
-> GroupAggregate (cost=26.80..26.82 rows=1 width=164)
Group Key: rp_2.erp_inventory_disassemble_id
-> Sort (cost=26.80..26.80 rows=2 width=7)
Sort Key: rp_2.erp_inventory_disassemble_id
-> Hash Right Join (cost=12.51..26.79 rows=2 width=7)
Hash Cond: (eip_2.erp_inventory_disassemble_product_id = rp_2.id)
-> Seq Scan on tbl_erp_inventory_products eip_2 (cost=0.00..12.97 rows=497 width=11)
-> Hash (cost=12.50..12.50 rows=1 width=8)
-> Seq Scan on tbl_erp_inventory_disassemble_products rp_2 (cost=0.00..12.50 rows=1 width=8)
Filter: (product_id = 2177)
-> Subquery Scan on "*SELECT* 6" (cost=18.72..18.94 rows=10 width=4)
-> HashAggregate (cost=18.72..18.84 rows=10 width=546)
Group Key: r_3.id
Filter: (sum(eip_3.inventory) > '0'::numeric)
-> Hash Join (cost=4.36..18.67 rows=10 width=11)
Hash Cond: (rp_3.erp_inventory_start_id = r_3.id)
-> Hash Right Join (cost=1.64..15.92 rows=10 width=7)
Hash Cond: (eip_3.erp_inventory_start_product_id = rp_3.id)
-> Seq Scan on tbl_erp_inventory_products eip_3 (cost=0.00..12.97 rows=497 width=11)
-> Hash (cost=1.62..1.62 rows=1 width=8)
-> Seq Scan on tbl_erp_inventory_start_products rp_3 (cost=0.00..1.62 rows=1 width=8)
Filter: (product_id = 2177)
-> Hash (cost=2.32..2.32 rows=32 width=8)
-> Seq Scan on tbl_erp_inventory_starts r_3 (cost=0.00..2.32 rows=32 width=8)
-> Subquery Scan on "*SELECT* 7" (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* 8" (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* 9" (cost=17.19..17.53 rows=15 width=4)
-> HashAggregate (cost=17.19..17.38 rows=15 width=546)
Group Key: r_4.id
Filter: (sum(eip_4.inventory) > '0'::numeric)
-> Hash Join (cost=2.71..17.07 rows=24 width=11)
Hash Cond: (rp_4.erp_purchase_gift_id = r_4.id)
-> Hash Right Join (cost=1.27..15.56 rows=24 width=7)
Hash Cond: (eip_4.erp_purchase_gift_product_id = rp_4.id)
-> Seq Scan on tbl_erp_inventory_products eip_4 (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_4 (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_4 (cost=0.00..1.25 rows=15 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Subquery Scan on "*SELECT* 10" (cost=27.49..27.62 rows=3 width=4)
-> GroupAggregate (cost=27.49..27.59 rows=3 width=546)
Group Key: r_5.id
Filter: (sum(eip_5.inventory) > '0'::numeric)
-> Merge Join (cost=27.49..27.54 rows=3 width=11)
Merge Cond: (rp_5.erp_inventory_overflow_id = r_5.id)
-> Sort (cost=26.33..26.34 rows=3 width=7)
Sort Key: rp_5.erp_inventory_overflow_id
-> Hash Right Join (cost=12.01..26.31 rows=3 width=7)
Hash Cond: (eip_5.erp_inventory_overflow_product_id = rp_5.id)
-> Seq Scan on tbl_erp_inventory_products eip_5 (cost=0.00..12.97 rows=497 width=11)
-> Hash (cost=12.00..12.00 rows=1 width=8)
-> Seq Scan on tbl_erp_inventory_overflow_products rp_5 (cost=0.00..12.00 rows=1 width=8)
Filter: (product_id = 2177)
-> Sort (cost=1.16..1.17 rows=5 width=8)
Sort Key: r_5.id
-> Seq Scan on tbl_erp_inventory_overflows r_5 (cost=0.00..1.10 rows=5 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Subquery Scan on "*SELECT* 11" (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