Re: Slow query: Select all buildings that have >1 pharmacies and >1 schools within 1000m

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Stefan Keller <sfkeller(at)gmail(dot)com>
Cc: Craig James <cjames(at)emolecules(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Slow query: Select all buildings that have >1 pharmacies and >1 schools within 1000m
Date: 2012-08-08 00:50:32
Message-ID: CAMkU=1xPh0mjyK-2VU3i9HFSP_zckJzFMRAbR+QvGxpQWE+qwg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Tue, Aug 7, 2012 at 5:07 PM, Stefan Keller <sfkeller(at)gmail(dot)com> wrote:
> Hi Craig
>
> Clever proposal!
> I slightly tried to adapt it to the hstore involved.
> Now I'm having a weird problem that PG says that "relation 'p' does not exist".
> Why does PG recognize table b in the subquery but not table p?
> Any ideas?

I don't think it does recognize b, either. It just fell over on p
before it had a chance to fall over on b.

I think you have to use WITH if you want to reference the same
subquery in multiple FROMs.

Another approach would be to add explicit conditions for there being
at least 1 school and 1 pharmacy within distance. There can't be >1
unless there is >=1, but the join possibilities for >=1 (i.e. "where
exists" rather than "where (select count(*)...)>1" ) are much more
attractive than the ones for >1.

Cheers,

Jeff

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Craig Ringer 2012-08-08 06:33:02 Re: Postgresql - performance of using array in big database
Previous Message Merlin Moncure 2012-08-08 00:42:17 Re: Is drop/restore trigger transactional?