Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id CE8829FB283 for ; Wed, 7 Feb 2007 17:31:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 53136-08 for ; Wed, 7 Feb 2007 17:30:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 9E96D9FB21C for ; Wed, 7 Feb 2007 17:30:48 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 3107C30E32; Wed, 7 Feb 2007 22:30:47 +0100 (MET) From: Mark Stosberg X-Newsgroups: pgsql.performance Subject: tip: faster sorting for proximity queries by using cube_distance() Date: Wed, 07 Feb 2007 16:30:16 -0500 Organization: Hub.Org Networking Services Lines: 23 Message-ID: References: <20070204051644.GA3754@wolff.to> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5.0.8 (X11/20061109) In-Reply-To: To: pgsql-performance@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/84 X-Sequence-Number: 23138 Hello, I wanted to share something else I learned in my proximity search work. One my requirements is to order by the distance that matches are found from the center point. When did this using earth_distance(), the benefit of the earth_box() technique over the old geo_distance became minimal as I approached a 250mi radius. Switching to sorting by cube_distance() offered a huge benefit, allowing the earth_distance() query to run in about 100ms vs 300ms for the geo_distance() equivalent. I checked the results that cube_distance() produced versus earth_distance(). cube_distance() is always (not surprisingly) a little smaller, but the difference seems only grows to about a mile for a 250 mile radius. That's an acceptable margin of error for this application, and may be for others as well. Mark