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 3E5C75293B for ; Wed, 20 Jul 2005 17:28:44 -0300 (ADT) 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 57065-04 for ; Wed, 20 Jul 2005 20:28:33 +0000 (GMT) Received: from calvin.surfutopia.net (calvin.surfutopia.net [67.120.245.34]) by svr1.postgresql.org (Postfix) with ESMTP id C9B1252AA5 for ; Wed, 20 Jul 2005 17:28:31 -0300 (ADT) Received: by calvin.surfutopia.net (Postfix, from userid 1000) id 7ADC9F23B; Wed, 20 Jul 2005 13:28:32 -0700 (PDT) Date: Wed, 20 Jul 2005 13:28:32 -0700 From: John Mendenhall To: pgsql-performance list Subject: Re: performance decrease after reboot Message-ID: <20050720202832.GA22109@calvin.surfutopia.net> References: <20050719210557.GA30794@calvin.surfutopia.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050719210557.GA30794@calvin.surfutopia.net> User-Agent: Mutt/1.5.6i 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: 200507/339 X-Sequence-Number: 13580 On Tue, 19 Jul 2005, John Mendenhall wrote: > I tuned a query last week to obtain acceptable performance. > Here is my recorded explain analyze results: > > LOG: duration: 826.505 ms statement: explain analyze > [cut for brevity] > > I rebooted the database machine later that night. > Now, when I run the same query, I get the following > results: > > LOG: duration: 6931.701 ms statement: explain analyze > [cut for brevity] I just ran my query again, no changes from yesterday and it is back to normal: LOG: duration: 795.839 ms statement: explain analyze What could have been the problem? The major differences in the query plan are as follows: (1) The one that runs faster uses a Hash Join at the very top of the query plan. It does a Hash Cond on the country and code fields. (2) The one that runs slower uses a Materialize with the subplan, with no Hash items. The Materialize does Seq Scan of the countries table, and above it, a Join Filter is run. (3) The partners_pkey index on the partners table is in a different place in the query. Does anyone know what would cause the query plan to be different like this, for the same server, same query? I run vacuum analyze every night. Is this perhaps the problem? What setting do I need to tweak to make sure the faster plan is always found? Thanks for any pointers in this dilemma. JohnM -- John Mendenhall john@surfutopia.net surf utopia internet services