Re: Definitive answer: can functions use indexes?

From: Seamus Abshere <seamus(at)abshere(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Definitive answer: can functions use indexes?
Date: 2016-01-07 00:01:12
Message-ID: 1452124872.2269413.484993730.4FA20D5F@webmail.messagingengine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jan 6, 2016, at 08:41 PM, Tom Lane wrote:
> Seamus Abshere <seamus(at)abshere(dot)net> writes:
> > -> Can a function like `LEFT()` use an index?
> Since the question makes little sense as stated, I'm going to assume
> you mean "can a query like SELECT ... WHERE left(foo, 3) = 'bar'
> use an index on column foo?"
>
> The answer to that is no, there is no such optimization built into
> Postgres. (In principle there could be, but I've not heard enough
> requests to make me think we'd ever pursue it.)
>
> The equivalent optimization that *is* built in, and has been for
> a long time, is for LIKE: "SELECT ... WHERE foo LIKE 'bar%'" can
> use an index on foo, at least if it's an index sorted according to
> C collation.

hi Tom,

I should have been more general. In layman's/narrative terms, what's the
deal with functions vs. operators for postgres indexes?

For example, `exist(hstore,text)` vs. `hstore ? text` ?

Thank you!
Seamus

PS. If I have understood correctly over the years, in order for the
query planner to use indexes, it needs to see operators - functions are
opaque to it. I'm looking for a bit more narrative on this to round out
my understanding.

--
Seamus Abshere, SCEA
+598 99 54 99 54
https://github.com/seamusabshere

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2016-01-07 00:27:07 Re: Definitive answer: can functions use indexes?
Previous Message Tom Lane 2016-01-06 23:41:53 Re: Definitive answer: can functions use indexes?