Feature request #16375
Change Way SDO_RELATE is used in QGIS spatial queries
|Pull Request or Patch supplied:||No||Resolution:|
|Easy fix?:||No||Copied to github as #:||24285|
I executed an "identify" in QGIS against a single mapped object that comes from an Oracle table with sdo_geometry column.
Using database SQL Trace, I dumped the SQL that QGIS executes and I got the following (which I have compared to the C++ source code):
Looking at qgsoracleconn.cpp there's an hasSpatial() method which runs:
"SELECT 1 FROM v$option WHERE parameter='Spatial' AND value='TRUE'"
This is then used at line 96 of qgsoraclefeatureiterator.cpp where it says:
// sdo_relate requires Spatial
If the connection has Spatial, it appends this to the query where clause:
Now, SDO_RELATE has always been a Location spatial filter, and so is free for all Oracle users.
Only SDO_GEOM.RELATE requires Spatial in 11g but not 12c.
Additionally, SDO_RELATE is a secondary filter that executes a Primary filter (SDO_FILTER) internally to generate a candidate set of possible objects that are sent to the internal Secondary filter which does the topological analysis.
Even if SDO_RELATE was a licensed filter, it does not need to be used in conjunction with SDO_FILTER.
Additionally, the Oracle Query Optimizer is still not smart enough to realise that the SDO_FILTER is not needed so the use of it with SDO_RELATE doubles the primary filtering.
So the above query should always be running SDO_RELATE… ANYINTERACT and leaving out the SDO_FILTER part.
But, also, the "mask=ANYINTERACT" should be a bind variable as it could be set to "mask=CONTAINS" etc.
In summary (the sentences in bold are the requested functional changes):
1. SDO_RELATE is a free function and not subject to Spatial licensing
- the hasSpatial() test in the C++ is invalid and should be removed;
2. SDO_GEOM.RELATE is a spatial function up till 12c and free afterwards
- AFAIK QGIS currently doesn't use SDO_GEOM.RELATE;
3. Because SDO_RELATE executes its own primary filtering, SDO_FILTER is not needed
- Modify the C++ to remove SDO_FILTER when SDO_RELATE is needed.
4. SDO_FILTER mask parameter should be a bind variable.
#1 Updated by Simon Greener over 4 years ago
Reference for licensing.