PostgreSQL not using index on wildcard
<p>I have a persons table. I want to look them up by using a field <code>person_code</code> which is an alphanumeric string. I have created an index as:</p>

<pre><code>create index my_idx on persons( some_function(person_code) )
</code></pre>

<p>However, when I try something like:</p>

<pre><code>select * from persons where some_function(person_code) like 'mycode%'
</code></pre>

<p>I end up having a sequential scan instead of an index scan. According to <a href="http://www.postgresql.org/docs/9.3/static/functions-matching.html" rel="nofollow noreferrer">Postgres index types documentation</a>, <code>LIKE</code> should make use of an index as long as matching pattern is a constant and is anchored to the beginning of the string.</p>