I'm running the following query, and the index I have created is not used; PostgreSQL uses a sequential scan instead of an index scan.
Query:
EXPLAIN (analyze, buffers)
SELECT date,
company,
host
FROM mytable
where date < ( now() - INTERVAL '10 days' )
The index I have created:
CREATE INDEX ix_mytable_company ON mytable USING btree (
host,
cumpany,
date
)
thanks for the reply but i still have problems
get this no matter what i try:
Seq Scan on mytable (cost=0.00..5577644.22 rows=65056015 width=34) (actual time=120.238..43372.108 rows=63058234 loops=1) Filter: (date < (now() - '10 days'::interval)) Rows Removed by Filter: 2543550 Buffers: shared hit=581914 read=3847699 Planning Time: 1.263 ms JIT: Functions: 4 Options: Inlining true, Optimization true, Expressions true, Deforming true Timing: Generation 0.495 ms, Inlining 66.265 ms, Optimization 37.358 ms, Emission 16.325 ms, Total 120.443 ms Execution Time: 46204.494 ms
view index shows this CREATE INDEX ix_mytable_company ON public.mytable USING btree (date) INCLUDE (host, cumpany)
and i still run: EXPLAIN (analyze, buffers) SELECT date,cumpany,host FROM mytable where date < (now() - INTERVAL '10 days' )
6.5 milj rows should qualify for an index scan i think.