Re: Problem with functional indexes

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Bruno Wolff III <bruno(at)wolff(dot)to>
Cc: Diogo de Oliveira Biazus <diogo(at)ikono(dot)com(dot)br>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Problem with functional indexes
Date: 2003-02-21 20:27:35
Message-ID: Pine.LNX.4.33.0302211325560.19678-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 21 Feb 2003, Bruno Wolff III wrote:

> On Fri, Feb 21, 2003 at 16:04:52 -0300,
> Diogo de Oliveira Biazus <diogo(at)ikono(dot)com(dot)br> wrote:
> > Hi everybody,
> > I'm having a problem with functional indexes.
> >
> > When I compare the function index using the "=" operator, it uses the index;
> > Otherwise, if I use the "<>" operator it uses SeqScan...even when i set
> > enable_seqscan to off.
> >
> > Ex.:
> > SELECT * FROM MyTable WHERE myFunction(myField) = 'just testing';
> > -> Works just fine.
> > SELECT * FROM MyTable WHERE myFunction(myField) <> 'just testing';
> > -> All I get is SeqScan...
>
> I don't believe <> functions are generally going to be able to use indexes.
> However, you really don't want to. The figure I have seen on these lists
> is that if you are going to hit over 10% of the records a sequencial
> scan is probably going to be faster.

The general rule of thumb is that the where condition in the select and
the create index need to match. So, creating a functional index like:

create index test on table (field2) where function (field2) <> 'someval';

should work for

select * from table where function(field2) <> 'someval';

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Devrim GUNDUZ 2003-02-21 20:35:36 =?ISO-8859-9?Q?=DDlgi:=20?=Non-English lists and User Groups
Previous Message Dmitry Tkach 2003-02-21 20:17:36 Re: A problem with sequences...