Re: How to optimize this query ? - Mailing list pgsql-sql

From proghome@silesky.com (krystoffff)
Subject Re: How to optimize this query ?
Date
Msg-id 85898f7e.0308130520.5af10fd0@posting.google.com
Whole thread Raw
In response to Re: How to optimize this query ?  ("Franco Bruno Borghesi" <franco@akyasociados.com.ar>)
List pgsql-sql
I tried with some LEFT JOINS, which give me the possibility to keep
the information of the right table.

I have now the following query, which is 10 times faster !!! (from 16s
to 1.6s)
But I's like to remove the last subquery, to see if it faster ;)
Can somebody help me ?


-------------------------

SELECT lead. *
FROM lead
LEFT JOIN purchase ON ( lead.id = purchase.lead_id ) 
LEFT JOIN affiliate_lockout ON ( lead.affiliate_id =
affiliate_lockout.affiliate_locked_id )
WHERE (
exclusive IS NULL OR (
exclusive = 0 AND nb_purchases < 3
)
) AND id NOT 
IN (

SELECT lead_id
FROM purchase
INNER JOIN member_exclusion
WHERE purchase.member_id = member_exclusion.member_id_to_exclude AND
purchase.member_id = 21101
) AND (
affiliate_lockout.member_id <> 21101 OR affiliate_lockout.member_id IS
NULL
) AND purchase.member_id <> 21101
GROUP BY lead.id


pgsql-sql by date:

Previous
From: proghome@silesky.com (krystoffff)
Date:
Subject: Re: Error message with a SQL function
Next
From: Stephan Szabo
Date:
Subject: Re: [ADMIN] Why table has drop, but the foreign key still there?