From: Віталій Тимчишин <tivv00@gmail.com>
To: pgsql-performance@postgresql.org
Subject: PostgreSQL OR performance
Date: Wed, 5 Nov 2008 13:12:32 +0200
Message-ID: <331e40660811050312u552cab53ifa88e493e1c4f7ac@mail.gmail.com> (raw)
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?
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: tivv00@gmail.com
Subject: Re: PostgreSQL OR performance
In-Reply-To: <331e40660811050312u552cab53ifa88e493e1c4f7ac@mail.gmail.com>
References: <331e40660811050312u552cab53ifa88e493e1c4f7ac@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox