pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Merlin Moncure <mmoncure@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Mark Stosberg <mark@summersault.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: cube operations slower than geo_distance() on production server
Date: Wed, 14 Feb 2007 08:58:35 -0500
Message-ID: <b42b73150702140558l3220d2e0v3e5e38d64b6e35c5@mail.gmail.com> (raw)
In-Reply-To: <18714.1171437344@sss.pgh.pa.us>
References: <eqiht3$2fvu$1@news.hub.org>
	<b42b73150702091731x57996613hb50af0296007436c@mail.gmail.com>
	<eqq3k3$1mpu$1@news.hub.org>
	<b42b73150702121103l297b690w84dde8ef9ef8d2f1@mail.gmail.com>
	<eqqgc5$kle$1@news.hub.org>
	<b42b73150702130615t22776654u9e0925e0fe368bc1@mail.gmail.com>
	<b42b73150702130631x332e4f18s34a057c0c47c5e8c@mail.gmail.com>
	<20070213204747.GD23491@summersault.com>
	<18714.1171437344@sss.pgh.pa.us>

On 2/14/07, Tom Lane <tgl@sss.pgh.pa.us> 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



view thread (11+ messages)

Message-ID: <b42b73150702140558l3220d2e0v3e5e38d64b6e35c5@mail.gmail.com>
Permalink:  ../b42b73150702140558l3220d2e0v3e5e38d64b6e35c5@mail.gmail.com/
Also on:    postgresql.org/message-id/b42b73150702140558l3220d2e0v3e5e38d64b6e35c5@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: mmoncure@gmail.com, tgl@sss.pgh.pa.us, mark@summersault.com
  Subject: Re: cube operations slower than geo_distance() on production server
  In-Reply-To: <b42b73150702140558l3220d2e0v3e5e38d64b6e35c5@mail.gmail.com>
  References: <eqiht3$2fvu$1@news.hub.org> <b42b73150702091731x57996613hb50af0296007436c@mail.gmail.com> <eqq3k3$1mpu$1@news.hub.org> <b42b73150702121103l297b690w84dde8ef9ef8d2f1@mail.gmail.com> <eqqgc5$kle$1@news.hub.org> <b42b73150702130615t22776654u9e0925e0fe368bc1@mail.gmail.com> <b42b73150702130631x332e4f18s34a057c0c47c5e8c@mail.gmail.com> <20070213204747.GD23491@summersault.com> <18714.1171437344@sss.pgh.pa.us> <b42b73150702140558l3220d2e0v3e5e38d64b6e35c5@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox