Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 5712F1336B42 for ; Tue, 21 Sep 2010 16:07:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 00415-06 for ; Tue, 21 Sep 2010 19:07:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from spinlock.commandprompt.com (host-215.commandprompt.net [207.173.203.215]) by mail.postgresql.org (Postfix) with ESMTP id 43FDF133616B for ; Tue, 21 Sep 2010 16:07:22 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by spinlock.commandprompt.com (Postfix) with ESMTP id A2CCE348013; Tue, 21 Sep 2010 12:07:15 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at commandprompt.com Received: from spinlock.commandprompt.com ([127.0.0.1]) by localhost (spinlock.commandprompt.com.commandprompt.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2FFkkMwxre8K; Tue, 21 Sep 2010 12:07:12 -0700 (PDT) Received: from [192.168.1.105] (unknown [75.142.155.118]) by spinlock.commandprompt.com (Postfix) with ESMTPSA id 1E563348011; Tue, 21 Sep 2010 12:07:12 -0700 (PDT) Subject: Re: Query much faster with enable_seqscan=0 From: "Joshua D. Drake" Reply-To: jd@commandprompt.com To: Ogden Cc: Jesper Krogh , Kenneth Marshall , pgsql-performance@postgresql.org In-Reply-To: <3062DF4E-7460-4487-818A-BF77F176E501@darkstatic.com> References: <0D5B9ED0-00C3-4EEB-8336-0B2F8A884620@darkstatic.com> <20100921180618.GI17152@aart.is.rice.edu> <4C98FEA2.8030607@krogh.cc> <3062DF4E-7460-4487-818A-BF77F176E501@darkstatic.com> Content-Type: text/plain; charset="UTF-8" Organization: Command Prompt, Inc. Date: Tue, 21 Sep 2010 12:07:11 -0700 Message-ID: <1285096031.15919.68.camel@jd-desktop.unknown.charter.com> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201009/129 X-Sequence-Number: 40332 On Tue, 2010-09-21 at 14:02 -0500, Ogden wrote: > How odd, I set the following: > > seq_page_cost = 1.0 > random_page_cost = 2.0 > > And now the query runs in milliseconds as opposed to 14 seconds. Could this really be the change? I am running ANALYZE now - how often is it recommended to do this? PostgreSQL's defaults are based on extremely small and some would say (non production) size databases. As a matter of course I always recommend bringing seq_page_cost and random_page_cost more in line. However, you may want to try moving random_page_cost back to 4 and try increasing cpu_tuple_cost instead. Sincerely, Joshua D. Drake -- PostgreSQL.org Major Contributor Command Prompt, Inc: http://www.commandprompt.com/ - 509.416.6579 Consulting, Training, Support, Custom Development, Engineering http://twitter.com/cmdpromptinc | http://identi.ca/commandprompt