I’ve got raw data from two sensors in a database. In order to calculate meaningful results from these sensors, I need one datapoint from each. The catch is that their timestamps are not guaranteed to match up exactly. I could make a request for MySQL to take a timestamp from one sensor and find the timestamp that’s closest for the other sensor, but this request would need to be run for each row, then again whenever a new row is added, and I’m concerned that searching through a table whenever a datapoint gets inserted might become a performance burden especially if more sensors like this are added. For a naive algorithm at least, finding the closest timestamp seems like a linear time operation. Could this cause a performance problem, or does MySQL have an optimization in this regard?
Share
You could use a simple query to fetch the result closest to the given value:
Should do the trick and is not very performance intensive if you use a index on the right columns. MySQL is made for queries like this.