Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id D87AB9FB8B4 for ; Wed, 14 Feb 2007 09:58:47 -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 57231-03 for ; Wed, 14 Feb 2007 09:58:34 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.172]) by postgresql.org (Postfix) with ESMTP id CBB119FB8B3 for ; Wed, 14 Feb 2007 09:58:37 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id k3so172596ugf for ; Wed, 14 Feb 2007 05:58:36 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Kifmwwf516iwYmeLfncBKilCbeMc7zGzl4ad25l/2M/MZW4Ju0BpceZCIbfIwJbkUfXxw1Oav+aN1i/olzogParXJ5p5nvdGlFhxwZBjdghGRXJM5TVnJXmrpyl+lC0yM4m5vwh2GeYHqSyoE8vlR07M8I7V7NfgRpDZsGYjkAg= Received: by 10.78.204.7 with SMTP id b7mr245008hug.1171461515941; Wed, 14 Feb 2007 05:58:35 -0800 (PST) Received: by 10.78.35.18 with HTTP; Wed, 14 Feb 2007 05:58:35 -0800 (PST) Message-ID: Date: Wed, 14 Feb 2007 08:58:35 -0500 From: "Merlin Moncure" To: "Tom Lane" Subject: Re: cube operations slower than geo_distance() on production server Cc: "Mark Stosberg" , pgsql-performance@postgresql.org In-Reply-To: <18714.1171437344@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20070213204747.GD23491@summersault.com> <18714.1171437344@sss.pgh.pa.us> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/150 X-Sequence-Number: 23204 On 2/14/07, Tom Lane wrote: > There are two things wrong here: first, that the estimated row count is > only 20% of actual; it should certainly not be that far off for such a > simple condition. I wonder if your vacuum/analyze procedures are > actually working. Second, you mentioned somewhere along the line that > 'available' pets are about 10% of all the entries, which means that this > indexscan is more than likely entirely counterproductive: it would be > cheaper to ignore this index altogether. I think switching the index on pet_state to a composite on (pet_state, species_id) might help too. or even better: create function is_pet_available(text) returns bool as $$ select $1='available'; $$ language sql immutable; create index pets_available_species_idx on pets(is_pet_available(pet_state), species_id); refactor your query something similar to: SELECT * FROM ( SELECT earth_coords(q.earth_coords, s.earth_coords)/1609.344 as radius FROM pets JOIN shelters_active as shelters USING (shelter_id) JOIN zipcodes s ON shelters.postal_code_for_joining = zipcodes.zipcode JOIN zipcodes q ON q.zipcode = '90210' WHERE is_pet_available(pet_state) AND species_id = 1 AND earth_box(q.earth_coords, 10*1609.344) @ s.earth_coords ) p order by radius merlin