Skip to content

POSTGRESQL-Explain

#writing
#sql优化

sql
explain select id, mobile from hd_personal_base where mobile is not null;  
-- Seq Scan on hd_personal_base  (cost=0.00..43992.19 rows=518971 width=19)  
--   Filter: (mobile IS NOT NULL)  
  
explain select id, mobile from hd_personal_base where mobile = '13780631839';  
-- Seq Scan on hd_personal_base  (cost=0.00..45540.99 rows=4 width=19)  
--   Filter: ((mobile)::text = '13780631839'::text)  
  
explain select id, mobile from hd_personal_base where id = 891181;  
-- Index Scan using pk_personal_base on hd_personal_base  (cost=0.42..8.44 rows=1 width=19)  
--   Index Cond: (id = 891181)
explain select id, mobile from hd_personal_base where mobile is not null;  
-- Seq Scan on hd_personal_base  (cost=0.00..43992.19 rows=518971 width=19)  
--   Filter: (mobile IS NOT NULL)  
  
explain select id, mobile from hd_personal_base where mobile = '13780631839';  
-- Seq Scan on hd_personal_base  (cost=0.00..45540.99 rows=4 width=19)  
--   Filter: ((mobile)::text = '13780631839'::text)  
  
explain select id, mobile from hd_personal_base where id = 891181;  
-- Index Scan using pk_personal_base on hd_personal_base  (cost=0.42..8.44 rows=1 width=19)  
--   Index Cond: (id = 891181)

14.1. 使用EXPLAIN

#writing