PostgreSQL does not use the gist index (btree_gist) when using the distance operator

177 views Asked by At

When I use the distance operator with a gist index, potgres still performs a sequential scan.

create extension btree_gist;

create table telemetry1(
    time timestamptz primary KEY,
    value DOUBLE PRECISION
);



create index telemetry1_idx on telemetry1 using gist(time);

insert into telemetry1
select t.time, random()
from generate_series(timestamptz '2021-07-24 00:00:00.000000',
                     timestamptz '2021-07-25 23:59:59.000000',
                     interval '250 milliseconds') as t(time);

analyze telemetry1;
                 
explain
select * 
from telemetry1 as t
where t.time <-> timestamptz '2021-07-25' = interval '1 year';
Gather  (cost=1000.00..13603.38 rows=5184 width=16)
  Workers Planned: 2
  ->  Parallel Seq Scan on telemetry1 t  (cost=0.00..12084.98 rows=2160 width=16)
        Filter: (("time" <-> '2021-07-25 00:00:00-03'::timestamp with time zone) = '1 year'::interval)

0

There are 0 answers