How to do it...

The best way to see how a query can be affected by an index is by running the query before and after the addition of an index. In this recipe, in order to avoid the need to define the schema, all the tables are assumed to be on the public schema. The following steps will guide you through the process of optimizing a query with an index:

  1. Run the following query, which returns the names of all the schools found in San Francisco:
      SELECT schoolid FROM caschools sc JOIN sfpoly sf       ON ST_Intersects(sf.geom, ST_Transform(sc.geom, 3310));
  1. The results from the query do not matter. We are more interested in the time it took to run the query. When we run the query three times, it runs with the following elapsed times; your numbers ...

Get PostGIS Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.