To optimize spatial queries, spatial indices are supported on the Geometry
columns of regular tables (not shapefiles). The syntax is the following:
The spatial index is stored on disk. Several spatial operators (such as the
&& predicate operator for bounding box overlap) use this index.
Example
In this example, we calculate the number of roads that intersect several
polygonal areas. First, we create the area and roads tables, putting a
spatial index on their Geometry columns:
Now we execute the request:
Result:
IDAREA
ROADSCOUNT
1
2
2
1
Note that ST_Intersects does not yet support spatial
indices, but it will in a future release.