leopard7777777

postgresql timestamp 索引问题

  •  
  •   leopard7777777 · Dec 29, 2018 · 4173 views
    This topic created in 2700 days ago, the information mentioned may be changed or developed.

    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 replies    2018-12-29 16:29:08 +08:00
    EchoUtopia
        2
    EchoUtopia  
       Dec 29, 2018
    可能是 postgres 觉得数据量大了走索引不划算,因为还要回表
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   949 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 21:40 · PVG 05:40 · LAX 14:40 · JFK 17:40
    ♥ Do have faith in what you're doing.