Re: forcing use of a specific (expression) index?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Dan Weber" <weberdan(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: forcing use of a specific (expression) index?
Date: 2007-05-02 21:38:16
Message-ID: 21595.1178141896@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Dan Weber" <weberdan(at)gmail(dot)com> writes:
> I have the following query:

> SELECT columns FROM my_table WHERE (bool_1 or int_1 = 0)
> AND (int_2 IS NULL) AND (int_3 IS NULL) AND (protocol =
> 2) ORDER BY id LIMIT 1;

> 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)));

A partial index would be WAY more useful than that:

create index on my_table(id) where (bool_1 or int_1 = 0) ...

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-05-02 21:59:49 Re: Have I b0rked something? Slow comparisons on "where x in (...)"
Previous Message Dan Weber 2007-05-02 20:18:32 forcing use of a specific (expression) index?