This post is inspired by a discussion with John
Didion:
Is there any way to optimize the query for overlapping ranges in MySQL
if both ranges are dynamic?
I have two tables, each with integer range columns (specified as
LineString), and I want to find rows that overlap.
No matter what I try, the query planner never uses any indexes.
This question addresses a well-known problem of efficient
searching for the intersecting intervals. The queries that deal
with it require ability to search for the intervals (stored in
two distinct columns) containing a constant scalar value.
Plain B-Tree indexes used by most databases do
not speed up the queries like that. However,
MySQL supports SPATIAL indexes that
can index …
[Read more]