The spatial index
Because spatial columns contain multidimensional geographic data, applications that query spatial columns require an index strategy that quickly identifies all geometries that satisfy a specified spatial relationship. To index spatial data, you create a spatial index, called the R-tree index.
The two-dimensional R-tree index differs from the traditional hierarchical (one-dimensional) B-tree index. Spatial data is two-dimensional, so you cannot use the B-tree index for spatial data. Similarly, you cannot use an R-tree index with non-spatial data.
CREATE INDEX location_ix
ON hazardous_sites (location ST_Geometry_ops)
USING RTREE;
The query optimizer does not use the R-tree index unless the statistics on the table are up-to-date. If the R-tree index is created after the data is loaded, the statistics are current and the optimizer uses the index. However, if the index is created before the data is loaded, the optimizer does not use the R-tree index because the statistics are out of date.
UPDATE STATISTICS FOR TABLE hazardous_sites;