Ticket #4699 (closed defect: fixed)
Postgres OGR driver not using spatial filters correctly.
|Reported by:||digimap2k||Owned by:||warmerdam|
File: ogrpgdatasource.cpp Method: ExecuteSQL Lines: Around 2334 onwards
When calling ExecuteSQL on a postgres OGR driver I am providing an SQL select statement and a spatial filter. Where there are results in the database this works fine.
Where there are no results matching the select statement (irrespective of the filter) then the following happens.
1. OGR creates the ExecuteSQLCursor and fetches zero records. 2. No errors seen so the results layer is created. 3. The results layer fails to implement the spatial args as the cursor fetch has no records so the SRID remains unknown. 4. OGR attempts to pull a cursor page of records without a spatial filter. This requires a full scan of the database using fields which may not be indexed and is slow.
FIX - would be to check that the cursor used to try and establish the geometry column actually hit something and return an empty layer of results rather than retrawling the database.