Re: Definitive answer: can functions use indexes? - Mailing list pgsql-general

From Seamus Abshere
Subject Re: Definitive answer: can functions use indexes?
Date
Msg-id 1452124872.2269413.484993730.4FA20D5F@webmail.messagingengine.com
Whole thread Raw
In response to Re: Definitive answer: can functions use indexes?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Definitive answer: can functions use indexes?
List pgsql-general
On Wed, Jan 6, 2016, at 08:41 PM, Tom Lane wrote:
> Seamus Abshere <seamus@abshere.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


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Definitive answer: can functions use indexes?
Next
From: Tom Lane
Date:
Subject: Re: Definitive answer: can functions use indexes?