pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: Roman Fail <rfail@posportal.com>
Cc: Josh Berkus <josh@agliodbs.com>
Cc: sszabo@megazone23.bigpanda.com
Cc: pgsql-performance@postgresql.org
Subject: Re: 7.3.1 New install, large queries are slow
Date: Thu, 16 Jan 2003 09:16:33 -0800
Message-ID: <web-2316163@davinci.ethosmedia.com> (raw)
In-Reply-To: <14736.1042730017@sss.pgh.pa.us>

Roman, Tom:

> No no no ... this is even worse than before.  Your big tables are
> batchdetail (d) and purc1 (p1).  What you've got to do is arrange the
> computation so that those are trimmed to just the interesting records
> as
> soon as possible. 

When joining disproportionally large tables, I've also had some success
with the following method:

SELECT b.batchdate, d.batchdetailid, t.bankno, d.trandate,
d.tranamount, 
d.submitinterchange, d.authamount, d.authno, d.cardtypeid, d.mcccode, 
m.name AS merchantname, c.cardtype, m.merchid, 
p1.localtaxamount, p1.productidentifier, dr.avsresponse, 
cr.checkoutdate, cr.noshowindicator, ck.checkingacctno, 
ck.abaroutingno, ck.checkno 
FROM tranheader t 
JOIN batchheader b ON (t.tranheaderid = b.tranheaderid AND b.batchdate
> '2002-12-15')
JOIN merchants m ON (m.merchantid = b.merchantid AND mmerchid =
'701252267')
JOIN batchdetail d ON (d.batchid = b.batchid AND d.tranamount BETWEEN
500 and 700)
JOIN cardtype c ON d.cardtypeid = c.cardtypeid 
LEFT JOIN purc1 p1 ON p1.batchdetailid = d.batchdetailid 
LEFT JOIN direct dr ON dr.batchdetailid = d.batchdetailid 
LEFT JOIN carrental cr ON cr.batchdetailid = d.batchdetailid 
LEFT JOIN checks ck ON ck.batchdetailid = d.batchdetailid 
WHERE t.clientid = 6 
AND d.tranamount BETWEEN 500.0 AND 700.0 
AND b.batchdate > '2002-12-15' 
AND m.merchid = '701252267' 
ORDER BY b.batchdate DESC 
LIMIT 50

This could be re-arranged some, but I think you get the idea ... I've
been able, in some queries, to get the planner to use a better and
faster join strategy by repeating my WHERE conditions in the JOIN
criteria.

-Josh




view thread (66+ messages)  latest in thread

Message-ID: <web-2316163@davinci.ethosmedia.com>
Permalink:  ../web-2316163@davinci.ethosmedia.com/
Also on:    postgresql.org/message-id/web-2316163@davinci.ethosmedia.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 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: josh@agliodbs.com, tgl@sss.pgh.pa.us, rfail@posportal.com, sszabo@megazone23.bigpanda.com
  Subject: Re: 7.3.1 New install, large queries are slow
  In-Reply-To: <web-2316163@davinci.ethosmedia.com>
  References: <14736.1042730017@sss.pgh.pa.us> <web-2316163@davinci.ethosmedia.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