pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jim Nasby <jim@nasby.net>
To: Boguk Maxim <astar@rambler-co.ru>
Cc: pgsql-admin@postgresql.org
Subject: Re: Possible bug in planner (or planner not enough wise in some cases)
Date: Thu, 21 Sep 2006 22:45:07 -0400
Message-ID: <256DACC7-6168-4615-BA7A-354BE59331DF@nasby.net> (raw)
In-Reply-To: <E848E9BE34F3DA45BB56B5BEEC33204B1BC033@prime.rambler.ramblermedia.com>
References: <E848E9BE34F3DA45BB56B5BEEC33204B1BC033@prime.rambler.ramblermedia.com>


On Sep 20, 2006, at 5:32 AM, Boguk Maxim wrote:

> Hm i have no idea how to rewrite 'OR' conditions with subqueries as  
> joins
> (exept using 'UNION' as writen end of my message)
> Are you sure it is possible?
>
> WHERE
> (parent_id IN (SELECT tt.id FROM el_comment as tt WHERE  
> tt.user_id=112 AND tt.status=1))
> OR
> (text_id IN (SELECT el_text.id FROM el_text WHERE  
> el_text.user_id=112))
>>> somedb=# EXPLAIN ANALYZE SELECT count(*) FROM el_comment
>> WHERE ((parent_id IN (SELECT tt.id FROM el_comment as tt
>> WHERE tt.user_id = 112 AND tt.status=1)) OR (text_id IN
>> (SELECT el_text.id FROM el_text WHERE el_text.user_id =
>> 112))) AND status=1;

... FROM el_comment c, el_comment tt, el_text t
WHERE ( ( c.parent_id = tt.id AND tt.user_id = 112 AND tt.status = 1 )
	OR ( c.text_id = t.id AND  t.user_id = 112 ) ) AND c.status=1;

--
Jim Nasby                                    jimn@enterprisedb.com
EnterpriseDB      http://enterprisedb.com      512.569.9461 (cell)





view thread (4+ messages)

Message-ID: <256DACC7-6168-4615-BA7A-354BE59331DF@nasby.net>
Permalink:  ../256DACC7-6168-4615-BA7A-354BE59331DF@nasby.net/
Also on:    postgresql.org/message-id/256DACC7-6168-4615-BA7A-354BE59331DF@nasby.net

 · 

reply

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-admin@postgresql.org
  Cc: jim@nasby.net, astar@rambler-co.ru
  Subject: Re: Possible bug in planner (or planner not enough wise in some cases)
  In-Reply-To: <256DACC7-6168-4615-BA7A-354BE59331DF@nasby.net>
  References: <E848E9BE34F3DA45BB56B5BEEC33204B1BC033@prime.rambler.ramblermedia.com> <256DACC7-6168-4615-BA7A-354BE59331DF@nasby.net>

* 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