QUERY PLAN
Limit (cost=627.78..627.79 rows=2 width=540)
-> Sort (cost=627.78..627.79 rows=2 width=540)
Sort Key: p.in_out_at DESC NULLS LAST, p.updated_at DESC
-> GroupAggregate (cost=627.62..627.77 rows=2 width=540)
Group Key: p.id
-> Sort (cost=627.62..627.63 rows=2 width=540)
Sort Key: p.id
-> Hash Left Join (cost=611.20..627.61 rows=2 width=540)
Hash Cond: (p.id = tmp4.product_id)
-> Hash Left Join (cost=608.53..624.93 rows=2 width=476)
Hash Cond: (p.id = tmp3.product_id)
-> Hash Left Join (cost=604.45..620.83 rows=2 width=412)
Hash Cond: (p.id = tmp2.product_id)
-> Hash Left Join (cost=553.36..569.74 rows=2 width=348)
Hash Cond: (p.id = tmp5.product_id)
-> Hash Left Join (cost=535.42..551.78 rows=2 width=284)
Hash Cond: (p.id = tmp1.product_id)
-> Nested Loop (cost=498.11..514.47 rows=2 width=156)
-> Group (cost=497.83..497.84 rows=2 width=4)
Group Key: p_1.id
-> Sort (cost=497.83..497.84 rows=2 width=4)
Sort Key: p_1.id
-> Hash Left Join (cost=347.43..497.82 rows=2 width=4)
Hash Cond: (eip.id = esosps.erp_inventory_product_id)
-> Hash Left Join (cost=334.18..484.53 rows=2 width=8)
Hash Cond: (epips.project_id = sc.from_project)
Filter: ((lower((p_1.name)::text) ~~* '%爱国者%'::text) OR (p_1.pinyin_shortcut ~~* '%爱国者%'::text) OR (lower((pt.name)::text) ~~* '%爱国者%'::text) OR (lower((pb.name)::text) ~~* '%爱国者%'::text) OR (lower((ps.name)::text) ~~* '%爱国者%'::text) OR (lower((pc.name)::text) ~~* '%爱国者%'::text) OR (lower(p_1.description) ~~* '%爱国者%'::text) OR (lower((sc.serial_no)::text) ~~* '%爱国者%'::text))
-> Hash Left Join (cost=194.37..237.63 rows=2121 width=171)
Hash Cond: (p_1.product_component = pc.id)
-> Hash Left Join (cost=188.77..226.31 rows=2121 width=159)
Hash Cond: (p_1.product_serie = ps.id)
-> Hash Left Join (cost=126.86..158.83 rows=2121 width=134)
Hash Cond: (p_1.product_type = pt.id)
-> Hash Left Join (cost=124.44..150.46 rows=2121 width=126)
Hash Cond: (p_1.product_brand = pb.id)
-> Hash Right Join (cost=116.54..136.88 rows=2121 width=122)
Hash Cond: (eip.product_id = p_1.id)
-> Hash Left Join (cost=17.82..36.85 rows=497 width=12)
Hash Cond: (eip.erp_purchase_inbound_id = epis.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..12.97 rows=497 width=32)
-> Hash (cost=15.17..15.17 rows=212 width=8)
-> Hash Right Join (cost=10.77..15.17 rows=212 width=8)
Hash Cond: (epips.erp_purchase_inbound_id = epis.id)
-> Seq Scan on tbl_erp_purchase_inbound_projects epips (cost=0.00..3.89 rows=189 width=8)
-> Hash (cost=8.12..8.12 rows=212 width=4)
-> Seq Scan on tbl_erp_purchase_inbounds epis (cost=0.00..8.12 rows=212 width=4)
-> Hash (cost=72.21..72.21 rows=2121 width=114)
-> Seq Scan on tbl_products p_1 (cost=0.00..72.21 rows=2121 width=114)
-> 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=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=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=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=118.25..118.25 rows=1725 width=20)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..118.25 rows=1725 width=20)
-> Hash (cost=8.11..8.11 rows=411 width=8)
-> Seq Scan on tbl_erp_sales_outbound_spent_products esosps (cost=0.00..8.11 rows=411 width=8)
-> Index Scan using tbl_products_pkey on tbl_products p (cost=0.28..8.30 rows=1 width=156)
Index Cond: (id = p_1.id)
-> Hash (cost=32.71..32.71 rows=368 width=132)
-> Subquery Scan on tmp1 (cost=21.67..32.71 rows=368 width=132)
-> HashAggregate (cost=21.67..29.03 rows=368 width=164)
Group Key: sub1.product_id
-> Seq Scan on tbl_erp_inventory_products sub1 (cost=0.00..12.97 rows=497 width=16)
-> Hash (cost=16.69..16.69 rows=100 width=68)
-> Subquery Scan on tmp5 (cost=14.19..16.69 rows=100 width=68)
-> HashAggregate (cost=14.19..15.69 rows=100 width=72)
Group Key: p_2.product_id
-> Hash Join (cost=1.16..13.19 rows=100 width=68)
Hash Cond: (p_2.erp_inventory_overflow_id = e.id)
-> Seq Scan on tbl_erp_inventory_overflow_products p_2 (cost=0.00..11.60 rows=160 width=72)
-> Hash (cost=1.10..1.10 rows=5 width=4)
-> Seq Scan on tbl_erp_inventory_overflows e (cost=0.00..1.10 rows=5 width=4)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Hash (cost=46.48..46.48 rows=368 width=68)
-> Subquery Scan on tmp2 (cost=37.28..46.48 rows=368 width=68)
-> HashAggregate (cost=37.28..42.80 rows=368 width=68)
Group Key: e_1.product_id
-> Hash Left Join (cost=19.18..33.15 rows=551 width=13)
Hash Cond: (p_3.erp_inventory_product_id = e_1.id)
-> Seq Scan on tbl_erp_inventory_product_spents p_3 (cost=0.00..12.51 rows=551 width=13)
-> Hash (cost=12.97..12.97 rows=497 width=8)
-> Seq Scan on tbl_erp_inventory_products e_1 (cost=0.00..12.97 rows=497 width=8)
-> Hash (cost=3.48..3.48 rows=49 width=68)
-> Subquery Scan on tmp3 (cost=2.25..3.48 rows=49 width=68)
-> HashAggregate (cost=2.25..2.99 rows=49 width=104)
Group Key: p_4.product_id
-> Seq Scan on tbl_erp_inventory_start_products p_4 (cost=0.00..1.50 rows=50 width=46)
-> Hash (cost=2.55..2.55 rows=9 width=68)
-> Subquery Scan on tmp4 (cost=2.33..2.55 rows=9 width=68)
-> HashAggregate (cost=2.33..2.46 rows=9 width=72)
Group Key: p_5.product_id
-> Hash Join (cost=1.06..2.24 rows=9 width=68)
Hash Cond: (p_5.erp_inventory_lost_id = e_2.id)
-> Seq Scan on tbl_erp_inventory_lost_products p_5 (cost=0.00..1.13 rows=13 width=72)
-> Hash (cost=1.04..1.04 rows=2 width=4)
-> Seq Scan on tbl_erp_inventory_losts e_2 (cost=0.00..1.04 rows=2 width=4)
Filter: (status = ANY ('{2,5}'::integer[]))