QUERY PLAN
Aggregate (cost=259.87..259.88 rows=1 width=8)
-> Sort (cost=258.74..258.93 rows=75 width=546)
Sort Key: sub.wrote_date DESC
-> Result (cost=38.68..256.40 rows=75 width=546)
-> Append (cost=38.68..255.65 rows=75 width=4)
-> Subquery Scan on sub (cost=38.68..38.91 rows=9 width=4)
-> GroupAggregate (cost=38.68..38.82 rows=9 width=546)
Group Key: r.id
-> Sort (cost=38.68..38.71 rows=9 width=8)
Sort Key: r.id
-> Hash Join (cost=22.80..38.54 rows=9 width=8)
Hash Cond: (rp.erp_purchase_inbound_id = r.id)
-> Hash Right Join (cost=12.62..28.34 rows=10 width=4)
Hash Cond: (eip.erp_purchase_inbound_product_id = rp.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..14.31 rows=531 width=8)
-> Hash (cost=12.50..12.50 rows=10 width=8)
-> Seq Scan on tbl_erp_purchase_inbound_products rp (cost=0.00..12.50 rows=10 width=8)
Filter: (product_id = 2177)
-> Hash (cost=7.66..7.66 rows=201 width=8)
-> Seq Scan on tbl_erp_purchase_inbounds r (cost=0.00..7.66 rows=201 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Subquery Scan on "*SELECT* 2" (cost=10.49..26.27 rows=1 width=4)
-> GroupAggregate (cost=10.49..26.26 rows=1 width=546)
Group Key: r_1.id
-> Nested Loop Left Join (cost=10.49..26.25 rows=1 width=8)
-> Merge Join (cost=2.18..2.22 rows=1 width=12)
Merge Cond: (r_1.id = rp_1.erp_purchase_return_id)
-> Sort (cost=1.10..1.11 rows=3 width=8)
Sort Key: r_1.id
-> Seq Scan on tbl_erp_purchase_returns r_1 (cost=0.00..1.07 rows=3 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Sort (cost=1.08..1.09 rows=1 width=8)
Sort Key: rp_1.erp_purchase_return_id
-> Seq Scan on tbl_erp_purchase_return_products rp_1 (cost=0.00..1.07 rows=1 width=8)
Filter: (product_id = 2177)
-> Hash Right Join (cost=8.30..24.02 rows=1 width=4)
Hash Cond: (eip_1.erp_purchase_inbound_product_id = epip.id)
-> Seq Scan on tbl_erp_inventory_products eip_1 (cost=0.00..14.31 rows=531 width=8)
-> Hash (cost=8.29..8.29 rows=1 width=4)
-> Index Only Scan using tbl_erp_purchase_inbound_products_pkey on tbl_erp_purchase_inbound_products epip (cost=0.28..8.29 rows=1 width=4)
Index Cond: (id = rp_1.erp_purchase_inbound_product_id)
-> Subquery Scan on "*SELECT* 3" (cost=2.42..2.45 rows=1 width=4)
-> GroupAggregate (cost=2.42..2.44 rows=1 width=546)
Group Key: r_2.id
-> Sort (cost=2.42..2.42 rows=1 width=8)
Sort Key: r_2.id
-> Hash Join (cost=1.25..2.41 rows=1 width=8)
Hash Cond: (r_2.id = rp_2.erp_inventory_lost_id)
-> Seq Scan on tbl_erp_inventory_losts r_2 (cost=0.00..1.12 rows=7 width=8)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> Hash (cost=1.24..1.24 rows=1 width=8)
-> Seq Scan on tbl_erp_inventory_lost_products rp_2 (cost=0.00..1.24 rows=1 width=8)
Filter: (product_id = 2177)
-> Subquery Scan on "*SELECT* 4" (cost=19.60..19.85 rows=10 width=4)
-> GroupAggregate (cost=19.60..19.75 rows=10 width=546)
Group Key: r_3.id
-> Sort (cost=19.60..19.62 rows=10 width=8)
Sort Key: r_3.id
-> Hash Left Join (cost=18.19..19.43 rows=10 width=8)
Hash Cond: (r_3.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=17.01..18.21 rows=10 width=12)
Hash Cond: (r_3.id = build_in.erp_inventory_build_id)
-> Seq Scan on tbl_erp_inventory_builds r_3 (cost=0.00..1.17 rows=10 width=8)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> Hash (cost=16.99..16.99 rows=1 width=4)
-> Subquery Scan on build_in (cost=16.97..16.99 rows=1 width=4)
-> HashAggregate (cost=16.97..16.98 rows=1 width=164)
Group Key: rp_3.erp_inventory_build_id
-> Hash Right Join (cost=1.15..16.85 rows=48 width=4)
Hash Cond: (eip_2.erp_inventory_build_product_id = rp_3.id)
-> Seq Scan on tbl_erp_inventory_products eip_2 (cost=0.00..14.31 rows=531 width=8)
-> Hash (cost=1.14..1.14 rows=1 width=8)
-> Seq Scan on tbl_erp_inventory_build_products rp_3 (cost=0.00..1.14 rows=1 width=8)
Filter: (product_id = 2177)
-> 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 = 2177)
-> Subquery Scan on "*SELECT* 5" (cost=19.25..19.35 rows=4 width=4)
-> GroupAggregate (cost=19.25..19.31 rows=4 width=546)
Group Key: r_4.id
-> Sort (cost=19.25..19.26 rows=4 width=8)
Sort Key: r_4.id
-> Hash Left Join (cost=18.10..19.21 rows=4 width=8)
Hash Cond: (r_4.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=17.01..18.10 rows=4 width=12)
Hash Cond: (r_4.id = disassemble_in.erp_inventory_disassemble_id)
-> Seq Scan on tbl_erp_inventory_disassembles r_4 (cost=0.00..1.07 rows=4 width=8)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> Hash (cost=17.00..17.00 rows=1 width=4)
-> Subquery Scan on disassemble_in (cost=16.98..17.00 rows=1 width=4)
-> HashAggregate (cost=16.98..16.99 rows=1 width=164)
Group Key: rp_4.erp_inventory_disassemble_id
-> Hash Right Join (cost=1.11..16.82 rows=66 width=4)
Hash Cond: (eip_3.erp_inventory_disassemble_product_id = rp_4.id)
-> Seq Scan on tbl_erp_inventory_products eip_3 (cost=0.00..14.31 rows=531 width=8)
-> Hash (cost=1.10..1.10 rows=1 width=8)
-> Seq Scan on tbl_erp_inventory_disassemble_products rp_4 (cost=0.00..1.10 rows=1 width=8)
Filter: (product_id = 2177)
-> 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 = 2177)
-> Subquery Scan on "*SELECT* 6" (cost=55.66..55.87 rows=3 width=4)
-> GroupAggregate (cost=55.66..55.84 rows=3 width=546)
Group Key: r_5.id
-> Merge Left Join (cost=55.66..55.80 rows=3 width=8)
Merge Cond: (r_5.id = rp_5.erp_inventory_transfer_id)
Filter: ((rp_5.erp_inventory_transfer_id IS NOT NULL) OR (tbl_erp_inventory_transfer_spent_products.erp_inventory_transfer_id IS NOT NULL))
-> Merge Left Join (cost=28.00..28.08 rows=3 width=12)
Merge Cond: (r_5.id = tbl_erp_inventory_transfer_spent_products.erp_inventory_transfer_id)
-> Sort (cost=12.36..12.37 rows=3 width=8)
Sort Key: r_5.id
-> Seq Scan on tbl_erp_inventory_transfers r_5 (cost=0.00..12.34 rows=3 width=8)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> GroupAggregate (cost=15.63..15.67 rows=2 width=68)
Group Key: tbl_erp_inventory_transfer_spent_products.erp_inventory_transfer_id
-> Sort (cost=15.63..15.64 rows=2 width=4)
Sort Key: tbl_erp_inventory_transfer_spent_products.erp_inventory_transfer_id
-> Seq Scan on tbl_erp_inventory_transfer_spent_products (cost=0.00..15.62 rows=2 width=4)
Filter: (product_id = 2177)
-> Materialize (cost=27.66..27.71 rows=1 width=4)
-> GroupAggregate (cost=27.66..27.69 rows=1 width=164)
Group Key: rp_5.erp_inventory_transfer_id
-> Sort (cost=27.66..27.67 rows=4 width=4)
Sort Key: rp_5.erp_inventory_transfer_id
-> Hash Right Join (cost=11.89..27.62 rows=4 width=4)
Hash Cond: (eip_4.erp_inventory_transfer_product_id = rp_5.id)
-> Seq Scan on tbl_erp_inventory_products eip_4 (cost=0.00..14.31 rows=531 width=8)
-> Hash (cost=11.88..11.88 rows=1 width=8)
-> Seq Scan on tbl_erp_inventory_transfer_products rp_5 (cost=0.00..11.88 rows=1 width=8)
Filter: (product_id = 2177)
-> Subquery Scan on "*SELECT* 7" (cost=19.13..19.35 rows=11 width=4)
-> HashAggregate (cost=19.13..19.24 rows=11 width=546)
Group Key: r_6.id
-> Hash Join (cost=3.36..19.10 rows=11 width=8)
Hash Cond: (rp_6.erp_inventory_start_id = r_6.id)
-> Hash Right Join (cost=1.64..17.35 rows=11 width=4)
Hash Cond: (eip_5.erp_inventory_start_product_id = rp_6.id)
-> Seq Scan on tbl_erp_inventory_products eip_5 (cost=0.00..14.31 rows=531 width=8)
-> Hash (cost=1.62..1.62 rows=1 width=8)
-> Seq Scan on tbl_erp_inventory_start_products rp_6 (cost=0.00..1.62 rows=1 width=8)
Filter: (product_id = 2177)
-> Hash (cost=1.32..1.32 rows=32 width=8)
-> Seq Scan on tbl_erp_inventory_starts r_6 (cost=0.00..1.32 rows=32 width=8)
-> Subquery Scan on "*SELECT* 8" (cost=21.71..21.99 rows=14 width=4)
-> HashAggregate (cost=21.71..21.85 rows=14 width=546)
Group Key: r_7.id
-> Hash Join (cost=9.96..21.68 rows=14 width=8)
Hash Cond: (rp_7.erp_sales_outbound_id = r_7.id)
-> Seq Scan on tbl_erp_sales_outbound_spent_products rp_7 (cost=0.00..11.68 rows=14 width=8)
Filter: (product_id = 2177)
-> Hash (cost=7.64..7.64 rows=186 width=8)
-> Seq Scan on tbl_erp_sales_outbounds r_7 (cost=0.00..7.64 rows=186 width=8)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> Subquery Scan on "*SELECT* 9" (cost=2.21..2.24 rows=1 width=4)
-> GroupAggregate (cost=2.21..2.23 rows=1 width=546)
Group Key: r_8.id
-> Sort (cost=2.21..2.21 rows=1 width=8)
Sort Key: r_8.id
-> Nested Loop (cost=0.00..2.20 rows=1 width=8)
Join Filter: (r_8.id = rp_8.erp_sales_return_id)
-> Seq Scan on tbl_erp_sales_return_products rp_8 (cost=0.00..1.07 rows=1 width=8)
Filter: (product_id = 2177)
-> Seq Scan on tbl_erp_sales_returns r_8 (cost=0.00..1.07 rows=4 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Subquery Scan on "*SELECT* 10" (cost=18.79..19.07 rows=14 width=4)
-> HashAggregate (cost=18.79..18.93 rows=14 width=546)
Group Key: r_9.id
-> Hash Join (cost=2.99..18.75 rows=14 width=8)
Hash Cond: (rp_9.erp_purchase_gift_id = r_9.id)
-> Hash Right Join (cost=1.50..17.22 rows=14 width=4)
Hash Cond: (eip_6.erp_purchase_gift_product_id = rp_9.id)
-> Seq Scan on tbl_erp_inventory_products eip_6 (cost=0.00..14.31 rows=531 width=8)
-> Hash (cost=1.49..1.49 rows=1 width=8)
-> Seq Scan on tbl_erp_purchase_gift_products rp_9 (cost=0.00..1.49 rows=1 width=8)
Filter: (product_id = 2177)
-> Hash (cost=1.27..1.27 rows=17 width=8)
-> Seq Scan on tbl_erp_purchase_gifts r_9 (cost=0.00..1.27 rows=17 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Subquery Scan on "*SELECT* 11" (cost=19.17..19.29 rows=6 width=4)
-> HashAggregate (cost=19.17..19.23 rows=6 width=546)
Group Key: r_10.id
-> Hash Right Join (cost=2.45..18.79 rows=152 width=8)
Hash Cond: (eip_7.erp_inventory_overflow_product_id = rp_10.id)
-> Seq Scan on tbl_erp_inventory_products eip_7 (cost=0.00..14.31 rows=531 width=8)
-> Hash (cost=2.40..2.40 rows=4 width=12)
-> Hash Join (cost=1.20..2.40 rows=4 width=12)
Hash Cond: (rp_10.erp_inventory_overflow_id = r_10.id)
-> Seq Scan on tbl_erp_inventory_overflow_products rp_10 (cost=0.00..1.18 rows=7 width=8)
Filter: (product_id = 2177)
-> Hash (cost=1.12..1.12 rows=6 width=8)
-> Seq Scan on tbl_erp_inventory_overflows r_10 (cost=0.00..1.12 rows=6 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Subquery Scan on "*SELECT* 12" (cost=11.00..11.03 rows=1 width=4)
-> GroupAggregate (cost=11.00..11.02 rows=1 width=546)
Group Key: r_11.id
-> Sort (cost=11.00..11.01 rows=1 width=8)
Sort Key: r_11.id
-> Hash Join (cost=4.00..10.99 rows=1 width=8)
Hash Cond: (r_11.id = rp_11.erp_sales_gift_id)
-> Seq Scan on tbl_erp_sales_gifts r_11 (cost=0.00..6.37 rows=165 width=8)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> Hash (cost=3.99..3.99 rows=1 width=8)
-> Seq Scan on tbl_erp_sales_gift_spent_products rp_11 (cost=0.00..3.99 rows=1 width=8)
Filter: (product_id = 2177)