V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
leopard7777777
V2EX  ›  PostgreSQL

postgresql timestamp 索引问题

  •  
  •   leopard7777777 · 2018-12-29 11:04:43 +08:00 · 3287 次点击
    这是一个创建于 1916 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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

    2 条回复    2018-12-29 16:29:08 +08:00
    EchoUtopia
        2
    EchoUtopia  
       2018-12-29 16:29:08 +08:00
    可能是 postgres 觉得数据量大了走索引不划算,因为还要回表
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3204 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 12:18 · PVG 20:18 · LAX 05:18 · JFK 08:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.