2021年3月31日星期三

Good way to ensure there are no overlapping intervals in a table

I am storing intervals where From < To for each entry. If I build an index on "From", then I can get the minimum and maximum entries efficiently when inserting a new record to do a validation check. However, this doesn't help if there were a big gap somewhere in these entries where a given record could've easily fit. For example:

[3, 5]  [8, 9]  

If I want to insert [6,7] or [1,2] above, what is the best way to check?

Just wondering if there's an efficient way of ensuring that a record doesn't overlap with any of the existing entries without comparing against all of them.

https://stackoverflow.com/questions/66896914/good-way-to-ensure-there-are-no-overlapping-intervals-in-a-table April 01, 2021 at 08:21AM

没有评论:

发表评论