QUERY PLAN
Aggregate (cost=74.20..74.21 rows=1 width=8)
-> Sort (cost=73.91..73.96 rows=19 width=546)
Sort Key: sub.wrote_date DESC
-> Result (cost=2.42..73.51 rows=19 width=546)
-> Append (cost=2.42..73.32 rows=19 width=4)
-> Subquery Scan on sub (cost=2.42..2.45 rows=1 width=4)
-> GroupAggregate (cost=2.42..2.44 rows=1 width=546)
Group Key: r.id
-> Sort (cost=2.42..2.42 rows=1 width=8)
Sort Key: r.id
-> Hash Join (cost=1.25..2.41 rows=1 width=8)
Hash Cond: (r.id = rp.erp_inventory_lost_id)
-> Seq Scan on tbl_erp_inventory_losts r (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 (cost=0.00..1.24 rows=1 width=8)
Filter: (product_id = 1372)
-> Subquery Scan on "*SELECT* 2" (cost=19.60..19.85 rows=10 width=4)
-> GroupAggregate (cost=19.60..19.75 rows=10 width=546)
Group Key: r_1.id
-> Sort (cost=19.60..19.62 rows=10 width=8)
Sort Key: r_1.id
-> Hash Left Join (cost=18.19..19.43 rows=10 width=8)
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=17.01..18.21 rows=10 width=12)
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=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_1.erp_inventory_build_id
-> Hash Right Join (cost=1.15..16.85 rows=48 width=4)
Hash Cond: (eip.erp_inventory_build_product_id = rp_1.id)
-> Seq Scan on tbl_erp_inventory_products eip (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_1 (cost=0.00..1.14 rows=1 width=8)
Filter: (product_id = 1372)
-> 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 = 1372)
-> Subquery Scan on "*SELECT* 3" (cost=19.25..19.35 rows=4 width=4)
-> GroupAggregate (cost=19.25..19.31 rows=4 width=546)
Group Key: r_2.id
-> Sort (cost=19.25..19.26 rows=4 width=8)
Sort Key: r_2.id
-> Hash Left Join (cost=18.10..19.21 rows=4 width=8)
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=17.01..18.10 rows=4 width=12)
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=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_2.erp_inventory_disassemble_id
-> Hash Right Join (cost=1.11..16.82 rows=66 width=4)
Hash Cond: (eip_1.erp_inventory_disassemble_product_id = rp_2.id)
-> Seq Scan on tbl_erp_inventory_products eip_1 (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_2 (cost=0.00..1.10 rows=1 width=8)
Filter: (product_id = 1372)
-> 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 = 1372)
-> Subquery Scan on "*SELECT* 4" (cost=20.57..20.64 rows=3 width=4)
-> GroupAggregate (cost=20.57..20.61 rows=3 width=546)
Group Key: r_3.id
-> Sort (cost=20.57..20.58 rows=3 width=8)
Sort Key: r_3.id
-> Hash Join (cost=11.71..20.55 rows=3 width=8)
Hash Cond: (r_3.id = rp_3.erp_sales_outbound_id)
-> Seq Scan on tbl_erp_sales_outbounds r_3 (cost=0.00..7.64 rows=186 width=8)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> Hash (cost=11.68..11.68 rows=3 width=8)
-> Seq Scan on tbl_erp_sales_outbound_spent_products rp_3 (cost=0.00..11.68 rows=3 width=8)
Filter: (product_id = 1372)
-> Subquery Scan on "*SELECT* 5" (cost=11.00..11.03 rows=1 width=4)
-> GroupAggregate (cost=11.00..11.02 rows=1 width=546)
Group Key: r_4.id
-> Sort (cost=11.00..11.01 rows=1 width=8)
Sort Key: r_4.id
-> Hash Join (cost=4.00..10.99 rows=1 width=8)
Hash Cond: (r_4.id = rp_4.erp_sales_gift_id)
-> Seq Scan on tbl_erp_sales_gifts r_4 (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_4 (cost=0.00..3.99 rows=1 width=8)
Filter: (product_id = 1372)