相关疑难解决方法(0)

为什么PostgreSQL(9.1)不使用索引进行简单的相等选择?

我的表lead有一个索引:

\d lead
...
Indexes:
    "lead_pkey" PRIMARY KEY, btree (id)
    "lead_account__c" btree (account__c)
    ...
    "lead_email" btree (email)
    "lead_id_prefix" btree (id text_pattern_ops)
Run Code Online (Sandbox Code Playgroud)

为什么PG(9.1)不使用索引进行这种直接的平等选择?电子邮件几乎都是独一无二的....

db=> explain select * from lead where email = 'blah';
                         QUERY PLAN
------------------------------------------------------------
 Seq Scan on lead  (cost=0.00..319599.38 rows=1 width=5108)
   Filter: (email = 'blah'::text)
(2 rows)
Run Code Online (Sandbox Code Playgroud)

其他索引命中查询似乎没问题(虽然我不知道为什么这个不只是使用pkey索引):

db=> explain select * from lead where id = '';
                                  QUERY PLAN
------------------------------------------------------------------------------
 Index Scan using lead_id_prefix on lead  (cost=0.00..8.57 rows=1 width=5108)
   Index Cond: (id = ''::text)
(2 rows) …
Run Code Online (Sandbox Code Playgroud)

postgresql indexing postgresql-9.1

5
推荐指数
1
解决办法
504
查看次数

标签 统计

indexing ×1

postgresql ×1

postgresql-9.1 ×1