I whipped up a table of 89280 triangles, 78 of which where randomly
coded for isolation. Then I deleted the neighbors of these triangles
with the command:
DELETE FROM gse_tritab1
WHERE oid in (
SELECT a.oid oid
FROM gse_tritab1 a, gse_tritab1 b
WHERE b.class = 'X'
AND sdo_anyinteract(a.geom,b.geom) = 'TRUE'
) AND class = 'R';
Which resulted in a layer looking like this:
Issuing the query:
SELECT a.oid oid
FROM gse_tritab1 a
WHERE NOT EXISTS (
SELECT b.oid
FROM gse_tritab1 b
WHERE SDO_FILTER(b.geom,a.geom,'querytype = WINDOW') = 'TRUE'
AND SDO_GEOM.RELATE(b.geom,'DISJOINT',a.geom,0.001) = 'FALSE'
AND b.oid <> a.oid
)
returned 76 rows (because two of the randomly selected polygons were
touching) in 4.06 minutes.
Just for grins I also ran:
SELECT a.oid oid
FROM gse_tritab1 a
WHERE NOT EXISTS (
SELECT b.oid
FROM gse_tritab1 b
WHERE SDO_ANYINTERACT(b.geom,a.geom) = 'TRUE'
AND b.oid <> a.oid
)
and it also generated 76 rows, in 6.47 minutes.
Both the DELETE and the queries used the technique known as a "self join" to
compare a column in the table to itself (one in a subselect, and one in
an EXISTS clause).
It's important to note that the position of the referenced columns in the
spatial columns is important -- The table with the index (the "many" side
of the "find many which have a relationship with one") must be in the first
position of the Spatial function for optimal performance (and sometimes to
prevent an ORA-13226 error). If I left out the SDO_FILTER constraint with the
RELATE test, performance was significantly worse.
select count(*) where "SDO_ANYINTERACT(geom1,geom2)='TRUE'
. Geom1 is feature that is under study, geom2 holds all the other features of the table. If count=0 the feature is disjoint. Query will use spatial index and it will be fast and I guess that doing it 100000 times will take couple of minutes.