Re: Possible bug in planner (or planner not enough wise in some cases)

From: Jim Nasby <jim(at)nasby(dot)net>
To: Boguk Maxim <astar(at)rambler-co(dot)ru>
Cc: <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Possible bug in planner (or planner not enough wise in some cases)
Date: 2006-09-22 02:45:07
Message-ID: 256DACC7-6168-4615-BA7A-354BE59331DF@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin


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(at)enterprisedb(dot)com
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Jim Nasby 2006-09-22 02:50:56 Re: WAL configuration and REINDEX
Previous Message Thomas Vatter 2006-09-21 17:53:32 The server lacks instrumentation functions