X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id B624630FCB4 for ; Wed, 2 Jul 2003 12:51:44 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 54837-05 for ; Wed, 2 Jul 2003 09:51:34 -0300 (ADT) Received: from tomts26-srv.bellnexxia.net (tomts26.bellnexxia.net [209.226.175.189]) by svr1.postgresql.org (Postfix) with ESMTP id B775130FC55 for ; Wed, 2 Jul 2003 09:51:33 -0300 (ADT) Received: from [192.168.1.200] ([216.209.81.133]) by tomts26-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030702125132.TTSG22067.tomts26-srv.bellnexxia.net@[192.168.1.200]>; Wed, 2 Jul 2003 08:51:32 -0400 Subject: Re: How to optimize monstrous query, sorts instead of From: Rod Taylor To: michael.mattox@verideon.com Cc: Postgresql Performance In-Reply-To: References: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-6snf1FxRhqL+C8ELDExW" Message-Id: <1057150311.28657.172.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.0 Date: 02 Jul 2003 12:51:51 +0000 X-Archive-Number: 200307/26 X-Sequence-Number: 2319 --=-6snf1FxRhqL+C8ELDExW Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Wed, 2003-07-02 at 10:24, Michael Mattox wrote: > > Try this: >=20 > Rod, you improved my query last week (thank you very much) but I'm not su= re > why but my performance is getting worse. I think I know what happened, w= hen > I did my load testing I created data that all had the same date, so sorti= ng > on the date was very fast. But now I've been running the system for a few > weeks I've got a range of dates and now the sort is very costly. I'm > curious if it's possible to optimize this with an index? I've tried > creating some indexes but they're never used. Standard questions, did you VACUUM? Regularly? Want to try again and send us the output from VACUUM VERBOSE? Sounds like you created a ton of test data, then removed a bunch? Did you REINDEX that table? During normal use, what is your query spread like? Mostly selects with some inserts? Any updates or deletes? How often to updates or deletes come in, and how many rows do they effect? > -> Index Scan using monitorstatusxmonitori on > monitorstatusx ms (cost=3D0.00..5996.18 rows=3D163 width=3D84) (actual > time=3D4383.38..14936.39 rows=3D225 loops=3D1) > Index Cond: ("outer".jdoidx =3D ms.monit= orx) > Filter: ((datex >=3D '2003-07-01 > 00:00:00'::timestamp without time zone) AND (datex <=3D '2003-07-01 > 23:59:59'::timestamp without time zone)) The above index scan is taking a vast majority of the time (nearly 15 seconds of the 16 second total -- stop thinking about sorts!).. What happened to the index on monitorx and datex? --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-6snf1FxRhqL+C8ELDExW Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA/AtVm6DETLow6vwwRAmnIAJ0ajEOElGfbnDDWCgnyZ5p936OFLgCeK4xk kI/IwhqyvKWhLBMYGGi+4Og= =ocCw -----END PGP SIGNATURE----- --=-6snf1FxRhqL+C8ELDExW--