I am trying to run the following query:
SELECT * FROM fences where ST_Intersects(geom, ST_GeomFromText('POINT(-73.990452 40.994184)', 4326))
When I run Explain Analyze I get the following:
"Index Scan using fencegeomindex1 on fences (cost=0.41..8.68 rows=1 width=980) (actual time=0.231..0.353 rows=9 loops=1)"
" Index Cond: (geom && '0101000020E61000008010C990637F52C06D1ADB6B417F4440'::geometry)"
" Filter: _st_intersects(geom, '0101000020E61000008010C990637F52C06D1ADB6B417F4440'::geometry)"
"Planning time: 0.239 ms"
"Execution time: 0.393 ms"
When I run this query which is using a normal postgresql polygon:
SELECT * FROM fences WHERE poly @> '(-73.990452,40.994184)'
I get:
"Bitmap Heap Scan on public.fences (cost=464.69..24194.22 rows=6229 width=980) (actual time=0.058..0.087 rows=9 loops=1)"
" Recheck Cond: (fences.poly @> '((-73.990452,40.994184))'::polygon)"
" Heap Blocks: exact=7"
" Buffers: shared hit=14"
" -> Bitmap Index Scan on fencepolyindex1 (cost=0.00..463.13 rows=6229 width=0) (actual time=0.042..0.042 rows=9 loops=1)"
" Index Cond: (fences.poly @> '((-73.990452,40.994184))'::polygon)"
" Buffers: shared hit=7"
"Planning time: 0.094 ms"
"Execution time: 0.136 ms"
From a cost perspective the query using the postgis ST_Intersects appears to be much cheaper however it is taking much longer to plan and then to execute. Any idea why this is happening. I have Vacuumed and Analyzed the table.
Running the two different queries in our real application the one using PostGIS is netting us about a 1/3rd of the throughput as the plain old postgresql query.
One more note, we are currently Unioning multiple queries together to prevent extra network traffic not sure if this would affect how the queries are executed.
example:
SELECT * FROM fences where geom && ST_GeomFromText('POINT(-82.85966597206304 31.44405266605823)') UNION ALL
SELECT * FROM fences where geom && ST_GeomFromText('POINT(-82.85966597206304 31.44405266605823)')