Given a set [2004, 2008], what is the fastest way to find if this set intersects with other sets?
Actually, I am dealing with a database, the table has 2 columns, one has a lower bound and the other has an upper bound. The task is to find all intersecting rows with the specified 2 tuples (for example, [2004,2008]).
I use mongodb, this is internally supported (I mean there are keywords for this). I have a large user base, so I want this task to be completed as quickly as possible.
EDIT: for clearer statistics, the database table contains the following rows:
20 30
10 50
60 90
...
Given the input range (25 40), I want to return the rows that represent the range intersect with the given range.
so return: (20 30),(10 50)
source
share