Re: Guesses on what this NestLoop is for? - Mailing list pgsql-performance

From Manfred Koizar
Subject Re: Guesses on what this NestLoop is for?
Date
Msg-id 3nhspvkbsarcieub1neodds7pr9h6hbtna@email.aon.at
Whole thread Raw
In response to Guesses on what this NestLoop is for?  (Josh Berkus <josh@agliodbs.com>)
Responses Re: Guesses on what this NestLoop is for?
List pgsql-performance
On Mon, 27 Oct 2003 15:32:41 -0800, Josh Berkus <josh@agliodbs.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

pgsql-performance by date:

Previous
From: Shridhar Daithankar
Date:
Subject: Re: Optimizing Performance
Next
From: Jeff
Date:
Subject: More info in explain analyze