From: | "Stuart McGraw" <smcg2297(at)frii(dot)com> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: slow view |
Date: | 2006-10-12 04:15:58 |
Message-ID: | NDBBKHIAJKGCOIMLDMGJKEEBGGAB.smcg2297@frii.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 2006/10/11 Stuart wrote:
> [..]
Apologies for following up my own post, but after
struggling with that query for over a day, I figured
out the answer within thirty minutes of posting.
(Sigh)
My slow query was:
> SELECT p.id AS pid, a.id AS aid, sub.bid AS bid
> FROM p
> JOIN a ON a.p=p.id
> LEFT JOIN (
> SELECT a.id AS aid, b.id as bid
> FROM a
> LEFT JOIN b ON b.p=a.p
> LEFT JOIN x ON x.a=a.id AND x.b=b.id
> WHERE x.a IS NULL
> ) AS sub ON sub.aid=a.id
> WHERE p.id=1;
Including the parent table p in the inner select was
all it took.
SELECT p.id AS pid, a.id AS aid, sub.bid AS bid
FROM p
JOIN a ON a.p=p.id
LEFT JOIN (
SELECT p.id AS pid, a.id AS aid, b.id as bid
FROM p
JOIN a ON a.p=p.id
LEFT JOIN b ON b.p=a.p
LEFT JOIN x ON x.a=a.id AND x.b=b.id
WHERE x.a IS NULL
) AS sub ON sub.aid=a.id AND sub.pid=p.id
WHERE p.id=1;
From | Date | Subject | |
---|---|---|---|
Next Message | Bryce Nesbitt | 2006-10-12 05:11:51 | Is this a bug? Deleting a column deletes the constraint. |
Previous Message | Stuart | 2006-10-12 01:18:55 | slow view |