QUERY PLAN
Limit (cost=119.29..119.34 rows=18 width=419)
-> Sort (cost=119.29..119.34 rows=18 width=419)
Sort Key: r.wrote_date DESC
-> Append (cost=37.53..118.92 rows=18 width=419)
-> GroupAggregate (cost=37.53..37.59 rows=1 width=407)
Group Key: r.id
Filter: (sum(eip.inventory) > '0'::numeric)
-> Sort (cost=37.53..37.53 rows=1 width=102)
Sort Key: r.id
-> Nested Loop Left Join (cost=0.14..37.52 rows=1 width=102)
Join Filter: (eip.erp_store_id = s.id)
-> Nested Loop (cost=0.14..36.48 rows=1 width=95)
Join Filter: (rp.id = eip.erp_purchase_inbound_product_id)
-> Nested Loop (cost=0.14..20.74 rows=1 width=92)
-> Seq Scan on tbl_erp_purchase_inbound_products rp (cost=0.00..12.50 rows=1 width=29)
Filter: (product_id = 2265)
-> Index Scan using tbl_erp_purchase_inbounds_pkey on tbl_erp_purchase_inbounds r (cost=0.14..8.16 rows=1 width=67)
Index Cond: (id = rp.erp_purchase_inbound_id)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..15.64 rows=8 width=11)
Filter: (erp_store_id = 2)
-> Seq Scan on tbl_erp_stores s (cost=0.00..1.02 rows=1 width=15)
Filter: (id = 2)
-> GroupAggregate (cost=20.49..21.00 rows=10 width=401)
Group Key: r_1.id
Filter: (max((sum(eip_1.inventory))) > '0'::numeric)
-> Merge Left Join (cost=20.49..20.60 rows=10 width=285)
Merge Cond: (r_1.id = rp_1.erp_inventory_build_id)
Filter: ((rp_1.erp_inventory_build_id IS NOT NULL) OR (build_out.erp_inventory_build_id IS NOT NULL))
-> Sort (cost=2.56..2.59 rows=10 width=129)
Sort Key: r_1.id
-> Hash Left Join (cost=1.19..2.40 rows=10 width=129)
Hash Cond: (r_1.id = build_out.erp_inventory_build_id)
-> Seq Scan on tbl_erp_inventory_builds r_1 (cost=0.00..1.17 rows=10 width=61)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> Hash (cost=1.18..1.18 rows=1 width=68)
-> Subquery Scan on build_out (cost=1.16..1.18 rows=1 width=68)
-> HashAggregate (cost=1.16..1.17 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=14)
Filter: (product_id = 2265)
-> Materialize (cost=17.92..17.98 rows=1 width=164)
-> GroupAggregate (cost=17.92..17.96 rows=1 width=164)
Group Key: rp_1.erp_inventory_build_id
-> Sort (cost=17.92..17.93 rows=1 width=32)
Sort Key: rp_1.erp_inventory_build_id
-> Nested Loop Left Join (cost=0.00..17.91 rows=1 width=32)
Join Filter: (eip_1.erp_store_id = s_1.id)
-> Nested Loop (cost=0.00..16.88 rows=1 width=25)
Join Filter: (rp_1.id = eip_1.erp_inventory_build_product_id)
-> Seq Scan on tbl_erp_inventory_build_products rp_1 (cost=0.00..1.14 rows=1 width=8)
Filter: (product_id = 2265)
-> Seq Scan on tbl_erp_inventory_products eip_1 (cost=0.00..15.64 rows=8 width=25)
Filter: (erp_store_id = 2)
-> Seq Scan on tbl_erp_stores s_1 (cost=0.00..1.02 rows=1 width=15)
Filter: (id = 2)
-> GroupAggregate (cost=20.11..20.36 rows=4 width=456)
Group Key: r_2.id
Filter: (max((sum(eip_2.inventory))) > '0'::numeric)
-> Merge Left Join (cost=20.11..20.20 rows=4 width=340)
Merge Cond: (r_2.id = rp_2.erp_inventory_disassemble_id)
Filter: ((rp_2.erp_inventory_disassemble_id IS NOT NULL) OR (disassemble_out.erp_inventory_disassemble_id IS NOT NULL))
-> Sort (cost=2.23..2.24 rows=4 width=184)
Sort Key: r_2.id
-> Hash Left Join (cost=1.09..2.19 rows=4 width=184)
Hash Cond: (r_2.id = disassemble_out.erp_inventory_disassemble_id)
-> Seq Scan on tbl_erp_inventory_disassembles r_2 (cost=0.00..1.07 rows=4 width=116)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> Hash (cost=1.08..1.08 rows=1 width=68)
-> Subquery Scan on disassemble_out (cost=1.06..1.08 rows=1 width=68)
-> HashAggregate (cost=1.06..1.07 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=14)
Filter: (product_id = 2265)
-> Materialize (cost=17.89..17.94 rows=1 width=164)
-> GroupAggregate (cost=17.89..17.93 rows=1 width=164)
Group Key: rp_2.erp_inventory_disassemble_id
-> Sort (cost=17.89..17.89 rows=1 width=32)
Sort Key: rp_2.erp_inventory_disassemble_id
-> Nested Loop Left Join (cost=0.00..17.88 rows=1 width=32)
Join Filter: (eip_2.erp_store_id = s_2.id)
-> Nested Loop (cost=0.00..16.84 rows=1 width=25)
Join Filter: (rp_2.id = eip_2.erp_inventory_disassemble_product_id)
-> Seq Scan on tbl_erp_inventory_disassemble_products rp_2 (cost=0.00..1.10 rows=1 width=8)
Filter: (product_id = 2265)
-> Seq Scan on tbl_erp_inventory_products eip_2 (cost=0.00..15.64 rows=8 width=25)
Filter: (erp_store_id = 2)
-> Seq Scan on tbl_erp_stores s_2 (cost=0.00..1.02 rows=1 width=15)
Filter: (id = 2)
-> GroupAggregate (cost=19.87..19.93 rows=1 width=427)
Group Key: r_3.id
Filter: (sum(eip_3.inventory) > '0'::numeric)
-> Sort (cost=19.87..19.88 rows=1 width=144)
Sort Key: r_3.id
-> Nested Loop Left Join (cost=1.64..19.86 rows=1 width=144)
Join Filter: (eip_3.erp_store_id = s_3.id)
-> Nested Loop (cost=1.64..18.82 rows=1 width=137)
Join Filter: (rp_3.id = eip_3.erp_inventory_start_product_id)
-> Hash Join (cost=1.64..3.09 rows=1 width=134)
Hash Cond: (r_3.id = rp_3.erp_inventory_start_id)
-> Seq Scan on tbl_erp_inventory_starts r_3 (cost=0.00..1.32 rows=32 width=83)
-> Hash (cost=1.62..1.62 rows=1 width=55)
-> Seq Scan on tbl_erp_inventory_start_products rp_3 (cost=0.00..1.62 rows=1 width=55)
Filter: (product_id = 2265)
-> Seq Scan on tbl_erp_inventory_products eip_3 (cost=0.00..15.64 rows=8 width=11)
Filter: (erp_store_id = 2)
-> Seq Scan on tbl_erp_stores s_3 (cost=0.00..1.02 rows=1 width=15)
Filter: (id = 2)
-> GroupAggregate (cost=0.01..0.04 rows=1 width=481)
Group Key: id
-> Sort (cost=0.01..0.02 rows=0 width=163)
Sort Key: id
-> Result (cost=0.00..0.00 rows=0 width=163)
One-Time Filter: false
-> GroupAggregate (cost=19.76..19.82 rows=1 width=409)
Group Key: r_4.id
Filter: (sum(eip_4.inventory) > '0'::numeric)
-> Sort (cost=19.76..19.76 rows=1 width=97)
Sort Key: r_4.id
-> Nested Loop Left Join (cost=0.00..19.75 rows=1 width=97)
Join Filter: (eip_4.erp_store_id = s_4.id)
-> Nested Loop (cost=0.00..18.71 rows=1 width=90)
Join Filter: (rp_4.erp_purchase_gift_id = r_4.id)
-> Nested Loop (cost=0.00..17.23 rows=1 width=25)
Join Filter: (rp_4.id = eip_4.erp_purchase_gift_product_id)
-> Seq Scan on tbl_erp_purchase_gift_products rp_4 (cost=0.00..1.49 rows=1 width=8)
Filter: (product_id = 2265)
-> Seq Scan on tbl_erp_inventory_products eip_4 (cost=0.00..15.64 rows=8 width=25)
Filter: (erp_store_id = 2)
-> Seq Scan on tbl_erp_purchase_gifts r_4 (cost=0.00..1.27 rows=17 width=69)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Seq Scan on tbl_erp_stores s_4 (cost=0.00..1.02 rows=1 width=15)
Filter: (id = 2)