Re: Or selection on index versus union - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Or selection on index versus union
Date
Msg-id 20051004210838.GA72829@winnie.fuhr.org
Whole thread Raw
In response to Or selection on index versus union  (han.holl@informationslogik.nl)
Responses Re: Or selection on index versus union  (han.holl@informationslogik.nl)
List pgsql-general
On Tue, Oct 04, 2005 at 09:32:41PM +0200, han.holl@informationslogik.nl wrote:
> I've got a table with an index, let's call it fase.
>
> The following query is fine: 'select something from table where fase = '1';
>
> However, this is disastrously slow:
> select something from table where fase = '1' or fase = '2';

Could we see some EXPLAIN ANALYZE output?  What version of PostgreSQL
are you using?  Have you run VACUUM ANALYZE on the table to remove
dead tuples and update the statistics?  Have you considered clustering
the table on fase's index?

It might be useful to see the output of the following queries,
assuming the table name is foo:

SET enable_seqscan TO on;
SET enable_indexscan TO off;
EXPLAIN ANALYZE SELECT something FROM foo WHERE fase = '1';
EXPLAIN ANALYZE SELECT something FROM foo WHERE fase = '2';
EXPLAIN ANALYZE SELECT something FROM foo WHERE fase = '1' OR fase = '2';

SET enable_seqscan TO off;
SET enable_indexscan TO on;
EXPLAIN ANALYZE SELECT something FROM foo WHERE fase = '1';
EXPLAIN ANALYZE SELECT something FROM foo WHERE fase = '2';
EXPLAIN ANALYZE SELECT something FROM foo WHERE fase = '1' OR fase = '2';

SHOW random_page_cost;
SHOW effective_cache_size;
SELECT version();

\x
SELECT * FROM pg_stats WHERE tablename = 'foo' AND attname = 'fase';

BTW, pgsql-performance is a list dedicated to performance issues,
so you might want to ask performance-related questions there.

--
Michael Fuhr

pgsql-general by date:

Previous
From: Douglas McNaught
Date:
Subject: Re: Isolated transactions?
Next
From: han.holl@informationslogik.nl
Date:
Subject: Re: Or selection on index versus union