PostgreSQL OR performance - Mailing list pgsql-performance

From Віталій Тимчишин
Subject PostgreSQL OR performance
Date
Msg-id 331e40660811050312u552cab53ifa88e493e1c4f7ac@mail.gmail.com
Whole thread Raw
Responses Re: PostgreSQL OR performance
Re: PostgreSQL OR performance
List 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?

pgsql-performance by date:

Previous
From: "praveen"
Date:
Subject: Re: [ADMIN] Installation Error of postgresql-8.1.5 with perl.
Next
From: Peter Schuller
Date:
Subject: lru_multiplier and backend page write-outs