Overlapping Ranges in Subsets in PostgreSQL


 

In Part I of this series, we explored overlap queries and the problems that accompany them, along with ways to improve their performance. We concluded by defining an overlap query in terms of timestamp ranges, which allowed us to use a new index type – known as GiST – that drastically sped up these types of queries. In Part II, we’ll boost overlap query performance even further, but first let’s cover some other features of range types.

A Range For All Occasions

Our Part I query used the following WHERE clause:

WHERE tsrange(o.start_time, o.end_time) && tsrange(p.enter, p.leave)

The “tsrange()”