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 C248452A77; Thu, 7 Apr 2005 22:40:23 +0100 (BST) 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 21502-07; Thu, 7 Apr 2005 21:40:14 +0000 (GMT) Received: from flake.decibel.org (flake.decibel.org [67.100.216.10]) by svr1.postgresql.org (Postfix) with ESMTP id E44D553731; Thu, 7 Apr 2005 22:40:13 +0100 (BST) Received: by flake.decibel.org (Postfix, from userid 1001) id 8828B15478; Thu, 7 Apr 2005 16:40:15 -0500 (CDT) Date: Thu, 7 Apr 2005 16:40:15 -0500 From: "Jim C. Nasby" To: Tom Lane Cc: Arjen van der Meijden , pgsql-hackers@postgreSQL.org, pgsql-performance@postgreSQL.org Subject: Re: [HACKERS] Recognizing range constraints (was Re: Plan for relatively simple query seems to be very inefficient) Message-ID: <20050407214015.GT93835@decibel.org> References: <425413D3.5030304@vulcanus.its.tudelft.nl> <28552.1112809334@sss.pgh.pa.us> <425423A9.9000504@vulcanus.its.tudelft.nl> <5999.1112820690@sss.pgh.pa.us> <6326.1112825377@sss.pgh.pa.us> <20050406222536.GL93835@decibel.org> <6594.1112826910@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6594.1112826910@sss.pgh.pa.us> X-Operating-System: FreeBSD 4.11-RELEASE i386 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.8i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.019 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/173 X-Sequence-Number: 11570 On Wed, Apr 06, 2005 at 06:35:10PM -0400, Tom Lane wrote: > "Jim C. Nasby" writes: > > On Wed, Apr 06, 2005 at 06:09:37PM -0400, Tom Lane wrote: > >> Can anyone suggest a more general rule? Do we need for example to > >> consider whether the relation membership is the same in two clauses > >> that might be opposite sides of a range restriction? It seems like > >> > >> a.x > b.y AND a.x < b.z > > > In a case like this, you could actually look at the data in b and see > > what the average range size is. > > Not with the current statistics --- you'd need some kind of cross-column > statistics involving both y and z. (That is, I doubt it would be > helpful to estimate the average range width by taking the difference of > independently-calculated mean values of y and z ...) But yeah, in > principle it would be possible to make a non-default estimate. Actually, it might be possible to take a SWAG at it using the histogram and correlation stats. You know... since getting universally useful cross-platform stats seems to be pretty pie-in-the-sky, would it be possible to generate more complex stats on the fly from a sampling of a table? If you're looking at a fairly sizeable table ISTM it would be worth sampling the rows on 10 or 20 random pages to see what you get. In this case, you'd want to know the average difference between two fields. Other queries might want something different. -- Jim C. Nasby, Database Consultant decibel@decibel.org Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?"