From: Rod Taylor <rbt@rbt.ca>
To: michael.mattox@verideon.com
Cc: Postgresql Performance <pgsql-performance@postgresql.org>
Subject: Re: How to optimize monstrous query, sorts instead of
Date: 25 Jun 2003 10:28:25 -0400
Message-ID: <1056551304.25587.52.camel@jester> (raw)
In-Reply-To: <CJEBLDCHAADCLAGIGCOOKEKGCKAA.michael.mattox@verideon.com>
References: <CJEBLDCHAADCLAGIGCOOKEKGCKAA.michael.mattox@verideon.com>
> I didn't notice that before, thanks for pointing that out. I just tried
> adding monitorx.idx to the select and it ended up making my query take
> several minutes long. Any ideas how I can fix this and keep my performance?
By using it aliased and non-aliased (2 different references to the same
table) you've caused it to join itself.
Try this:
SELECT m.idx
, ms.averageconnecttimex AS ms_averageconnecttime
, ms.averagedurationx AS ms_averageduration
, ms.datex AS ms_date
, ms.idx AS ms_id
, ms.statusstringx AS ms_statusstring
, ms.statusx AS ms_status
, msi.actualcontentx AS msi_actualcontent
, msi.connecttimex AS msi_connecttime
, msi.correctcontentx AS msi_correctcontent
, msi.datex AS msi_date
, msi.descriptionx AS msi_description
, msi.durationx AS msi_duration
, msi.errorcontentx AS msi_errorcontent
, msi.idx AS msi_id
, msi.monitorlocationx AS msi_monitorlocation
, msi.statusstringx AS msi_statusstring
, msi.statusx AS msi_status
FROM monitorstatusx AS ms
, monitorstatusitemx AS msi
, monitorx AS mx
, monitorstatus_statusitemsx AS mssisx
, monitorstatusitemlistd8ea58a5x AS litem
WHERE ms.jdoidx = mssisx.jdoidx
AND mssisx.statusitemsx = litem.jdoidx
AND litem.statusitemlistx = msi.jdoidx
AND mx.jdoidx = ms.monitorx
AND ms.datex BETWEEN '2003-06-20 08:57:21.36'
AND '2003-06-29 08:57:21.36'
AND m.idx = 'M-TEST_1444-TEST_00_10560561260561463219352'
ORDER BY ms.datex DESC;
--
Rod Taylor <rbt@rbt.ca>
PGP Key: http://www.rbt.ca/rbtpub.ascAttachments:
signature.asc (application/pgp-signature, 186B) download
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: rbt@rbt.ca, michael.mattox@verideon.com
Subject: Re: How to optimize monstrous query, sorts instead of
In-Reply-To: <1056551304.25587.52.camel@jester>
References: <CJEBLDCHAADCLAGIGCOOKEKGCKAA.michael.mattox@verideon.com> <1056551304.25587.52.camel@jester>
* 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