Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 711F4650403 for ; Wed, 5 Nov 2008 12:31:40 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 16930-03 for ; Wed, 5 Nov 2008 12:31:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.226]) by mail.postgresql.org (Postfix) with ESMTP id 396F86503F6 for ; Wed, 5 Nov 2008 12:31:38 -0400 (AST) Received: by rv-out-0506.google.com with SMTP id b25so67156rvf.43 for ; Wed, 05 Nov 2008 08:31:37 -0800 (PST) Received: by 10.141.206.13 with SMTP id i13mr514271rvq.271.1225902697314; Wed, 05 Nov 2008 08:31:37 -0800 (PST) Received: from ?192.168.1.10? (c-24-7-36-154.hsd1.ca.comcast.net [24.7.36.154]) by mx.google.com with ESMTPS id b8sm177404rvf.3.2008.11.05.08.31.35 (version=SSLv3 cipher=RC4-MD5); Wed, 05 Nov 2008 08:31:36 -0800 (PST) Subject: Re: PostgreSQL OR performance From: Jeff Davis To: =?UTF-8?Q?=D0=92=D1=96=D1=82=D0=B0=D0=BB=D1=96=D0=B9_?= =?UTF-8?Q?=D0=A2=D0=B8=D0=BC=D1=87=D0=B8=D1=88=D0=B8=D0=BD?= Cc: pgsql-performance@postgresql.org In-Reply-To: <331e40660811050312u552cab53ifa88e493e1c4f7ac@mail.gmail.com> References: <331e40660811050312u552cab53ifa88e493e1c4f7ac@mail.gmail.com> Content-Type: text/plain; charset=utf-8 Date: Wed, 05 Nov 2008 08:31:40 -0800 Message-Id: <1225902700.1432.53.camel@jdavis> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 Content-Transfer-Encoding: 8bit X-Archive-Number: 200811/10 X-Sequence-Number: 31741 On Wed, 2008-11-05 at 13:12 +0200, Віталій Тимчишин wrote: > 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 > What version are you using? Have you run "VACUUM ANALYZE"? Next, do: EXPLAIN ANALYZE select something from table where condition1 or condition2; for each of the queries, unless that query takes so long you don't want to wait for the result. In that case, omit the "ANALYZE" and just do "EXPLAIN ...". Then post those results to the list. These tell us what plans PostgreSQL is choosing and what it estimates the costs to be. If it's the output of EXPLAIN ANALYZE, it also runs the query and tells us what the costs really are. From that, we can see where the planner is going wrong, and what you might do to change it. Regards, Jeff Davis