Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 057C21337B7E for ; Thu, 17 Feb 2011 12:41:43 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 39000-06 for ; Thu, 17 Feb 2011 16:41:36 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og102.obsmtp.com (exprod7og102.obsmtp.com [64.18.2.157]) by mail.postgresql.org (Postfix) with ESMTP id BDAF21336FA7 for ; Thu, 17 Feb 2011 12:41:35 -0400 (AST) Received: from source ([74.125.82.50]) (using TLSv1) by exprod7ob102.postini.com ([64.18.6.12]) with SMTP ID DSNKTV1PvvQT97t80gNjdY9hliVzHPDdw4mj@postini.com; Thu, 17 Feb 2011 08:41:36 PST Received: by wwf26 with SMTP id 26so2884945wwf.19 for ; Thu, 17 Feb 2011 08:41:33 -0800 (PST) Received: by 10.227.141.205 with SMTP id n13mr1898893wbu.52.1297960893155; Thu, 17 Feb 2011 08:41:33 -0800 (PST) Received: from [192.168.1.183] (dsl-hkibrasgw2-ff7ac300-240.dhcp.inet.fi [88.195.122.240]) by mx.google.com with ESMTPS id t5sm466728wes.33.2011.02.17.08.41.31 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 Feb 2011 08:41:31 -0800 (PST) Message-ID: <4D5D4FB9.8020709@enterprisedb.com> Date: Thu, 17 Feb 2011 18:41:29 +0200 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.1.16) Gecko/20101226 Icedove/3.0.11 MIME-Version: 1.0 To: Mark Stosberg CC: pgsql-performance@postgresql.org Subject: Re: application of KNN code to US zipcode searches? References: <4D5CE118020000250003AB83@gw.wicourts.gov> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.2 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3 X-Spam-Level: X-Archive-Number: 201102/431 X-Sequence-Number: 42569 On 17.02.2011 17:20, Mark Stosberg wrote: >> I thought the benefit of KNN was that you could retrieve the rows in >> distance order, so that a query for the closest 20 locations (for >> example) would be very fast. I wouldn't have expected it to be >> helpful when you're selecting all the rows regardless of distance. > > Kevin, > > Thanks for the feedback. You are right that my "reduced test case" > wasn't a good approximation. I added a limit, to simulate finding the > 100 zipcodes closest to 90210. > > Below I compare 4 approaches to the same query: > > 1. Cube search > 2. Earth Distance Search > 3. Simple point distance (no index) > 4. Simple point distance (KNN) > > Now KNN benchmarks to be almost 100x faster! That's very promising. > Then there's only the issue that simple point distance is not expected > to be a good enough approximation of earth-distances. Perhaps that can > be solved by pre-computing coordinates based on the lat/long pairs.... > much like the map projections used to present a curved surface on a flat > map? Given that's OK to be be a few miles off, it seems we have some > leeway here. > > Recommendations? The existing opclasses only support distance-to-a-point, but I believe the KNN gist code is flexible enough that it could be used for distance to the edge of a shape as well. Someone just needs to write the operators and support functions. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com