I found the SQL test scripts at
http://www.gaia-gis.it/spatialite/test-sql-scripts-2.3.zip. These
definitely helped me rewrite my query to make it more efficient. The
query ran in seconds, although I am not sure if I benefited from any
caching of the query.
I would still appreciate a critique if anyone is willing to help me
optimize this.
The use case is where I have several polygon data sets that will be
static. I will be generating point data sets ranging from 1- ~30,000
points and then doing overlay operations with the different polygon
data sets to determine which polygon from each data set a point falls
into.
So, I want to do everything to pre-index and optimize the poly data
sets, and if necessary, index the point data set after creating it and
before running my queries.
Here is the latest query that I came up with:
SELECT
pt.id,
poly.id
FROM mypoints as pt, mypolys as poly
WHERE INTERSECTS(pt.geometry, poly.geometry)
AND pt.ROWID IN
(
SELECT pkid FROM idx_mypoints_Geometry
WHERE xmin > MbrMinX(poly.Geometry) AND
xmax < MbrMaxX(poly.Geometry) AND
ymin > MbrMinY(poly.Geometry) AND
ymax < MbrMaxY(poly.Geometry)
)