Multiple-index optimization not working for = ANY operator

From: "Jimmy Choi" <JCHOI(at)altera(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Multiple-index optimization not working for = ANY operator
Date: 2006-02-15 22:56:05
Message-ID: 6E3775AF29598B46AA3F102067A510F1D370A8@tor-ismsg01.altera.priv.altera.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

From Section 11.4 of the Postgres 8.1 documentation, a new optimization
is shipped in the latest release.

"... a query like WHERE x = 42 OR x = 47 OR x = 53 OR x = 99 could be
broken down into four separate scans of an index on x, each scan using
one of the query clauses. The results of these scans are then ORed
together to produce the result."

While the feature works fine for cases such as:

SELECT * FROM foo WHERE id IN (1, 2);

And

SELECT * FROM foo WHERE id = 1 OR id = 2;

I find that it doesn't work (i.e. index is not used and a sequential
scan is needed), if I have the following instead:

SELECT * FROM foo WHERE id = ANY (ARRAY[1,2]);

Is this expected? The reason I would like the last case to work is that
my plpgsql function takes as input an array of IDs, and so I cannot
write my query using the first two forms above.

Any idea on how I can get around this is greatly appreciated.

Thanks
Jimmy

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rick Gigger 2006-02-15 22:56:36 Re: I see this as the end of BDB in MySQL without a doubt.
Previous Message Tom Lane 2006-02-15 22:52:29 Re: Pg_hba.conf issues