I have a column foo_bar of type text indexed with text_pattern_ops:
profiles_foo_bar_txt" btree (foo_bar text_pattern_ops)
My psql server is configured with UTF-8:
lc_collate
------------
en_US.utf8
(1 row)
But for some reason the index is not being used for pattern matching queries:
EXPLAIN SELECT "profiles".* FROM "profiles" WHERE foo_bar LIKE 'Mar%';
results in
QUERY PLAN
-----------------------------------------------------------------
Seq Scan on profiles (cost=0.00..2288.12 rows=51370 width=142)
Filter: (foo_bar ~~ 'Mar%'::text)
(2 rows)
Am I missing something? Any ideas on what I might be doing wrong?
EDIT:
As requested on Frank Heiken's comment, here's the out put when using EXPLAIN(ANALYZE, VERBOSE, BUFFERS):
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Seq Scan on public.profiles (cost=0.00..2436.12 rows=51370 width=11) (actual time=0.013..14.224 rows=51370 loops=1)
Output: foo_bar
Filter: (profiles.foo_bar ~~ 'Mar%'::text)
Rows Removed by Filter: 1
Buffers: shared hit=1794
Planning Time: 0.077 ms
Execution Time: 16.932 ms
(7 rows)
So it seems that indded the index with text_pattern_ops it not being for that pattern matching query.
Any ideas?