QUERY PLAN
Aggregate (cost=93.32..93.33 rows=1 width=8)
-> Sort (cost=92.88..92.96 rows=29 width=546)
Sort Key: sub.wrote_date DESC
-> Result (cost=55.18..92.18 rows=29 width=546)
-> Append (cost=55.18..91.89 rows=29 width=4)
-> Subquery Scan on sub (cost=55.18..55.40 rows=3 width=4)
-> GroupAggregate (cost=55.18..55.37 rows=3 width=546)
Group Key: r.id
Filter: (max((sum(eip.inventory))) > '0'::numeric)
-> Merge Left Join (cost=55.18..55.32 rows=3 width=40)
Merge Cond: (r.id = rp.erp_inventory_disassemble_id)
Filter: ((rp.erp_inventory_disassemble_id IS NOT NULL) OR (tbl_erp_inventory_disassemble_spent_products.erp_inventory_disassemble_id IS NOT NULL))
-> Merge Left Join (cost=28.38..28.46 rows=3 width=12)
Merge Cond: (r.id = tbl_erp_inventory_disassemble_spent_products.erp_inventory_disassemble_id)
-> Sort (cost=12.50..12.51 rows=3 width=8)
Sort Key: r.id
-> Seq Scan on tbl_erp_inventory_disassembles r (cost=0.00..12.47 rows=3 width=8)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> GroupAggregate (cost=15.88..15.92 rows=2 width=68)
Group Key: tbl_erp_inventory_disassemble_spent_products.erp_inventory_disassemble_id
-> Sort (cost=15.88..15.89 rows=2 width=4)
Sort Key: tbl_erp_inventory_disassemble_spent_products.erp_inventory_disassemble_id
-> Seq Scan on tbl_erp_inventory_disassemble_spent_products (cost=0.00..15.88 rows=2 width=4)
Filter: (product_id = 2177)
-> Materialize (cost=26.80..26.84 rows=1 width=36)
-> GroupAggregate (cost=26.80..26.82 rows=1 width=164)
Group Key: rp.erp_inventory_disassemble_id
-> Sort (cost=26.80..26.80 rows=2 width=7)
Sort Key: rp.erp_inventory_disassemble_id
-> Hash Right Join (cost=12.51..26.79 rows=2 width=7)
Hash Cond: (eip.erp_inventory_disassemble_product_id = rp.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..12.97 rows=497 width=11)
-> Hash (cost=12.50..12.50 rows=1 width=8)
-> Seq Scan on tbl_erp_inventory_disassemble_products rp (cost=0.00..12.50 rows=1 width=8)
Filter: (product_id = 2177)
-> Subquery Scan on "*SELECT* 2" (cost=18.72..18.94 rows=10 width=4)
-> HashAggregate (cost=18.72..18.84 rows=10 width=546)
Group Key: r_1.id
Filter: (sum(eip_1.inventory) > '0'::numeric)
-> Hash Join (cost=4.36..18.67 rows=10 width=11)
Hash Cond: (rp_1.erp_inventory_start_id = r_1.id)
-> Hash Right Join (cost=1.64..15.92 rows=10 width=7)
Hash Cond: (eip_1.erp_inventory_start_product_id = rp_1.id)
-> Seq Scan on tbl_erp_inventory_products eip_1 (cost=0.00..12.97 rows=497 width=11)
-> Hash (cost=1.62..1.62 rows=1 width=8)
-> Seq Scan on tbl_erp_inventory_start_products rp_1 (cost=0.00..1.62 rows=1 width=8)
Filter: (product_id = 2177)
-> Hash (cost=2.32..2.32 rows=32 width=8)
-> Seq Scan on tbl_erp_inventory_starts r_1 (cost=0.00..2.32 rows=32 width=8)
-> Subquery Scan on "*SELECT* 3" (cost=0.00..0.02 rows=1 width=4)
-> HashAggregate (cost=0.00..0.01 rows=1 width=546)
Group Key: id
-> Result (cost=0.00..0.00 rows=0 width=8)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 4" (cost=17.19..17.53 rows=15 width=4)
-> HashAggregate (cost=17.19..17.38 rows=15 width=546)
Group Key: r_2.id
Filter: (sum(eip_2.inventory) > '0'::numeric)
-> Hash Join (cost=2.71..17.07 rows=24 width=11)
Hash Cond: (rp_2.erp_purchase_gift_id = r_2.id)
-> Hash Right Join (cost=1.27..15.56 rows=24 width=7)
Hash Cond: (eip_2.erp_purchase_gift_product_id = rp_2.id)
-> Seq Scan on tbl_erp_inventory_products eip_2 (cost=0.00..12.97 rows=497 width=11)
-> Hash (cost=1.26..1.26 rows=1 width=8)
-> Seq Scan on tbl_erp_purchase_gift_products rp_2 (cost=0.00..1.26 rows=1 width=8)
Filter: (product_id = 2177)
-> Hash (cost=1.25..1.25 rows=15 width=8)
-> Seq Scan on tbl_erp_purchase_gifts r_2 (cost=0.00..1.25 rows=15 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))