QUERY PLAN
Limit (cost=722.57..722.62 rows=20 width=313)
-> Sort (cost=722.57..727.87 rows=2122 width=313)
Sort Key: p.updated_at DESC NULLS LAST, p.id DESC
-> Hash Left Join (cost=537.46..666.10 rows=2122 width=313)
Hash Cond: (p.id = price.product_id)
-> Hash Left Join (cost=507.33..630.39 rows=2122 width=277)
Hash Cond: (p.id = in_verify.product_id)
Filter: ((COALESCE(stock.available_stock_number, '0'::numeric) <> '0'::numeric) OR (COALESCE(purchase_un.purchase_order_un_inbound_number, '0'::numeric) <> '0'::numeric) OR (COALESCE(sales_un.sales_order_un_outbound_number, '0'::numeric) <> '0'::numeric) OR (COALESCE(out_verify.outbound_verifying_number, '0'::numeric) <> '0'::numeric) OR (COALESCE(in_verify.inbound_verifying_number, '0'::numeric) <> '0'::numeric))
-> Hash Left Join (cost=450.53..568.00 rows=2122 width=245)
Hash Cond: (p.id = out_verify.product_id)
-> Hash Left Join (cost=383.29..495.18 rows=2122 width=213)
Hash Cond: (p.id = sales_un.product_id)
-> Hash Left Join (cost=193.35..299.66 rows=2122 width=181)
Hash Cond: (p.id = purchase_un.product_id)
-> Hash Left Join (cost=107.96..208.69 rows=2122 width=149)
Hash Cond: (p.id = stock.product_id)
-> Hash Left Join (cost=77.83..172.98 rows=2122 width=117)
Hash Cond: (p.product_component = pc.id)
-> Hash Left Join (cost=72.23..161.66 rows=2122 width=101)
Hash Cond: (p.product_type = pt.id)
-> Hash Left Join (cost=69.81..153.30 rows=2122 width=89)
Hash Cond: (p.product_serie = ps.id)
-> Hash Left Join (cost=7.90..85.81 rows=2122 width=60)
Hash Cond: (p.product_brand = pb.id)
-> Seq Scan on tbl_products p (cost=0.00..72.22 rows=2122 width=52)
-> Hash (cost=5.18..5.18 rows=218 width=12)
-> Seq Scan on tbl_product_brands pb (cost=0.00..5.18 rows=218 width=12)
-> Hash (cost=41.96..41.96 rows=1596 width=33)
-> Seq Scan on tbl_product_series ps (cost=0.00..41.96 rows=1596 width=33)
-> Hash (cost=1.63..1.63 rows=63 width=16)
-> Seq Scan on tbl_product_types pt (cost=0.00..1.63 rows=63 width=16)
-> Hash (cost=3.60..3.60 rows=160 width=20)
-> Seq Scan on tbl_product_components pc (cost=0.00..3.60 rows=160 width=20)
-> Hash (cost=25.53..25.53 rows=368 width=36)
-> Subquery Scan on stock (cost=17.25..25.53 rows=368 width=36)
-> HashAggregate (cost=17.25..21.85 rows=368 width=36)
Group Key: tbl_erp_inventory_products.product_id
-> Seq Scan on tbl_erp_inventory_products (cost=0.00..14.50 rows=550 width=7)
-> Hash (cost=84.82..84.82 rows=46 width=36)
-> Subquery Scan on purchase_un (cost=83.78..84.82 rows=46 width=36)
-> HashAggregate (cost=83.78..84.36 rows=46 width=36)
Group Key: epop.product_id
-> Hash Join (cost=70.69..83.44 rows=46 width=12)
Hash Cond: (epop.erp_purchase_order_id = epo.id)
-> Seq Scan on tbl_erp_purchase_order_products epop (cost=0.00..11.60 rows=438 width=16)
Filter: ((number - COALESCE(into_inventory, '0'::numeric)) <> '0'::numeric)
-> Hash (cost=67.78..67.78 rows=233 width=4)
-> Seq Scan on tbl_erp_purchase_orders epo (cost=0.00..67.78 rows=233 width=4)
Filter: ((NOT is_done) AND (status = ANY ('{2,5}'::integer[])))
-> Hash (cost=175.73..175.73 rows=1136 width=36)
-> Subquery Scan on sales_un (cost=150.17..175.73 rows=1136 width=36)
-> HashAggregate (cost=150.17..164.37 rows=1136 width=36)
Group Key: esop.product_id
-> Hash Join (cost=73.38..139.43 rows=1432 width=11)
Hash Cond: (esop.erp_sales_order_id = eso.id)
-> Seq Scan on tbl_erp_sales_order_products esop (cost=0.00..60.25 rows=2206 width=15)
Filter: ((number - COALESCE(outbound, '0'::numeric)) <> '0'::numeric)
-> Hash (cost=59.45..59.45 rows=1114 width=4)
-> Seq Scan on tbl_erp_sales_orders eso (cost=0.00..59.45 rows=1114 width=4)
Filter: ((NOT is_done) AND (status = ANY ('{2,5}'::integer[])))
-> Hash (cost=67.00..67.00 rows=19 width=36)
-> Subquery Scan on out_verify (cost=65.77..67.00 rows=19 width=36)
-> GroupAggregate (cost=65.77..66.81 rows=19 width=36)
Group Key: eip.product_id
-> Merge Append (cost=65.77..66.48 rows=19 width=36)
Sort Key: eip.product_id
-> GroupAggregate (cost=63.57..63.93 rows=18 width=36)
Group Key: eip.product_id
-> Sort (cost=63.57..63.62 rows=18 width=8)
Sort Key: eip.product_id
-> Nested Loop (cost=34.87..63.20 rows=18 width=8)
-> Hash Left Join (cost=34.60..56.28 rows=18 width=8)
Hash Cond: (eips.erp_inventory_disassemble_spent_id = eid.id)
Filter: (((eips.erp_sales_outbound_id IS NOT NULL) AND (eso_1.status = 1)) OR ((eips.erp_sales_gift_id IS NOT NULL) AND (esg.status = 1)) OR ((eips.erp_inventory_lost_id IS NOT NULL) AND (eil.status = 1)) OR ((eips.erp_inventory_build_spent_id IS NOT NULL) AND (eib.status = 1)) OR ((eips.erp_inventory_disassemble_spent_id IS NOT NULL) AND (eid.status = 1)) OR ((eips.erp_inventory_transfer_spent_id IS NOT NULL) AND (eit.status = 1)))
-> Hash Left Join (cost=33.49..53.65 rows=565 width=42)
Hash Cond: (eips.erp_inventory_transfer_spent_id = eit.id)
-> Hash Left Join (cost=19.66..38.31 rows=565 width=40)
Hash Cond: (eips.erp_inventory_build_spent_id = eib.id)
-> Hash Left Join (cost=18.39..35.55 rows=565 width=38)
Hash Cond: (eips.erp_inventory_lost_id = eil.id)
-> Hash Left Join (cost=17.19..32.84 rows=565 width=36)
Hash Cond: (eips.erp_sales_gift_id = esg.id)
-> Hash Left Join (cost=9.32..23.48 rows=565 width=34)
Hash Cond: (eips.erp_sales_outbound_id = eso_1.id)
-> Seq Scan on tbl_erp_inventory_product_spents eips (cost=0.00..12.65 rows=565 width=32)
-> Hash (cost=6.92..6.92 rows=192 width=6)
-> Seq Scan on tbl_erp_sales_outbounds eso_1 (cost=0.00..6.92 rows=192 width=6)
-> Hash (cost=5.72..5.72 rows=172 width=6)
-> Seq Scan on tbl_erp_sales_gifts esg (cost=0.00..5.72 rows=172 width=6)
-> Hash (cost=1.09..1.09 rows=9 width=6)
-> Seq Scan on tbl_erp_inventory_losts eil (cost=0.00..1.09 rows=9 width=6)
-> Hash (cost=1.12..1.12 rows=12 width=6)
-> Seq Scan on tbl_erp_inventory_builds eib (cost=0.00..1.12 rows=12 width=6)
-> Hash (cost=11.70..11.70 rows=170 width=6)
-> Seq Scan on tbl_erp_inventory_transfers eit (cost=0.00..11.70 rows=170 width=6)
-> Hash (cost=1.05..1.05 rows=5 width=6)
-> Seq Scan on tbl_erp_inventory_disassembles eid (cost=0.00..1.05 rows=5 width=6)
-> Index Scan using tbl_erp_inventory_products_pkey on tbl_erp_inventory_products eip (cost=0.28..0.38 rows=1 width=8)
Index Cond: (id = eips.erp_inventory_product_id)
-> GroupAggregate (cost=2.18..2.21 rows=1 width=36)
Group Key: eprp.product_id
-> Sort (cost=2.18..2.19 rows=1 width=9)
Sort Key: eprp.product_id
-> Hash Join (cost=1.09..2.17 rows=1 width=9)
Hash Cond: (eprp.erp_purchase_return_id = epr.id)
-> Seq Scan on tbl_erp_purchase_return_products eprp (cost=0.00..1.06 rows=6 width=13)
-> Hash (cost=1.07..1.07 rows=1 width=4)
-> Seq Scan on tbl_erp_purchase_returns epr (cost=0.00..1.07 rows=1 width=4)
Filter: (status = 1)
-> Hash (cost=56.61..56.61 rows=15 width=36)
-> Subquery Scan on in_verify (cost=55.48..56.61 rows=15 width=36)
-> GroupAggregate (cost=55.48..56.46 rows=15 width=36)
Group Key: epip.product_id
-> Merge Append (cost=55.48..56.20 rows=15 width=36)
Sort Key: epip.product_id
-> GroupAggregate (cost=19.34..19.38 rows=2 width=36)
Group Key: epip.product_id
-> Sort (cost=19.34..19.34 rows=2 width=12)
Sort Key: epip.product_id
-> Hash Join (cost=7.74..19.33 rows=2 width=12)
Hash Cond: (epip.erp_purchase_inbound_id = epi.id)
-> Seq Scan on tbl_erp_purchase_inbound_products epip (cost=0.00..10.41 rows=441 width=16)
-> Hash (cost=7.72..7.72 rows=1 width=4)
-> Seq Scan on tbl_erp_purchase_inbounds epi (cost=0.00..7.72 rows=1 width=4)
Filter: (status = 1)
-> GroupAggregate (cost=2.81..2.86 rows=2 width=36)
Group Key: epgp.product_id
-> Sort (cost=2.81..2.82 rows=2 width=41)
Sort Key: epgp.product_id
-> Hash Join (cost=1.29..2.80 rows=2 width=41)
Hash Cond: (epgp.erp_purchase_gift_id = epg.id)
-> Seq Scan on tbl_erp_purchase_gift_products epgp (cost=0.00..1.39 rows=39 width=45)
-> Hash (cost=1.27..1.27 rows=1 width=4)
-> Seq Scan on tbl_erp_purchase_gifts epg (cost=0.00..1.27 rows=1 width=4)
Filter: (status = 1)
-> GroupAggregate (cost=2.34..2.36 rows=1 width=36)
Group Key: eiop.product_id
-> Sort (cost=2.34..2.34 rows=1 width=41)
Sort Key: eiop.product_id
-> Hash Join (cost=1.14..2.33 rows=1 width=41)
Hash Cond: (eiop.erp_inventory_overflow_id = eio.id)
-> Seq Scan on tbl_erp_inventory_overflow_products eiop (cost=0.00..1.14 rows=14 width=45)
-> Hash (cost=1.12..1.12 rows=1 width=4)
-> Seq Scan on tbl_erp_inventory_overflows eio (cost=0.00..1.12 rows=1 width=4)
Filter: (status = 1)
-> GroupAggregate (cost=2.45..2.57 rows=6 width=36)
Group Key: eibp.product_id
-> Sort (cost=2.45..2.47 rows=6 width=9)
Sort Key: eibp.product_id
-> Hash Join (cost=1.22..2.38 rows=6 width=9)
Hash Cond: (eibp.erp_inventory_build_id = eib_1.id)
-> Seq Scan on tbl_erp_inventory_build_products eibp (cost=0.00..1.11 rows=11 width=13)
-> Hash (cost=1.15..1.15 rows=6 width=4)
-> Seq Scan on tbl_erp_inventory_builds eib_1 (cost=0.00..1.15 rows=6 width=4)
Filter: (status = 1)
-> GroupAggregate (cost=2.21..2.25 rows=2 width=36)
Group Key: eidp.product_id
-> Sort (cost=2.21..2.21 rows=2 width=9)
Sort Key: eidp.product_id
-> Hash Join (cost=1.07..2.20 rows=2 width=9)
Hash Cond: (eidp.erp_inventory_disassemble_id = eid_1.id)
-> Seq Scan on tbl_erp_inventory_disassemble_products eidp (cost=0.00..1.08 rows=8 width=13)
-> Hash (cost=1.06..1.06 rows=1 width=4)
-> Seq Scan on tbl_erp_inventory_disassembles eid_1 (cost=0.00..1.06 rows=1 width=4)
Filter: (status = 1)
-> GroupAggregate (cost=24.05..24.07 rows=1 width=36)
Group Key: eitp.product_id
-> Sort (cost=24.05..24.06 rows=1 width=36)
Sort Key: eitp.product_id
-> Hash Join (cost=12.14..24.04 rows=1 width=36)
Hash Cond: (eitp.erp_inventory_transfer_id = eit_1.id)
-> Seq Scan on tbl_erp_inventory_transfer_products eitp (cost=0.00..11.50 rows=150 width=40)
-> Hash (cost=12.12..12.12 rows=1 width=4)
-> Seq Scan on tbl_erp_inventory_transfers eit_1 (cost=0.00..12.12 rows=1 width=4)
Filter: (status = 1)
-> GroupAggregate (cost=2.18..2.21 rows=1 width=36)
Group Key: esrp.product_id
-> Sort (cost=2.18..2.19 rows=1 width=9)
Sort Key: esrp.product_id
-> Hash Join (cost=1.09..2.17 rows=1 width=9)
Hash Cond: (esrp.erp_sales_return_id = esr.id)
-> Seq Scan on tbl_erp_sales_return_products esrp (cost=0.00..1.06 rows=6 width=13)
-> Hash (cost=1.07..1.07 rows=1 width=4)
-> Seq Scan on tbl_erp_sales_returns esr (cost=0.00..1.07 rows=1 width=4)
Filter: (status = 1)
-> Hash (cost=25.53..25.53 rows=368 width=36)
-> Subquery Scan on price (cost=17.25..25.53 rows=368 width=36)
-> HashAggregate (cost=17.25..21.85 rows=368 width=36)
Group Key: tbl_erp_inventory_products_1.product_id
-> Seq Scan on tbl_erp_inventory_products tbl_erp_inventory_products_1 (cost=0.00..14.50 rows=550 width=14)