Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id D6C3B9FB8CB for ; Tue, 24 Apr 2007 18:27:00 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 89669-05 for ; Tue, 24 Apr 2007 18:26:56 -0300 (ADT) 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 EF1FB9FB8E7 for ; Tue, 24 Apr 2007 18:26:55 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id DF61330DF9; Tue, 24 Apr 2007 23:26:54 +0200 (MET DST) From: zardozrocks X-Newsgroups: pgsql.performance Subject: Simple query, 10 million records...MySQL ten times faster Date: 24 Apr 2007 14:26:46 -0700 Organization: http://groups.google.com Lines: 49 Message-ID: <1177450006.547698.120920@u32g2000prd.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Complaints-To: groups-abuse@google.com User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: u32g2000prd.googlegroups.com; posting-host=76.173.105.40; posting-account=6w13Tw0AAAB5XYxeuWKMphbu-NtlWN2Q To: pgsql-performance@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200704/437 X-Sequence-Number: 24314 I have this table: CREATE TABLE test_zip_assoc ( id serial NOT NULL, f_id integer DEFAULT 0 NOT NULL, lat_radians numeric(6,5) DEFAULT 0.00000 NOT NULL, long_radians numeric(6,5) DEFAULT 0.00000 NOT NULL ); CREATE INDEX lat_radians ON test_zip_assoc USING btree (lat_radians); CREATE INDEX long_radians ON test_zip_assoc USING btree (long_radians); It's basically a table that associates some foreign_key (for an event, for instance) with a particular location using longitude and latitude. I'm basically doing a simple proximity search. I have populated the database with *10 million* records. I then test performance by picking 50 zip codes at random and finding the records within 50 miles with a query like this: SELECT id FROM test_zip_assoc WHERE lat_radians > 0.69014816041 AND lat_radians < 0.71538026567 AND long_radians > -1.35446228028 AND long_radians < -1.32923017502 On my development server (dual proc/dual core Opteron 2.8 Ghz with 4GB ram) this query averages 1.5 seconds each time it runs after a brief warmup period. In PostGreSQL it averages about 15 seconds. Both of those times are too slow. I need the query to run in under a second with as many as a billion records. I don't know if this is possible but I'm really hoping someone can help me restructure my indexes (multicolumn?, multiple indexes with a 'where' clause?) so that I can get this running as fast as possible. If I need to consider some non-database data structure in RAM I will do that too. Any help or tips would be greatly appreciated. I'm willing to go to greath lengths to test this if someone can make a good suggestion that sounds like it has a reasonable chance of improving the speed of this search. There's an extensive thread on my efforts already here: http://phpbuilder.com/board/showthread.php?t=10331619&page=10