This is like a relational join. Since your timestamps do not have to match, this is called not equivalent.
Sort-Merge is one of several popular algorithms. For non equijoins it works well. I think this will be what you are called "pre-merge". I don’t know what you mean by “real-time merge”, but I suspect that this is still a simple sort-merge, which is a great technique, heavily used by real databases.
Nested loops can also work. In this case, you are reading a smaller table in the outer loop. In the inner loop, you will find all the “matching” rows from the larger table. This is sort-merge efficiently, but with the assumption that there will be several rows from the large table that will correspond to the small table.
This, BTW, will allow you to more correctly assign value to the relationship between event data and environmental data. Instead of reading the result of a massive merge sort and trying to determine which record you have, nested loops do a great job.
In addition, you can “search” into a smaller table by reading the larger table.
This is difficult if you are making unequal comparisons because you do not have a suitable key to easily extract from a simple dict. However, you can easily extend the dict (overriding __contains__ and __getitem__ ) to compare ranges by key instead of simple equality tests.
source share