From: | proghome(at)silesky(dot)com (krystoffff) |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: How to optimize this query ? |
Date: | 2003-08-13 13:20:43 |
Message-ID: | 85898f7e.0308130520.5af10fd0@posting.google.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Christoph Haller | 2003-08-13 13:23:48 | Re: Insert a description while creating a table |
Previous Message | Reinoud van Leeuwen | 2003-08-13 13:11:27 | Re: Insert a description while creating a table |