From: Tomas Vondra <tv@fuzzy.cz>
To: Stefan Keller <sfkeller@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Slow query: Select all buildings that have >1 pharmacies and >1 schools within 1000m
Date: Tue, 7 Aug 2012 14:16:43 +0200
Message-ID: <1e50929e6ba44cabb8deb2ad0ee98c82.squirrel@sq.gransy.com> (raw)
In-Reply-To: <CAFcOn29ZAGzFjd+VnmAfF4iQigd8mJnACHjLMkow46V4+uUrLQ@mail.gmail.com>
References: <CAFcOn29ZAGzFjd+VnmAfF4iQigd8mJnACHjLMkow46V4+uUrLQ@mail.gmail.com>
On 7 Srpen 2012, 14:01, Stefan Keller wrote:
> Hi
>
> I have an interesting query to be optimized related to this one [1].
>
> The query definition is: Select all buildings that have more than 1
> pharmacies and more than 1 schools within a radius of 1000m.
>
> The problem is that I think that this query is inherently O(n^2). In
> fact the solution I propose below takes forever...
What about plain INTERSECT? Something like
SELECT osm_id FROM osm_poi AS p, osm_polygon b
WHERE p.tags @> hstore('amenity','pharmacy')
AND ST_DWithin(b.way,p.way,1000)
INTERSECT
SELECT osm_id FROM osm_poi AS p, osm_polygon b
WHERE p.tags @> hstore('amenity','school')
AND ST_DWithin(b.way,p.way,1000)
Or something like that. But maybe it's a complete nonsense ...
Tomas
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tv@fuzzy.cz, sfkeller@gmail.com
Subject: Re: Slow query: Select all buildings that have >1 pharmacies and >1 schools within 1000m
In-Reply-To: <1e50929e6ba44cabb8deb2ad0ee98c82.squirrel@sq.gransy.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