PostgreSQL OR performance

From: Віталій Тимчишин <tivv00(at)gmail(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: PostgreSQL OR performance
Date: 2008-11-05 11:12:32
Message-ID: 331e40660811050312u552cab53ifa88e493e1c4f7ac@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hello.

For a long time already I can see very poor OR performance in postgres.
If one have query like "select something from table where condition1 or
condition2" it may take ages to execute while
"select something from table where condition1" and "select something from
table where condition2" are executed very fast and
"select something from table where condition1 and not condition2 union all
select something from table where condition2" gives required results fast

For example, in my current query for "condition1" optimizer gives 88252, for
"condition1 and not condition2" it is 88258, for "condition2" it is 99814.
And for "condition1 or condition2" it is 961499627680. And it does perform
this way.

All is more or less good when "select" part is easy and query can be easily
rewritten. But for complex queries it looks ugly and if the query is
autogenerated, moving autogeneration mechanism from creating simple clean
"where" to unions is not an easy task.

So the question is: Do I miss something? Can this be optimized?

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Peter Schuller 2008-11-05 12:28:30 lru_multiplier and backend page write-outs
Previous Message praveen 2008-11-05 07:01:21 Re: Installation Error of postgresql-8.1.5 with perl.