On Mon, 27 Oct 2003 15:32:41 -0800, Josh Berkus <[EMAIL PROTECTED]>
>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 ...


I'd also try to push that NOT EXISTS condition into the FROM clause:

                     event_id, mod_date, mod_user
                FROM event_history
               ORDER BY event_id, mod_date
             ) AS eh ON (events.event_id = eh.event_id) ...
  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).


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to