From: | Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> |
---|---|
To: | ProgHome <proghome(at)silesky(dot)com> |
Cc: | 'Franco Bruno Borghesi' <franco(at)akyasociados(dot)com(dot)ar>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: How to optimize this query ? |
Date: | 2003-08-13 18:39:39 |
Message-ID: | 20030813113719.G53899-100000@megazone.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Wed, 13 Aug 2003, ProgHome wrote:
> select member.id, automated.delivery, member.email
>
> from (automated INNER JOIN member ON member.id = automated.member_id)
>
> where activated=1
> and website='$SITE_NAME'
> and (select count(*) from trans_member where
> (unix_timestamp(now())-unix_timestamp(date)) <
> (unix_timestamp(now())-'$today_midnight') and type='purchase' and
> comment LIKE '%automated%'
> and member_id=member.id and comment LIKE '%$type%') < max_$field
> and balance_in_points > $price
> and credit_ratings_t$n LIKE '%$lead[borrower_credit_rating]%'
> and states LIKE '%$lead[prop_state]%'
> and ltv_t$n/100 >= (cast($lead[loan_amount] as unsigned) /
> cast($lead[current_value] as unsigned))
> and amount_t$n < $lead[loan_amount]
>
> AND $id NOT IN (select lead_id from purchase where
> member_id=member.id)
> AND $aff_id NOT IN (select affiliate_locked_id from affiliate_lockout
> where member_id=member.id)
> AND $id NOT IN (select lead_id from purchase where member_id IN
> (select member_id_to_exclude from member_exclusion where
> member_id=member.id))
In these cases I'd suggest trying a NOT EXISTS, maybe something like
(for the first one):
AND NOT EXISTS (select 1 from purchase where member_id=member.id
AND lead_id=$id)
With a two column index on purchase(member_id,lead_id) [or lead_id,
member_id maybe] you might be able to do okay.
From | Date | Subject | |
---|---|---|---|
Next Message | krystoffff | 2003-08-13 18:54:16 | Re: How to optimize this query ? |
Previous Message | Stephan Szabo | 2003-08-13 18:29:19 | Re: How to optimize this query ? |