QUERY PLAN
Limit (cost=328.45..328.47 rows=9 width=506)
-> Sort (cost=328.45..328.47 rows=9 width=506)
Sort Key: r.wrote_date DESC
-> Append (cost=24.41..328.31 rows=9 width=506)
-> GroupAggregate (cost=24.41..31.68 rows=1 width=506)
Group Key: r.id
-> Nested Loop Left Join (cost=24.41..31.64 rows=1 width=819)
-> Nested Loop Left Join (cost=24.27..25.39 rows=1 width=307)
Join Filter: (eip.erp_purchase_inbound_product_id = rp.id)
-> Merge Join (cost=24.27..24.30 rows=1 width=302)
Merge Cond: (r.id = rp.erp_purchase_inbound_id)
-> Sort (cost=12.13..12.14 rows=2 width=202)
Sort Key: r.id
-> Seq Scan on tbl_erp_purchase_inbounds r (cost=0.00..12.12 rows=2 width=202)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Sort (cost=12.13..12.14 rows=1 width=104)
Sort Key: rp.erp_purchase_inbound_id
-> Seq Scan on tbl_erp_purchase_inbound_products rp (cost=0.00..12.12 rows=1 width=104)
Filter: (product_id = 947)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..1.04 rows=4 width=13)
-> Index Scan using tbl_erp_stores_pkey on tbl_erp_stores s (cost=0.14..6.16 rows=1 width=520)
Index Cond: (eip.erp_store_id = id)
-> GroupAggregate (cost=28.56..43.84 rows=1 width=506)
Group Key: r_1.id
-> Nested Loop Left Join (cost=28.56..43.82 rows=1 width=782)
-> Nested Loop Left Join (cost=28.41..37.56 rows=1 width=270)
-> Merge Join (cost=28.27..28.30 rows=1 width=270)
Merge Cond: (r_1.id = rp_1.erp_purchase_return_id)
-> Sort (cost=12.63..12.64 rows=2 width=202)
Sort Key: r_1.id
-> Seq Scan on tbl_erp_purchase_returns r_1 (cost=0.00..12.62 rows=2 width=202)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Sort (cost=15.63..15.64 rows=2 width=72)
Sort Key: rp_1.erp_purchase_return_id
-> Seq Scan on tbl_erp_purchase_return_products rp_1 (cost=0.00..15.62 rows=2 width=72)
Filter: (product_id = 947)
-> Nested Loop Left Join (cost=0.14..9.25 rows=1 width=8)
Join Filter: (eip_1.erp_purchase_inbound_product_id = epip.id)
-> Index Only Scan using tbl_erp_purchase_inbound_products_pkey on tbl_erp_purchase_inbound_products epip (cost=0.14..8.16 rows=1 width=4)
Index Cond: (id = rp_1.erp_purchase_inbound_product_id)
-> Seq Scan on tbl_erp_inventory_products eip_1 (cost=0.00..1.04 rows=4 width=8)
-> Index Scan using tbl_erp_stores_pkey on tbl_erp_stores s_1 (cost=0.14..6.16 rows=1 width=520)
Index Cond: (eip_1.erp_store_id = id)
-> GroupAggregate (cost=28.66..35.92 rows=1 width=506)
Group Key: r_2.id
-> Nested Loop Left Join (cost=28.66..35.89 rows=1 width=746)
-> Nested Loop Left Join (cost=28.52..29.64 rows=1 width=234)
Join Filter: (eip_2.id = rp_2.erp_inventory_product_id)
-> Merge Join (cost=28.52..28.55 rows=1 width=234)
Merge Cond: (r_2.id = rp_2.erp_inventory_lost_id)
-> Sort (cost=12.63..12.64 rows=2 width=198)
Sort Key: r_2.id
-> Seq Scan on tbl_erp_inventory_losts r_2 (cost=0.00..12.62 rows=2 width=198)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Sort (cost=15.88..15.89 rows=2 width=40)
Sort Key: rp_2.erp_inventory_lost_id
-> Seq Scan on tbl_erp_inventory_lost_products rp_2 (cost=0.00..15.88 rows=2 width=40)
Filter: (product_id = 947)
-> Seq Scan on tbl_erp_inventory_products eip_2 (cost=0.00..1.04 rows=4 width=8)
-> Index Scan using tbl_erp_stores_pkey on tbl_erp_stores s_2 (cost=0.14..6.16 rows=1 width=520)
Index Cond: (eip_2.erp_store_id = id)
-> GroupAggregate (cost=25.16..48.40 rows=1 width=506)
Group Key: r_3.id
-> Nested Loop Left Join (cost=25.16..48.35 rows=1 width=798)
-> Nested Loop Left Join (cost=25.02..42.10 rows=1 width=286)
Join Filter: (eip_3.erp_inventory_build_product_id = rp_3.id)
-> Nested Loop Left Join (cost=25.02..41.01 rows=1 width=266)
Join Filter: (rp2.erp_inventory_build_id = r_3.id)
Filter: ((rp_3.product_id = 947) OR (rp2.product_id = 947))
-> Merge Left Join (cost=25.02..25.05 rows=2 width=206)
Merge Cond: (r_3.id = rp_3.erp_inventory_build_id)
-> Sort (cost=12.26..12.27 rows=2 width=198)
Sort Key: r_3.id
-> Seq Scan on tbl_erp_inventory_builds r_3 (cost=0.00..12.25 rows=2 width=198)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Sort (cost=12.76..12.77 rows=1 width=12)
Sort Key: rp_3.erp_inventory_build_id
-> Seq Scan on tbl_erp_inventory_build_products rp_3 (cost=0.00..12.75 rows=1 width=12)
Filter: (product_id = 947)
-> Materialize (cost=0.00..15.88 rows=2 width=72)
-> Seq Scan on tbl_erp_inventory_build_spent_products rp2 (cost=0.00..15.88 rows=2 width=72)
Filter: (product_id = 947)
-> Seq Scan on tbl_erp_inventory_products eip_3 (cost=0.00..1.04 rows=4 width=28)
-> Index Scan using tbl_erp_stores_pkey on tbl_erp_stores s_3 (cost=0.14..6.16 rows=1 width=520)
Index Cond: (eip_3.erp_store_id = id)
-> GroupAggregate (cost=27.71..27.75 rows=1 width=506)
Group Key: r_4.id
-> Sort (cost=27.71..27.72 rows=1 width=819)
Sort Key: r_4.id
-> Nested Loop Left Join (cost=0.29..27.70 rows=1 width=819)
-> Nested Loop Left Join (cost=0.14..21.45 rows=1 width=307)
Join Filter: (eip_4.erp_inventory_start_product_id = rp_4.id)
-> Nested Loop (cost=0.14..20.36 rows=1 width=302)
-> Seq Scan on tbl_erp_inventory_start_products rp_4 (cost=0.00..12.12 rows=1 width=104)
Filter: (product_id = 947)
-> Index Scan using tbl_erp_inventory_starts_pkey on tbl_erp_inventory_starts r_4 (cost=0.14..8.16 rows=1 width=202)
Index Cond: (id = rp_4.erp_inventory_start_id)
-> Seq Scan on tbl_erp_inventory_products eip_4 (cost=0.00..1.04 rows=4 width=13)
-> Index Scan using tbl_erp_stores_pkey on tbl_erp_stores s_4 (cost=0.14..6.16 rows=1 width=520)
Index Cond: (eip_4.erp_store_id = id)
-> GroupAggregate (cost=26.41..33.69 rows=1 width=506)
Group Key: r_5.id
-> Nested Loop Left Join (cost=26.41..33.64 rows=1 width=850)
-> Nested Loop Left Join (cost=26.27..27.39 rows=1 width=338)
Join Filter: (eip_5.id = rp_5.erp_inventory_product_id)
-> Merge Join (cost=26.27..26.30 rows=1 width=338)
Merge Cond: (r_5.id = rp_5.erp_sales_outbound_id)
-> Sort (cost=12.51..12.52 rows=2 width=206)
Sort Key: r_5.id
-> Seq Scan on tbl_erp_sales_outbounds r_5 (cost=0.00..12.50 rows=2 width=206)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Sort (cost=13.76..13.77 rows=2 width=136)
Sort Key: rp_5.erp_sales_outbound_id
-> Seq Scan on tbl_erp_sales_outbound_spent_products rp_5 (cost=0.00..13.75 rows=2 width=136)
Filter: (product_id = 947)
-> Seq Scan on tbl_erp_inventory_products eip_5 (cost=0.00..1.04 rows=4 width=8)
-> Index Scan using tbl_erp_stores_pkey on tbl_erp_stores s_5 (cost=0.14..6.16 rows=1 width=520)
Index Cond: (eip_5.erp_store_id = id)
-> GroupAggregate (cost=27.32..41.58 rows=1 width=506)
Group Key: r_6.id
-> Nested Loop Left Join (cost=27.32..41.55 rows=1 width=786)
-> Merge Join (cost=26.89..26.93 rows=1 width=274)
Merge Cond: (r_6.id = rp_6.erp_sales_return_id)
-> Sort (cost=12.63..12.64 rows=2 width=206)
Sort Key: r_6.id
-> Seq Scan on tbl_erp_sales_returns r_6 (cost=0.00..12.62 rows=2 width=206)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Sort (cost=14.26..14.27 rows=2 width=72)
Sort Key: rp_6.erp_sales_return_id
-> Seq Scan on tbl_erp_sales_return_products rp_6 (cost=0.00..14.25 rows=2 width=72)
Filter: (product_id = 947)
-> Nested Loop Left Join (cost=0.42..14.62 rows=1 width=520)
-> Index Scan using tbl_erp_sales_outbound_spent_products_pkey on tbl_erp_sales_outbound_spent_products rp2_1 (cost=0.15..8.17 rows=1 width=8)
Index Cond: (rp_6.erp_sales_outbound_spent_product_id = id)
-> Nested Loop Left Join (cost=0.28..6.44 rows=1 width=520)
-> Index Scan using tbl_erp_inventory_products_pkey on tbl_erp_inventory_products eip_6 (cost=0.13..0.19 rows=1 width=8)
Index Cond: (id = rp2_1.erp_inventory_product_id)
-> Index Scan using tbl_erp_stores_pkey on tbl_erp_stores s_6 (cost=0.14..6.16 rows=1 width=520)
Index Cond: (eip_6.erp_store_id = id)
-> GroupAggregate (cost=24.41..31.68 rows=1 width=506)
Group Key: r_7.id
-> Nested Loop Left Join (cost=24.41..31.64 rows=1 width=738)
-> Nested Loop Left Join (cost=24.27..25.39 rows=1 width=226)
Join Filter: (eip_7.erp_purchase_gift_product_id = rp_7.id)
-> Merge Join (cost=24.27..24.30 rows=1 width=206)
Merge Cond: (r_7.id = rp_7.erp_purchase_gift_id)
-> Sort (cost=12.13..12.14 rows=2 width=202)
Sort Key: r_7.id
-> Seq Scan on tbl_erp_purchase_gifts r_7 (cost=0.00..12.12 rows=2 width=202)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Sort (cost=12.13..12.14 rows=1 width=8)
Sort Key: rp_7.erp_purchase_gift_id
-> Seq Scan on tbl_erp_purchase_gift_products rp_7 (cost=0.00..12.12 rows=1 width=8)
Filter: (product_id = 947)
-> Seq Scan on tbl_erp_inventory_products eip_7 (cost=0.00..1.04 rows=4 width=28)
-> Index Scan using tbl_erp_stores_pkey on tbl_erp_stores s_7 (cost=0.14..6.16 rows=1 width=520)
Index Cond: (eip_7.erp_store_id = id)
-> GroupAggregate (cost=26.41..33.67 rows=1 width=506)
Group Key: r_8.id
-> Nested Loop Left Join (cost=26.41..33.64 rows=1 width=754)
-> Nested Loop Left Join (cost=26.27..27.39 rows=1 width=242)
Join Filter: (eip_8.id = rp_8.erp_inventory_product_id)
-> Merge Join (cost=26.27..26.30 rows=1 width=242)
Merge Cond: (r_8.id = rp_8.erp_sales_gift_id)
-> Sort (cost=12.51..12.52 rows=2 width=206)
Sort Key: r_8.id
-> Seq Scan on tbl_erp_sales_gifts r_8 (cost=0.00..12.50 rows=2 width=206)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Sort (cost=13.76..13.77 rows=2 width=40)
Sort Key: rp_8.erp_sales_gift_id
-> Seq Scan on tbl_erp_sales_gift_spent_products rp_8 (cost=0.00..13.75 rows=2 width=40)
Filter: (product_id = 947)
-> Seq Scan on tbl_erp_inventory_products eip_8 (cost=0.00..1.04 rows=4 width=8)
-> Index Scan using tbl_erp_stores_pkey on tbl_erp_stores s_8 (cost=0.14..6.16 rows=1 width=520)
Index Cond: (eip_8.erp_store_id = id)