Re: forcing use of a specific (expression) index? - Mailing list pgsql-general

From Richard Huxton
Subject Re: forcing use of a specific (expression) index?
Date
Msg-id 4639A9F1.9050606@archonet.com
Whole thread Raw
In response to forcing use of a specific (expression) index?  ("Dan Weber" <weberdan@gmail.com>)
Responses Re: forcing use of a specific (expression) index?
List pgsql-general
Dan Weber wrote:
> I made an expression index specifically for that where clause:
>
> CREATE INDEX special_testing_idx on my_table (((bool_1 or
> int_1 = 0) AND (int_2 IS NULL) AND (int_3 IS
> NULL) AND (protocol = 2)));

No, you haven't. What you've done here is create an index *for that
expression*. And it's not terribly useful because your expression will
only have two possible values: true, false.

What you were after is something like:

CREATE INDEX special_idx2 ON my_table (id) WHERE (...long expression...)

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Cross-schema inheritence problem
Next
From: Richard Huxton
Date:
Subject: Re: Have I b0rked something? Slow comparisons on "where x in (...)"