pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: proghome@silesky.com
To: pgsql-sql@postgresql.org
Subject: Re: How to optimize this query ?
Date: 13 Aug 2003 06:20:43 -0700
Message-ID: <85898f7e.0308130520.5af10fd0@posting.google.com> (raw)
References: <4848.200.59.66.253.1060736672.squirrel@webmail.akyasociados.com.ar>
	<20030812180544.L27665-100000@megazone.bigpanda.com>

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



view thread (28+ messages)  latest in thread

Message-ID: <85898f7e.0308130520.5af10fd0@posting.google.com>
Permalink:  ../85898f7e.0308130520.5af10fd0@posting.google.com/
Also on:    postgresql.org/message-id/85898f7e.0308130520.5af10fd0@posting.google.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: proghome@silesky.com
  Subject: Re: How to optimize this query ?
  In-Reply-To: <85898f7e.0308130520.5af10fd0@posting.google.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox