[MDEV-10251] ST_INTERSECTS(tbl1.col, tbl2.col) does not use the spatial index Created: 2016-06-17 Updated: 2016-06-27 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | GIS, Optimizer |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor |
| Reporter: | Geoff Montee (Inactive) | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | gis, optimizer | ||
| Description |
|
Let's say that we have the following tables: One table that keeps track of specific geolocation points, which is an InnoDB table:
And one table that keeps track of predefined areas:
Some users want to find out which area each point is in, so they ran queries like this:
This query does not use the spatial index:
It will not use the index even if FORCE INDEX is used. The users also tried something like this:
That does not use the spatial index either:
|
| Comments |
| Comment by Sergei Petrunia [ 2016-06-22 ] | ||||||||||||||||||||
|
The spatial index is used when one uses a constant:
As far as I understand, this is a known limitation of the GIS optimizer. R-Tree index only supports "range-like" scans, that is, it only works when a GIS predicate compares an indexed column with a constant. It's similar with non-GIS ranges. If we consider the "<" comparison, "t.key < const" is handled efficiently, while "t1.key < t2.col" is not. One could argue that "t1.key < t2.col" avoids running cross-joins by using "Range checked for each record" plans. We don't see "range checked for each record" for GIS queries, for some reason. I'd like to check this with holyfoot. | ||||||||||||||||||||
| Comment by Sergei Petrunia [ 2016-06-22 ] | ||||||||||||||||||||
|
Wait. Actually with MariaDB 10.1.15, I do get "Range checked for each record":
But I don't get it for the subquery:
Also tried with 10.0.26-MariaDB-debug. I get the same results as with 10.1 | ||||||||||||||||||||
| Comment by Sergei Petrunia [ 2016-06-22 ] | ||||||||||||||||||||
|
Example I've tried with: | ||||||||||||||||||||
| Comment by Sergei Petrunia [ 2016-06-22 ] | ||||||||||||||||||||
|
The difference between having "Range checked for each record" for join and not having it for subselect has nothing to do with GIS.
| ||||||||||||||||||||
| Comment by Sergei Petrunia [ 2016-06-23 ] | ||||||||||||||||||||
|
Ok, looking at the original issue, one can tell that it's not at all clear if making ST_INTERSECTS slightly faster would resolve the issue. | ||||||||||||||||||||
| Comment by Sergei Petrunia [ 2016-06-23 ] | ||||||||||||||||||||
|
Changing the bug attributes accordingly It would be nice to have efficient handling for use cases like
but
|