pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nörder-Tuitje, Marcus <noerder-tuitje@technology.de>
To: db@zigo.dhs.org
To: Gregory S. Williamson <gsw@globexplorer.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Horribly slow query/ sequential scan
Date: Tue, 9 Jan 2007 13:50:47 +0100
Message-ID: <16F953410A0F1346848DCB476A989CFE087890@swtexchange2.technology.de> (raw)

Forget abount "IN". Its horribly slow.

try :

select w.appid,
       w.rate,
       w.is_subscribed,
       sum(w.hits) AS Hits,
       sum(w.sius) AS IUs,
       sum(w.total_amnt) AS Total,
       sum(w.hits) * w.rate AS ByHits,
       sum(w.sius) * w.rate AS BYIUS
  from bill_rpt_work w
 where (select b.report_id from billing_reports b where b.report_s_date = '2006-09-30' and w.report_id = b.report_id)
   and w.client_id IN ('227400001','2274000010')
group by 1,2,3
order by 1,2,3;



should by faster; 

assuming : index on report_id in b; index on report_id, client_id in w

to enforce useage of indexes on grouping (depends on result size), consider extending w with cols 1,2,3.


regards, 
marcus

-----Ursprüngliche Nachricht-----
Von: pgsql-performance-owner@postgresql.org
[mailto:pgsql-performance-owner@postgresql.org]Im Auftrag von
db@zigo.dhs.org
Gesendet: Dienstag, 9. Januar 2007 13:36
An: Gregory S. Williamson
Cc: pgsql-performance@postgresql.org
Betreff: Re: [PERFORM] Horribly slow query/ sequential scan


I don't think I understand the idea behind this query. Do you really need
billing_reports twice?

> The query:
> explain analyze select
> w.appid,w.rate,w.is_subscribed,sum(w.hits) AS Hits ,sum(w.sius) AS IUs,
> sum(w.total_amnt) AS Total,sum(w.hits) * w.rate AS ByHits,
> sum(w.sius) * w.rate AS BYIUS
> from bill_rpt_work w, billing_reports b
> where w.report_id in
> (select b.report_id from billing_reports where b.report_s_date =
> '2006-09-30')
> and (w.client_id = '227400001' or w.client_id = '2274000010')
> group by 1,2,3
> order by 1,2,3;

Maybe this is the query you want instead?

select w.appid,
       w.rate,
       w.is_subscribed,
       sum(w.hits) AS Hits,
       sum(w.sius) AS IUs,
       sum(w.total_amnt) AS Total,
       sum(w.hits) * w.rate AS ByHits,
       sum(w.sius) * w.rate AS BYIUS
  from bill_rpt_work w
 where w.report_id in
       (select b.report_id from billing_reports b where b.report_s_date =
'2006-09-30')
   and (w.client_id = '227400001' or w.client_id = '2274000010')
group by 1,2,3
order by 1,2,3;

/Dennis


---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

                http://www.postgresql.org/about/donate





view thread (11+ messages)  latest in thread

Message-ID: <16F953410A0F1346848DCB476A989CFE087890@swtexchange2.technology.de>
Permalink:  ../16F953410A0F1346848DCB476A989CFE087890@swtexchange2.technology.de/
Also on:    postgresql.org/message-id/16F953410A0F1346848DCB476A989CFE087890@swtexchange2.technology.de

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: noerder-tuitje@technology.de, db@zigo.dhs.org, gsw@globexplorer.com
  Subject: Re: Horribly slow query/ sequential scan
  In-Reply-To: <16F953410A0F1346848DCB476A989CFE087890@swtexchange2.technology.de>
  References: <16F953410A0F1346848DCB476A989CFE087890@swtexchange2.technology.de>

* 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