QUERY PLAN
Aggregate (cost=272.86..272.87 rows=1 width=8)
-> Sort (cost=271.61..271.82 rows=83 width=546)
Sort Key: sub.wrote_date DESC
-> Result (cost=38.01..268.97 rows=83 width=546)
-> Append (cost=38.01..268.14 rows=83 width=4)
-> Subquery Scan on sub (cost=38.01..38.23 rows=9 width=4)
-> GroupAggregate (cost=38.01..38.14 rows=9 width=546)
Group Key: r.id
-> Sort (cost=38.01..38.03 rows=9 width=8)
Sort Key: r.id
-> Hash Join (cost=21.89..37.87 rows=9 width=8)
Hash Cond: (rp.erp_purchase_inbound_id = r.id)
-> Hash Right Join (cost=11.60..27.55 rows=9 width=4)
Hash Cond: (eip.erp_purchase_inbound_product_id = rp.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..14.50 rows=550 width=8)
-> Hash (cost=11.51..11.51 rows=7 width=8)
-> Seq Scan on tbl_erp_purchase_inbound_products rp (cost=0.00..11.51 rows=7 width=8)
Filter: (product_id = 2261)
-> Hash (cost=7.72..7.72 rows=205 width=8)
-> Seq Scan on tbl_erp_purchase_inbounds r (cost=0.00..7.72 rows=205 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Subquery Scan on "*SELECT* 2" (cost=10.49..26.51 rows=1 width=4)
-> GroupAggregate (cost=10.49..26.50 rows=1 width=546)
Group Key: r_1.id
-> Nested Loop Left Join (cost=10.49..26.48 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 = 2261)
-> Hash Right Join (cost=8.30..24.26 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.50 rows=550 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.27..8.29 rows=1 width=4)
Index Cond: (id = rp_1.erp_purchase_inbound_product_id)
-> Subquery Scan on "*SELECT* 3" (cost=2.47..2.52 rows=2 width=4)
-> GroupAggregate (cost=2.47..2.50 rows=2 width=546)
Group Key: r_2.id
-> Sort (cost=2.47..2.47 rows=2 width=8)
Sort Key: r_2.id
-> Hash Join (cost=1.21..2.46 rows=2 width=8)
Hash Cond: (rp_2.erp_inventory_lost_id = r_2.id)
-> Seq Scan on tbl_erp_inventory_lost_products rp_2 (cost=0.00..1.24 rows=3 width=8)
Filter: (product_id = 2261)
-> Hash (cost=1.12..1.12 rows=7 width=8)
-> 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[]))
-> Subquery Scan on "*SELECT* 4" (cost=20.09..20.34 rows=10 width=4)
-> GroupAggregate (cost=20.09..20.24 rows=10 width=546)
Group Key: r_3.id
-> Sort (cost=20.09..20.12 rows=10 width=8)
Sort Key: r_3.id
-> Hash Left Join (cost=18.69..19.93 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.43..18.63 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=17.41..17.41 rows=2 width=4)
-> Subquery Scan on build_in (cost=17.37..17.41 rows=2 width=4)
-> HashAggregate (cost=17.37..17.39 rows=2 width=164)
Group Key: rp_3.erp_inventory_build_id
-> Hash Right Join (cost=1.16..17.12 rows=100 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.50 rows=550 width=8)
-> Hash (cost=1.14..1.14 rows=2 width=8)
-> Seq Scan on tbl_erp_inventory_build_products rp_3 (cost=0.00..1.14 rows=2 width=8)
Filter: (product_id = 2261)
-> Hash (cost=1.22..1.22 rows=3 width=4)
-> Subquery Scan on build_out (cost=1.16..1.22 rows=3 width=4)
-> HashAggregate (cost=1.16..1.19 rows=3 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=3 width=4)
Filter: (product_id = 2261)
-> Subquery Scan on "*SELECT* 5" (cost=19.94..20.04 rows=4 width=4)
-> GroupAggregate (cost=19.94..20.00 rows=4 width=546)
Group Key: r_4.id
-> Sort (cost=19.94..19.95 rows=4 width=8)
Sort Key: r_4.id
-> Hash Left Join (cost=18.79..19.90 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.70..18.80 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.67..17.67 rows=3 width=4)
-> Subquery Scan on disassemble_in (cost=17.61..17.67 rows=3 width=4)
-> HashAggregate (cost=17.61..17.64 rows=3 width=164)
Group Key: rp_4.erp_inventory_disassemble_id
-> Hash Right Join (cost=1.14..17.09 rows=206 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.50 rows=550 width=8)
-> Hash (cost=1.10..1.10 rows=3 width=8)
-> Seq Scan on tbl_erp_inventory_disassemble_products rp_4 (cost=0.00..1.10 rows=3 width=8)
Filter: (product_id = 2261)
-> 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 = 2261)
-> Subquery Scan on "*SELECT* 6" (cost=55.87..56.08 rows=3 width=4)
-> GroupAggregate (cost=55.87..56.05 rows=3 width=546)
Group Key: r_5.id
-> Merge Left Join (cost=55.87..56.01 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 = 2261)
-> Materialize (cost=27.87..27.91 rows=1 width=4)
-> GroupAggregate (cost=27.87..27.90 rows=1 width=164)
Group Key: rp_5.erp_inventory_transfer_id
-> Sort (cost=27.87..27.88 rows=4 width=4)
Sort Key: rp_5.erp_inventory_transfer_id
-> Hash Right Join (cost=11.89..27.83 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.50 rows=550 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 = 2261)
-> Subquery Scan on "*SELECT* 7" (cost=19.37..19.59 rows=11 width=4)
-> HashAggregate (cost=19.37..19.48 rows=11 width=546)
Group Key: r_6.id
-> Hash Join (cost=3.36..19.34 rows=11 width=8)
Hash Cond: (rp_6.erp_inventory_start_id = r_6.id)
-> Hash Right Join (cost=1.64..17.59 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.50 rows=550 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 = 2261)
-> 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=32.31..32.71 rows=20 width=4)
-> HashAggregate (cost=32.31..32.51 rows=20 width=546)
Group Key: r_7.id
-> Nested Loop (cost=16.28..32.26 rows=20 width=8)
-> Hash Join (cost=16.14..27.89 rows=20 width=4)
Hash Cond: (rp_7.erp_inventory_product_id = eip_6.id)
-> Seq Scan on tbl_erp_sales_outbound_spent_products rp_7 (cost=0.00..10.34 rows=534 width=8)
-> Hash (cost=15.88..15.88 rows=21 width=8)
-> Seq Scan on tbl_erp_inventory_products eip_6 (cost=0.00..15.88 rows=21 width=8)
Filter: (product_id = 2261)
-> Index Scan using tbl_erp_sales_outbounds_pkey on tbl_erp_sales_outbounds r_7 (cost=0.14..0.22 rows=1 width=8)
Index Cond: (id = rp_7.erp_sales_outbound_id)
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
-> Hash Join (cost=1.10..2.20 rows=1 width=8)
Hash Cond: (r_8.id = rp_8.erp_sales_return_id)
-> Seq Scan on tbl_erp_sales_returns r_8 (cost=0.00..1.07 rows=4 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Hash (cost=1.07..1.07 rows=2 width=8)
-> Seq Scan on tbl_erp_sales_return_products rp_8 (cost=0.00..1.07 rows=2 width=8)
Filter: (product_id = 2261)
-> Subquery Scan on "*SELECT* 10" (cost=19.03..19.31 rows=14 width=4)
-> HashAggregate (cost=19.03..19.17 rows=14 width=546)
Group Key: r_9.id
-> Hash Join (cost=2.99..18.99 rows=14 width=8)
Hash Cond: (rp_9.erp_purchase_gift_id = r_9.id)
-> Hash Right Join (cost=1.50..17.45 rows=14 width=4)
Hash Cond: (eip_7.erp_purchase_gift_product_id = rp_9.id)
-> Seq Scan on tbl_erp_inventory_products eip_7 (cost=0.00..14.50 rows=550 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 = 2261)
-> 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 Join (cost=2.43..18.97 rows=79 width=8)
Hash Cond: (rp_10.erp_inventory_overflow_id = r_10.id)
-> Hash Right Join (cost=1.23..17.18 rows=157 width=4)
Hash Cond: (eip_8.erp_inventory_overflow_product_id = rp_10.id)
-> Seq Scan on tbl_erp_inventory_products eip_8 (cost=0.00..14.50 rows=550 width=8)
-> Hash (cost=1.18..1.18 rows=4 width=8)
-> Seq Scan on tbl_erp_inventory_overflow_products rp_10 (cost=0.00..1.18 rows=4 width=8)
Filter: (product_id = 2261)
-> 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.23..11.28 rows=2 width=4)
-> GroupAggregate (cost=11.23..11.26 rows=2 width=546)
Group Key: r_11.id
-> Sort (cost=11.23..11.24 rows=2 width=8)
Sort Key: r_11.id
-> Hash Join (cost=4.01..11.22 rows=2 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=2 width=8)
-> Seq Scan on tbl_erp_sales_gift_spent_products rp_11 (cost=0.00..3.99 rows=2 width=8)
Filter: (product_id = 2261)