Re: optimizing LIKE '%2345' queries

From: Gene <genekhart(at)gmail(dot)com>
To: "Tarhon-Onu Victor" <mituc(at)iasi(dot)rdsnet(dot)ro>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: optimizing LIKE '%2345' queries
Date: 2006-07-04 20:27:44
Message-ID: 430d92a20607041327r4bcd6306ofec4adec6856c037@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Thanks for the suggestion. Actually I went ahead and created a reverse
function using plpgsql, created an index using reverse column and now
my queries use "where reverse(column) like reverse('%2345') and it's
using the index like i hoped it would! Now if I could figure out how
to optimize like '%2345%' queries. I don't want to create many
indexes though the table is very write heavy.

> > Is the only way to create a reverse function and create an index using
> > the reverse function and modify queries to use:
> >
> > where reverse(column) like reverse('%2345') ?
>
> Hmm.. interesting.
> If (and only if) the records stored in "column" column have fixed
> length (say, all are 50 characters in length) you could create and index
> on, say, substring(column,45,50), and use this in the WHERE clauses in
> your queries.
> Or if the length of those records is not the same maybe it is
> feasible to create an ondex on substring(column, length(column)-5,
> length(column)).
>
> --
> Any views or opinions presented within this e-mail are solely those of
> the author and do not necessarily represent those of any company, unless
> otherwise expressly stated.
>

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Chris 2006-07-05 00:22:42 Re: optimizing LIKE '%2345' queries
Previous Message Tom Lane 2006-07-04 18:15:54 Re: query very slow when enable_seqscan=on