Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 562AC9FB3E0 for ; Tue, 3 Oct 2006 21:56:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 20579-07 for ; Wed, 4 Oct 2006 00:56:03 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id E5B2B9FB3E1 for ; Tue, 3 Oct 2006 21:56:02 -0300 (ADT) Received: by noel.decibel.org (Postfix, from userid 1001) id B333D56431; Tue, 3 Oct 2006 19:55:45 -0500 (CDT) Received: (hashcash-sendmail, from uid 1001); Tue, 3 Oct 2006 19:55:45 -0500 Date: Tue, 3 Oct 2006 19:55:45 -0500 From: "Jim C. Nasby" To: Ron Mayer , pgsql-performance@postgresql.org Subject: Re: Forcing the use of particular execution plans Message-ID: <20061004005545.GA81937@nasby.net> References: <000501c6e1ff$c80022c0$0340050a@sdg> <007b01c6e24c$ccfc8190$8300a8c0@tridecap.com> <20060927201350.GS19827@nasby.net> <4522FBDC.3030706@cheapcomplexdevices.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4522FBDC.3030706@cheapcomplexdevices.com> X-Operating-System: FreeBSD 6.0-RELEASE-p4 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Hashcash: 1:20:061004:rm_pg@cheapcomplexdevices.com::eQo6dRw8rFH/YDR4:00000000 0000000000000000000000003ud0 X-Hashcash: 1:20:061004:pgsql-performance@postgresql.org::km1KprEphQFOvZPD:00000 0000000000000000000000001jgy X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200610/69 X-Sequence-Number: 21198 Adding -performance back in. On Tue, Oct 03, 2006 at 05:10:04PM -0700, Ron Mayer wrote: > Jim C. Nasby wrote: > > > > Index scans are also pretty picky about correlation. If you have really > > low correlation you don't want to index scan, > > I'm still don't think "correlation" is the right metric > at all for making this decision. > > If you have a list of addresses clustered by "zip" > the "correlation" of State, City, County, etc will all be zero (since > the zip codes don't match the alphabetical order of state or city names) > but index scans are still big wins because the data for any given > state or city will be packed on the same few pages - and in fact > the pages could be read mostly sequentially. That's a good point that I don't think has been considered before. I think correlation is still somewhat important, but what's probably far more important is data localization. One possible way to calculate this would be to note the location of every tuple with a given value in the heap. Calculate the geometric mean of those locations (I think you could essentially average all the ctids), and divide that by the average distance of each tuple from that mean (or maybe the reciprocal of that would be more logical). Obviously we don't want to scan the whole table to do that, but there should be some way to do it via sampling as well. Or perhaps someone knows of a research paper with real data on how to do this instead of hand-waving. :) > > but I think our current > > estimates make it too eager to switch to a seqscan. -- Jim C. Nasby, Database Architect jim@nasby.net 512.569.9461 (cell) http://jim.nasby.net