QUERY PLAN
Aggregate (cost=110.83..110.84 rows=1 width=8)
-> Sort (cost=110.17..110.28 rows=44 width=546)
Sort Key: sub.wrote_date DESC
-> Result (cost=35.71..108.97 rows=44 width=546)
-> Append (cost=35.71..108.53 rows=44 width=4)
-> Subquery Scan on sub (cost=35.71..35.77 rows=2 width=4)
-> GroupAggregate (cost=35.71..35.75 rows=2 width=546)
Group Key: r.id
Filter: (sum(eip.inventory) > '0'::numeric)
-> Sort (cost=35.71..35.71 rows=2 width=11)
Sort Key: r.id
-> Hash Join (cost=27.01..35.70 rows=2 width=11)
Hash Cond: (r.id = rp.erp_purchase_inbound_id)
-> Seq Scan on tbl_erp_purchase_inbounds r (cost=0.00..7.66 rows=201 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Hash (cost=26.99..26.99 rows=2 width=7)
-> Hash Right Join (cost=12.53..26.99 rows=2 width=7)
Hash Cond: (eip.erp_purchase_inbound_product_id = rp.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..13.11 rows=511 width=11)
-> Hash (cost=12.50..12.50 rows=2 width=8)
-> Seq Scan on tbl_erp_purchase_inbound_products rp (cost=0.00..12.50 rows=2 width=8)
Filter: (product_id = 1562)
-> Subquery Scan on "*SELECT* 2" (cost=18.34..18.54 rows=10 width=4)
-> HashAggregate (cost=18.34..18.44 rows=10 width=546)
Group Key: r_1.id
Filter: (max(build_in.inventory) > '0'::numeric)
-> Hash Left Join (cost=17.05..18.29 rows=10 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=15.87..17.07 rows=10 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.17 rows=10 width=8)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> Hash (cost=15.85..15.85 rows=1 width=36)
-> Subquery Scan on build_in (cost=15.83..15.85 rows=1 width=36)
-> HashAggregate (cost=15.83..15.84 rows=1 width=164)
Group Key: rp_1.erp_inventory_build_id
-> Hash Right Join (cost=1.15..15.60 rows=46 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..13.11 rows=511 width=11)
-> Hash (cost=1.14..1.14 rows=1 width=8)
-> Seq Scan on tbl_erp_inventory_build_products rp_1 (cost=0.00..1.14 rows=1 width=8)
Filter: (product_id = 1562)
-> Hash (cost=1.17..1.17 rows=1 width=4)
-> Subquery Scan on build_out (cost=1.15..1.17 rows=1 width=4)
-> HashAggregate (cost=1.15..1.16 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.15 rows=1 width=4)
Filter: (product_id = 1562)
-> Subquery Scan on "*SELECT* 3" (cost=18.16..18.27 rows=4 width=4)
-> GroupAggregate (cost=18.16..18.23 rows=4 width=546)
Group Key: r_2.id
Filter: (max(disassemble_in.inventory) > '0'::numeric)
-> Sort (cost=18.16..18.17 rows=4 width=40)
Sort Key: r_2.id
-> Hash Left Join (cost=17.00..18.12 rows=4 width=40)
Hash Cond: (r_2.id = disassemble_out.erp_inventory_disassemble_id)
Filter: ((disassemble_in.erp_inventory_disassemble_id IS NOT NULL) OR (disassemble_out.erp_inventory_disassemble_id IS NOT NULL))
-> Hash Left Join (cost=15.92..17.01 rows=4 width=44)
Hash Cond: (r_2.id = disassemble_in.erp_inventory_disassemble_id)
-> Seq Scan on tbl_erp_inventory_disassembles r_2 (cost=0.00..1.07 rows=4 width=8)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> Hash (cost=15.91..15.91 rows=1 width=36)
-> Subquery Scan on disassemble_in (cost=15.88..15.91 rows=1 width=36)
-> HashAggregate (cost=15.88..15.90 rows=1 width=164)
Group Key: rp_2.erp_inventory_disassemble_id
-> Hash Right Join (cost=1.11..15.56 rows=64 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..13.11 rows=511 width=11)
-> Hash (cost=1.10..1.10 rows=1 width=8)
-> Seq Scan on tbl_erp_inventory_disassemble_products rp_2 (cost=0.00..1.10 rows=1 width=8)
Filter: (product_id = 1562)
-> Hash (cost=1.07..1.07 rows=1 width=4)
-> Subquery Scan on disassemble_out (cost=1.05..1.07 rows=1 width=4)
-> HashAggregate (cost=1.05..1.06 rows=1 width=68)
Group Key: tbl_erp_inventory_disassemble_spent_products.erp_inventory_disassemble_id
-> Seq Scan on tbl_erp_inventory_disassemble_spent_products (cost=0.00..1.05 rows=1 width=4)
Filter: (product_id = 1562)
-> Subquery Scan on "*SELECT* 4" (cost=17.90..18.12 rows=10 width=4)
-> HashAggregate (cost=17.90..18.02 rows=10 width=546)
Group Key: r_3.id
Filter: (sum(eip_3.inventory) > '0'::numeric)
-> Hash Join (cost=3.36..17.85 rows=10 width=11)
Hash Cond: (rp_3.erp_inventory_start_id = r_3.id)
-> Hash Right Join (cost=1.64..16.10 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..13.11 rows=511 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 = 1562)
-> Hash (cost=1.32..1.32 rows=32 width=8)
-> Seq Scan on tbl_erp_inventory_starts r_3 (cost=0.00..1.32 rows=32 width=8)
-> Subquery Scan on "*SELECT* 5" (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* 6" (cost=17.43..17.81 rows=17 width=4)
-> HashAggregate (cost=17.43..17.64 rows=17 width=546)
Group Key: r_4.id
Filter: (sum(eip_4.inventory) > '0'::numeric)
-> Hash Join (cost=2.79..17.32 rows=22 width=11)
Hash Cond: (rp_4.erp_purchase_gift_id = r_4.id)
-> Hash Right Join (cost=1.30..15.76 rows=22 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..13.11 rows=511 width=11)
-> Hash (cost=1.29..1.29 rows=1 width=8)
-> Seq Scan on tbl_erp_purchase_gift_products rp_4 (cost=0.00..1.29 rows=1 width=8)
Filter: (product_id = 1562)
-> Hash (cost=1.27..1.27 rows=17 width=8)
-> Seq Scan on tbl_erp_purchase_gifts r_4 (cost=0.00..1.27 rows=17 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))