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