[postgis-users] Invoking GIST index on 2 disjoints within a query

Dylan Lorimer edylan at google.com
Thu Apr 3 14:12:38 PDT 2008


Hi,

So I have probably a simple question but I don't use PostGIS enough to
know the right way to go about this. Hoping someone can help.

So I've got 3 spatial tables, each containing a bunch of polygon
geometries. Let's call the tables A, B, C. What I want is to find out
which polygons in table A are disjoint from all polygons in tables B
and C. Meaning, which polygons in A have 0 overlap with polygons in B
or C.

I seem to have no troubles doing this when using only 2 tables, but
adding the 3rd is messing things up. Oh, and I also want to invoke the
GIST indexes to speed things up.

Here's the (slightly generalized) query I think I should be using:

SELECT <some stuff> FROM A, B, C WHERE disjoint(A.the_geom,
B.the_geom) AND disjoint(A.the_geom, C.the_geom) AND <some other
attribute filters> AND A.the_geom && B.the_geom AND A.the_geom &&
C.the_geom;

I've not seen this query complete successfully as it takes so long,
but I think something is wrong with it as running it against only A
and B is really quick and there aren't too many geometries in the
tables.

Thoughts?

Cheers,
dylan



More information about the postgis-users mailing list