Re: Functions and Indexes

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Moreno Andreo <moreno(dot)andreo(at)evolu-s(dot)it>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Functions and Indexes
Date: 2024-11-19 11:34:03
Message-ID: c58ac11e7fe0c11d84b3e5fb3244a434d8d87509.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2024-11-19 at 11:53 +0100, Moreno Andreo wrote:
> > > What about if query becomes
> > > SELECT foo1, foo2 FROM bar WHERE (POSITION(foo1 IN 'blah blah') >0)
> >
> > You could create an index like
> >
> >     CREATE INDEX ON bar (position(foo1 IN 'blah blah'));
> >
> > Alternatively, you could have a partial index:
> >
> >     CREATE INDEX ON bar (foo1) INCLUDE (foo2)
> >     WHERE position(foo1 IN 'blah blah') > 0;
>
> Interesting. Never seen this form, I'll look further on it.
>
> I stumbled into
> https://www.cybertec-postgresql.com/en/indexing-like-postgresql-oracle/
> and discovered text_pattern_ops.
> I'm wondering if it can be of any use in my index, that should hold a
> WHERE condition with a combination of LIKE and the POSITION expression
> above.
> More docs to read ... :-)

I don't think "text_pattern_ops" will help here - queries that use LIKE
to search for a substring (LIKE '%string%') cannot make use of a b-tree
index.

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Moreno Andreo 2024-11-19 13:30:37 Re: Functions and Indexes
Previous Message Moreno Andreo 2024-11-19 10:53:44 Re: Functions and Indexes