Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id BFA6A9FB1CC for ; Tue, 9 Jan 2007 08:56:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 90730-03 for ; Tue, 9 Jan 2007 08:56:27 -0400 (AST) X-Greylist: delayed 00:05:13.951564 by SQLgrey-1.7.4 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.179]) by postgresql.org (Postfix) with ESMTP id AF9349FA4B6 for ; Tue, 9 Jan 2007 08:56:30 -0400 (AST) Received: from [212.202.150.2] (helo=swtexchange2.technology.de) by mrelayeu.kundenserver.de (node=mrelayeu0) with ESMTP (Nemesis), id 0MKwh2-1H4GRE2P6r-000765; Tue, 09 Jan 2007 13:50:50 +0100 Subject: Re: Horribly slow query/ sequential scan MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Tue, 9 Jan 2007 13:50:47 +0100 Content-class: urn:content-classes:message Message-ID: <16F953410A0F1346848DCB476A989CFE087890@swtexchange2.technology.de> X-MimeOLE: Produced By Microsoft Exchange V6.5 X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PERFORM] Horribly slow query/ sequential scan Thread-Index: Accz69E9+v1mguIeR8uzlo15VnWxDwAAIJLw From: =?iso-8859-1?Q?N=F6rder-Tuitje=2C_Marcus?= To: , "Gregory S. Williamson" Cc: X-Provags-ID: kundenserver.de abuse@kundenserver.de login:24478085a861b01e05bdc3b8f80dc176 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/108 X-Sequence-Number: 22709 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 = =3D '2006-09-30' and w.report_id =3D b.report_id) and w.client_id IN ('227400001','2274000010') group by 1,2,3 order by 1,2,3; should by faster;=20 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,=20 marcus -----Urspr=FCngliche 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 =3D > '2006-09-30') > and (w.client_id =3D '227400001' or w.client_id =3D '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 = =3D '2006-09-30') and (w.client_id =3D '227400001' or w.client_id =3D '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