postgresql timestamp 索引问题

2018-12-29 11:04:43 +08:00
 leopard7777777

CREATE INDEX idx_e_d ON public.expense USING btree (date);

explain select * from "public"."expense" where date > '2018-12-19'

Seq Scan on expense (cost=0.00..15133.15 rows=181367 width=41)

Filter: (date > '2018-12-19 00:00:00'::timestamp without time zone)

explain select * from "public"."expense" where date > '2018-12-20'

Bitmap Heap Scan on expense (cost=5245.18..14770.65 rows=162678 width=41)

Recheck Cond: (date > '2018-12-20 00:00:00'::timestamp without time zone)

-> Bitmap Index Scan on idx_e_d (cost=0.00..5204.51 rows=162678 width=0)

    Index Cond: (date > '2018-12-20 00:00:00'::timestamp without time zone)

日期差一天,不走索引,用的是阿里云的 postgresql 9.4 2 核 4g

3323 次点击
所在节点    PostgreSQL
2 条回复
zbinlin
2018-12-29 12:32:13 +08:00
EchoUtopia
2018-12-29 16:29:08 +08:00
可能是 postgres 觉得数据量大了走索引不划算,因为还要回表

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/522194

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX