From: | Manfred Koizar <mkoi-pg(at)aon(dot)at> |
---|---|
To: | josh(at)agliodbs(dot)com |
Cc: | PostgreSQL Performance <pgsql-performance(at)postgresql(dot)org> |
Subject: | Re: Guesses on what this NestLoop is for? |
Date: | 2003-10-28 10:59:36 |
Message-ID: | 3nhspvkbsarcieub1neodds7pr9h6hbtna@email.aon.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On Mon, 27 Oct 2003 15:32:41 -0800, Josh Berkus <josh(at)agliodbs(dot)com>
wrote:
>FROM event_types, events
> LEFT OUTER JOIN ...
>WHERE events.status = 1 or events.status = 11
> and events.event_date > '2003-10-27'
> and events.etype_id = event_types.etype_id
> and ( ...
> );
>
>
>What I can't figure out is what is that inredibly expensive nested loop for?
Sorry, I have no answer to your question, but may I ask whether you
really want to get presumably 106 output rows for each event with
status 1?
Or did you mean
WHERE (events.status = 1 OR events.status = 11) AND ...
>Ideas?
I'd also try to push that NOT EXISTS condition into the FROM clause:
...LEFT JOIN (SELECT DISTINCT ON (event_id)
event_id, mod_date, mod_user
FROM event_history
ORDER BY event_id, mod_date
) AS eh ON (events.event_id = eh.event_id) ...
WHERE ...
AND CASE WHEN eh.event_id IS NULL
THEN events.mod_user
ELSE eh.mod_user END = 562
If mod_user is NOT NULL in event_history, then CASE ... END can be
simplified to COALESCE(eh.mod_user, events.mod_user).
Servus
Manfred
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff | 2003-10-28 14:05:15 | More info in explain analyze |
Previous Message | Kamalraj Singh Madhan | 2003-10-28 06:21:57 | Optimizing Performance |