QUERY PLAN
Limit (cost=425.19..425.24 rows=20 width=313)
-> Sort (cost=425.19..433.74 rows=3423 width=313)
Sort Key: p.updated_at DESC NULLS LAST
-> Hash Left Join (cost=34.07..334.10 rows=3423 width=313)
Hash Cond: (p.id = price.product_id)
-> Nested Loop Left Join (cost=17.92..311.22 rows=489 width=277)
Join Filter: (in_verify.product_id = p.id)
Filter: ((COALESCE(stock.available_stock_number, '0'::numeric) <> '0'::numeric) OR (COALESCE((sum((epop.number - COALESCE(epop.into_inventory, '0'::numeric)))), '0'::numeric) <> '0'::numeric) OR (COALESCE((sum((esop.number - COALESCE(esop.outbound, '0'::numeric)))), '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))
-> Nested Loop Left Join (cost=17.92..252.39 rows=70 width=245)
Join Filter: (out_verify.product_id = p.id)
-> Nested Loop Left Join (cost=1.12..210.83 rows=35 width=213)
Join Filter: (stock.product_id = p.id)
-> Nested Loop Left Join (cost=1.12..194.60 rows=5 width=181)
Join Filter: (esop.product_id = p.id)
-> Nested Loop Left Join (cost=0.84..70.24 rows=1 width=149)
Join Filter: (epop.product_id = p.id)
-> Nested Loop Left Join (cost=0.56..32.53 rows=1 width=117)
Join Filter: (pc.id = p.product_component)
-> Nested Loop Left Join (cost=0.56..26.93 rows=1 width=101)
Join Filter: (pt.id = p.product_type)
-> Nested Loop Left Join (cost=0.56..24.51 rows=1 width=89)
-> Nested Loop Left Join (cost=0.28..16.20 rows=1 width=60)
Join Filter: (pb.id = p.product_brand)
-> Index Scan using tbl_products_pkey on tbl_products p (cost=0.28..8.30 rows=1 width=52)
Index Cond: (id = 1372)
-> Seq Scan on tbl_product_brands pb (cost=0.00..5.18 rows=218 width=12)
-> Index Scan using tbl_product_series_pkey on tbl_product_series ps (cost=0.28..8.29 rows=1 width=33)
Index Cond: (id = p.product_serie)
-> Seq Scan on tbl_product_types pt (cost=0.00..1.63 rows=63 width=16)
-> Seq Scan on tbl_product_components pc (cost=0.00..3.60 rows=160 width=20)
-> GroupAggregate (cost=0.28..37.69 rows=1 width=36)
Group Key: epop.product_id
-> Nested Loop (cost=0.28..37.67 rows=1 width=12)
-> Seq Scan on tbl_erp_purchase_order_products epop (cost=0.00..12.70 rows=3 width=16)
Filter: ((product_id = 1372) AND ((number - COALESCE(into_inventory, '0'::numeric)) <> '0'::numeric))
-> Index Scan using tbl_erp_purchase_orders_pkey on tbl_erp_purchase_orders epo (cost=0.28..8.30 rows=1 width=4)
Index Cond: (id = epop.erp_purchase_order_id)
Filter: ((NOT is_done) AND (status = ANY ('{2,5}'::integer[])))
-> GroupAggregate (cost=0.28..124.29 rows=5 width=36)
Group Key: esop.product_id
-> Nested Loop (cost=0.28..124.19 rows=5 width=11)
-> Seq Scan on tbl_erp_sales_order_products esop (cost=0.00..65.80 rows=8 width=15)
Filter: ((product_id = 1372) AND ((number - COALESCE(outbound, '0'::numeric)) <> '0'::numeric))
-> Index Scan using tbl_erp_sales_orders_pkey on tbl_erp_sales_orders eso (cost=0.28..7.30 rows=1 width=4)
Index Cond: (id = esop.erp_sales_order_id)
Filter: ((NOT is_done) AND (status = ANY ('{2,5}'::integer[])))
-> Materialize (cost=0.00..16.10 rows=7 width=36)
-> Subquery Scan on stock (cost=0.00..16.07 rows=7 width=36)
-> GroupAggregate (cost=0.00..16.00 rows=7 width=36)
Group Key: tbl_erp_inventory_products.product_id
-> Seq Scan on tbl_erp_inventory_products (cost=0.00..15.88 rows=7 width=7)
Filter: (product_id = 1372)
-> Materialize (cost=16.80..40.86 rows=2 width=36)
-> Subquery Scan on out_verify (cost=16.80..40.85 rows=2 width=36)
-> GroupAggregate (cost=16.80..40.83 rows=2 width=36)
Group Key: eip.product_id
-> Append (cost=16.80..40.80 rows=2 width=36)
-> GroupAggregate (cost=16.80..38.60 rows=1 width=36)
Group Key: eip.product_id
-> Nested Loop Left Join (cost=16.80..38.58 rows=1 width=8)
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)))
-> Nested Loop Left Join (cost=16.67..37.21 rows=7 width=42)
-> Nested Loop Left Join (cost=16.52..35.47 rows=7 width=40)
-> Nested Loop Left Join (cost=16.39..34.25 rows=7 width=38)
-> Nested Loop Left Join (cost=16.25..33.03 rows=7 width=36)
-> Nested Loop Left Join (cost=16.11..31.59 rows=7 width=34)
-> Hash Join (cost=15.96..30.11 rows=7 width=32)
Hash Cond: (eips.erp_inventory_product_id = eip.id)
-> Seq Scan on tbl_erp_inventory_product_spents eips (cost=0.00..12.65 rows=565 width=32)
-> Hash (cost=15.88..15.88 rows=7 width=8)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..15.88 rows=7 width=8)
Filter: (product_id = 1372)
-> Index Scan using tbl_erp_sales_outbounds_pkey on tbl_erp_sales_outbounds eso_1 (cost=0.14..0.21 rows=1 width=6)
Index Cond: (id = eips.erp_sales_outbound_id)
-> Index Scan using tbl_erp_sales_gifts_pkey on tbl_erp_sales_gifts esg (cost=0.14..0.20 rows=1 width=6)
Index Cond: (id = eips.erp_sales_gift_id)
-> Index Scan using tbl_erp_inventory_losts_pkey on tbl_erp_inventory_losts eil (cost=0.14..0.17 rows=1 width=6)
Index Cond: (id = eips.erp_inventory_lost_id)
-> Index Scan using tbl_erp_inventory_builds_pkey on tbl_erp_inventory_builds eib (cost=0.14..0.17 rows=1 width=6)
Index Cond: (id = eips.erp_inventory_build_spent_id)
-> Index Scan using tbl_erp_inventory_transfers_pkey on tbl_erp_inventory_transfers eit (cost=0.14..0.25 rows=1 width=6)
Index Cond: (id = eips.erp_inventory_transfer_spent_id)
-> Index Scan using tbl_erp_inventory_disassembles_pkey on tbl_erp_inventory_disassembles eid (cost=0.13..0.17 rows=1 width=6)
Index Cond: (id = eips.erp_inventory_disassemble_spent_id)
-> GroupAggregate (cost=0.00..2.18 rows=1 width=36)
Group Key: eprp.product_id
-> Nested Loop (cost=0.00..2.16 rows=1 width=9)
Join Filter: (eprp.erp_purchase_return_id = epr.id)
-> Seq Scan on tbl_erp_purchase_return_products eprp (cost=0.00..1.07 rows=1 width=13)
Filter: (product_id = 1372)
-> Seq Scan on tbl_erp_purchase_returns epr (cost=0.00..1.07 rows=1 width=4)
Filter: (status = 1)
-> Materialize (cost=0.00..55.47 rows=7 width=36)
-> Subquery Scan on in_verify (cost=0.00..55.44 rows=7 width=36)
-> GroupAggregate (cost=0.00..55.37 rows=7 width=36)
Group Key: epip.product_id
-> Append (cost=0.00..55.25 rows=7 width=36)
-> GroupAggregate (cost=0.00..19.28 rows=1 width=36)
Group Key: epip.product_id
-> Nested Loop (cost=0.00..19.26 rows=1 width=12)
Join Filter: (epip.erp_purchase_inbound_id = epi.id)
-> Seq Scan on tbl_erp_purchase_inbounds epi (cost=0.00..7.72 rows=1 width=4)
Filter: (status = 1)
-> Seq Scan on tbl_erp_purchase_inbound_products epip (cost=0.00..11.51 rows=2 width=16)
Filter: (product_id = 1372)
-> GroupAggregate (cost=0.00..2.81 rows=1 width=36)
Group Key: epgp.product_id
-> Nested Loop (cost=0.00..2.79 rows=1 width=41)
Join Filter: (epgp.erp_purchase_gift_id = epg.id)
-> Seq Scan on tbl_erp_purchase_gifts epg (cost=0.00..1.27 rows=1 width=4)
Filter: (status = 1)
-> Seq Scan on tbl_erp_purchase_gift_products epgp (cost=0.00..1.49 rows=2 width=45)
Filter: (product_id = 1372)
-> GroupAggregate (cost=0.00..2.33 rows=1 width=36)
Group Key: eiop.product_id
-> Nested Loop (cost=0.00..2.31 rows=1 width=41)
Join Filter: (eiop.erp_inventory_overflow_id = eio.id)
-> Seq Scan on tbl_erp_inventory_overflow_products eiop (cost=0.00..1.18 rows=1 width=45)
Filter: (product_id = 1372)
-> Seq Scan on tbl_erp_inventory_overflows eio (cost=0.00..1.12 rows=1 width=4)
Filter: (status = 1)
-> GroupAggregate (cost=1.15..2.35 rows=1 width=36)
Group Key: eibp.product_id
-> Hash Join (cost=1.15..2.33 rows=1 width=9)
Hash Cond: (eib_1.id = eibp.erp_inventory_build_id)
-> Seq Scan on tbl_erp_inventory_builds eib_1 (cost=0.00..1.15 rows=6 width=4)
Filter: (status = 1)
-> Hash (cost=1.14..1.14 rows=1 width=13)
-> Seq Scan on tbl_erp_inventory_build_products eibp (cost=0.00..1.14 rows=1 width=13)
Filter: (product_id = 1372)
-> GroupAggregate (cost=0.00..2.19 rows=1 width=36)
Group Key: eidp.product_id
-> Nested Loop (cost=0.00..2.18 rows=1 width=9)
Join Filter: (eidp.erp_inventory_disassemble_id = eid_1.id)
-> Seq Scan on tbl_erp_inventory_disassemble_products eidp (cost=0.00..1.10 rows=1 width=13)
Filter: (product_id = 1372)
-> Seq Scan on tbl_erp_inventory_disassembles eid_1 (cost=0.00..1.06 rows=1 width=4)
Filter: (status = 1)
-> GroupAggregate (cost=0.00..24.03 rows=1 width=36)
Group Key: eitp.product_id
-> Nested Loop (cost=0.00..24.01 rows=1 width=36)
Join Filter: (eitp.erp_inventory_transfer_id = eit_1.id)
-> Seq Scan on tbl_erp_inventory_transfer_products eitp (cost=0.00..11.88 rows=1 width=40)
Filter: (product_id = 1372)
-> Seq Scan on tbl_erp_inventory_transfers eit_1 (cost=0.00..12.12 rows=1 width=4)
Filter: (status = 1)
-> GroupAggregate (cost=0.00..2.18 rows=1 width=36)
Group Key: esrp.product_id
-> Nested Loop (cost=0.00..2.16 rows=1 width=9)
Join Filter: (esrp.erp_sales_return_id = esr.id)
-> Seq Scan on tbl_erp_sales_return_products esrp (cost=0.00..1.07 rows=1 width=13)
Filter: (product_id = 1372)
-> Seq Scan on tbl_erp_sales_returns esr (cost=0.00..1.07 rows=1 width=4)
Filter: (status = 1)
-> Hash (cost=16.07..16.07 rows=7 width=36)
-> Subquery Scan on price (cost=0.00..16.07 rows=7 width=36)
-> GroupAggregate (cost=0.00..16.00 rows=7 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..15.88 rows=7 width=14)
Filter: (product_id = 1372)