I have an AWS lambda function deployed with a spatialite table. When queried, a point lookup is done on the table to find the locations in the table containing the point.
The first execution of the function I typically see the query execute taking 3.3 seconds.
point_in_polygon_query = 'SELECT ssc_code16, ssc_name16, ste_name16 FROM suburbs WHERE within(PointFromText(\'POINT({lon} {lat})\'),suburbs.GEOMETRY)'
cur.execute(point_in_polygon_query.format(lat=str(lat), lon=str(lon)))
And the fetchall taking 6.6 seconds.
rows = cur.fetchall()
(Determined by using AWS X-Ray subsegments)
However any subsequent runs take about 0.11 seconds each for the query execution and fetchall.
Why is the first execution of my function taking so long (compared to subsequent executions)?
Note: Subsequent query optimisation has significantly improved response times but I still want to understand the why.