Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 8DA066325EF for ; Wed, 26 May 2010 12:55:18 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 59369-01 for ; Wed, 26 May 2010 15:55:11 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id 5CE7D632523 for ; Wed, 26 May 2010 12:55:11 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Wed, 26 May 2010 10:55:10 -0500 Message-Id: <4BFCFE080200002500031AF9@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Wed, 26 May 2010 10:55:04 -0500 From: "Kevin Grittner" To: "David Jarvis" Cc: Subject: Re: Random Page Cost and Planner References: <4BFBD0890200002500031A6E@gw.wicourts.gov> In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.311 tagged_above=-10 required=5 tests=BAYES_20=-0.001, RCVD_IN_DNSWL_MED=-2.3, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201005/197 X-Sequence-Number: 38781 David Jarvis wrote: >> It sounds as though the active portion of your database is pretty >> much cached in RAM. True? > I would not have thought so; there are seven tables, each with 39 > to 43 million rows > The machine has 4GB of RAM In that case, modifying seq_page_cost or setting random_page_cost below something in the range of 1.5 to 2 is probably not going to be a good choice for the mix as a whole. > effective_cache_size = 256MB This should probably be set to something on the order of 3GB. This will help the optimizer make more intelligent choices about when use of the index will be a win. >> It would tend to be better than random access to 43 million rows, >> at least if you need to go to disk for many of them. > > I thought that the index would take care of this? When the index can limit the number of rows to a fraction of the 43 million rows, using it is a win. The trick is to accurately model the relative costs of different aspects of running the query, so that when the various plans are compared, the one which looks the cheapest actually *is*. Attempting to force any particular plan through other means is risky. > I will be trying various other indexes. I've noticed now that > sometimes the results are very quick and sometimes very slow. For > the query I posted, it would be great to know what would be the > best indexes to use. I have a suspicion that that's going to > require trial and many errors. Yeah, there's no substitute for testing your actual software against the actual data. Be careful, though -- as previously mentioned caching can easily distort results, particularly when you run the same query, all by itself (with no competing queries) multiple times. You'll get your best information if you can simulate a more-or-less realistic load, and try that with various settings and indexes. The cache turnover and resource contention involved in production can influence performance, and are hard to estimate any other way. -Kevin