X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B034B8BA2CC for ; Thu, 17 Feb 2005 22:38:35 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 68511-03 for ; Thu, 17 Feb 2005 22:38:32 +0000 (GMT) Received: from server07.icaen.uiowa.edu (server07.icaen.uiowa.edu [128.255.17.47]) by svr1.postgresql.org (Postfix) with ESMTP id 1E2AF8BA2C5 for ; Thu, 17 Feb 2005 22:38:30 +0000 (GMT) Received: from server11.icaen.uiowa.edu (server11.icaen.uiowa.edu [128.255.17.51]) by server07.icaen.uiowa.edu (8.13.2/8.12.9) with ESMTP id j1HMcT09010114; (envelope-from ) Thu, 17 Feb 2005 16:38:29 -0600 (CST) Received: from [192.168.1.100] (12-217-241-0.client.mchsi.com [12.217.241.0]) (authenticated user=jfmeinel) by server11.icaen.uiowa.edu (8.13.2/smtp-serv-1.7) with ESMTP id j1HMcSW4020807 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256); (envelope-from ) Thu, 17 Feb 2005 16:38:29 -0600 (CST) Message-ID: <42151CED.7050309@arbash-meinel.com> Date: Thu, 17 Feb 2005 16:38:37 -0600 From: John Arbash Meinel User-Agent: Mozilla Thunderbird 1.0 (Macintosh/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: werner fraga Cc: pgsql-performance@postgresql.org Subject: Re: VACUUM ANALYZE slows down query References: <20050217222428.84111.qmail@web41408.mail.yahoo.com> In-Reply-To: <20050217222428.84111.qmail@web41408.mail.yahoo.com> X-Enigmail-Version: 0.89.6.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig073C75771F7B62E0836CCEC1" X-Virus-Scanned: ClamAV 0.80/682/Mon Jan 24 12:53:43 2005 clamav-milter version 0.80j on clamav.icaen.uiowa.edu X-Virus-Scanned: ClamAV 0.80/706/Sun Feb 13 18:14:02 2005, clamav-milter version 0.75 on clamav.icaen.uiowa.edu X-Virus-Status: Clean X-Virus-Status: Clean X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200502/252 X-Sequence-Number: 10581 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig073C75771F7B62E0836CCEC1 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit werner fraga wrote: >Certain queries on my database get slower after >running a VACUUM ANALYZE. Why would this happen, and >how can I fix it? > >I am running PostgreSQL 7.4.2 (I also seen this >problem on v. 7.3 and 8.0) > >Here is a sample query that exhibits this behaviour >(here the query goes from 1 second before VACUUM >ANALYZE to 2 seconds after; there are other queries >that go from 20 seconds before to 800 seconds after): > > > First, try to attach your explain analyze as a textfile attachment, rather than inline to prevent wrapping and make it easier to read. Second, the problem is that it *is* getting a more accurate estimate of the number of rows that are going to be returned, compare: Plan 1: >----------------------------------------------------------------------------------------------------------------------------------------------------------------- > Nested Loop Left Join (cost=3974.74..48055.42 >rows=79 width=8) (actual time=359.751..1136.165 >rows=1518 loops=1) > > The planner was expecting 79 rows, but was actually getting 1518. Plan 2: >----------------------------------------------------------------------------------------------------------------------------------------------------------------------- > Merge Left Join (cost=18310.59..29162.44 rows=1533 >width=8) (actual time=1886.942..2183.774 rows=1518 >loops=1) > > It is predicting 1533 rows, and found 1518, a pretty good guess. So the big issue is why does the planner think that a nested loop is going to be more expensive than a merge join. That I don't really know. I'm guessing some parameters like random_page_cost could be tweaked, but I don't really know the criteria postgres uses for merge joins vs nested loop joins. >Thanks for any assistance. > >Walt > > Hopefully someone can help a little better. In the mean time, you might want to resend with an attachment. I know I had trouble reading your explain analyze. John =:-> --------------enig073C75771F7B62E0836CCEC1 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (Darwin) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCFRztJdeBCYSNAAMRAuH2AKCBNz/SpGT2oq2gk3tnz4OW0mEm9gCgtHlM SBbeTT88SuzqfkZU/meGp6Q= =6kb7 -----END PGP SIGNATURE----- --------------enig073C75771F7B62E0836CCEC1--