How can we combine a quick search for children in a tree, as well as have a SPACE INDEX in a table?
Create indexes on id and parentId your table manually:
CREATE INDEX ix_mytable_parentid ON mytable (parentid)
Note that since id most likely a PRIMARY KEY , an explicit index is not required on it (one will be created implicitly).
BTW , if you have a natural geodatabase hierarchy, what is the point of using parent-child relationships for searches?
You can force queries to use SPATIAL indices:
SELECT * FROM mytable m1 JOIN mytable m2 ON MBRContains (m2.area, m1.area) AND m2.parentId = m1.id WHERE m1.name = 'London'
which will use the spatial index for search and relationships for fine filtering.
Quassnoi
source share