I am working with an application that uses phpActiveRecord and mySQL to output data from a network of sensors and build it on several flot.js graphs on the client.
There are several timeframes that the user can choose between to influence the range of data displayed by the graphs. 2hrs, 24hrs, 3 days and 1 week.
Sensors are sent to the database every 60 seconds, so when plotting, the query pulls in all lines between now and DATE_SUB(CUR_DATE - INTERVAL ? DAY) where? either 1, 3 or 7, etc.
However, this leads to a massive number of returned rows (60,000 + for the full week!) And causes huge server delays and errors.
I know that I can simply increase the maximum memory available for requests in the php.ini , but this is hardly a good solution and does not solve the speed problem.
My question is: is there a way that I can easily select only every second or third row from the required date range depending on the length of the interval that the user wants to view?
In C or Java, I would do something like modulo select to return alternative strings, but I can't think of a way to do this in the current structure.
Any ideas would be appreciated. Thanks.
source share