I have a Raspberry Pi I have been using to log household temperature data collected from a bunch of 1-Wire sensors. The data has all been collected into a MySQL database over several years. I use the Raspbian distribution and the default MySQL configuration. I now have a table with over a million records and my Pi is running queries very slowly.
Here is a description of the TemperatureRecords table:
+--------------+----------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+----------+------+-----+---------------------+-------+
| timeRecorded | datetime | NO | PRI | 0000-00-00 00:00:00 | |
| sensorName | char(3) | NO | PRI | | |
| tempValue | float | YES | | NULL | |
+--------------+----------+------+-----+---------------------+-------+
I record the date and time, a 3 character sensor name and value for the temperature. I want to run two queries, one to select the current (most recent) temperature of a certain sensor, and one to select the highest temperature that day.
Current temperature example:
SELECT ROUND(tempValue, 1) as tempValue
FROM TemperatureRecords
WHERE DATE(timeRecorded) = '2015-01-20' AND HOUR(timeRecorded) = '20' AND sensorName = 'abc'
ORDER BY timeRecorded DESC LIMIT 1;
Highest temperature example:
SELECT MAX(tempValue)
FROM TemperatureRecords
WHERE DATE(timeRecorded) = '2015-01-20' AND sensorName = 'abc';
Unfortunately these can take 10-20 seconds to complete, which is too slow, especially as I want to retrieve data from several sensors to display on a web page at once.
I have tried adding additional indexes to the table, but this has not made any improvement, and I am not sure I understand indexes fully anyway. I also tried using the MySQL configuration for small systems found in /usr/share/doc/mysql-server-5.5/examples/my-small.cnf, which I was told might improve performance but to no avail.
My knowledge of MySQL is somewhat basic. Am I expecting to much from a Raspberry Pi now my data has grown so large, or is there anything I can do to improve my setup?