Hourly temperature readings are collected from several animal cages in an animal shelter every 30 minutes and dumped them into a file. A cron processes that data and inserts it into a MYSQL database. Currently all 48 temperature readings for the day are stored in one table, and I have it updating them as the data comes in or if no record exists, a new record is created storing the first temperature.
We currently have a table for Cage information and one for the cage temperature readings. Our total number of cages is 45. The amount of data we have is 7 years (roughly 2557 days). The total number of records for the temperature table is: 115,065
We will be adding different locations and additional cages to the system, thus the total number of cages will be greater than 1,000. We expect the data use to grow very fast.
Is there a more efficient way of structuring the table below to optimize read speed? The data is used to generate graphs of every cage that gets displayed every morning, and 30min crons to check for inadequate ventilation inside cage.
The current temperature table is as follows:
CREATE TABLE `temperature_readings` (
`CAGE_ID` int(10) NOT NULL DEFAULT '0',
`INT_VALUE_0000` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0030` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0100` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0130` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0200` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0230` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0300` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0330` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0400` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0430` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0500` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0530` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0600` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0630` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0700` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0730` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0800` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0830` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0900` decimal(5,2) DEFAULT NULL,
`INT_VALUE_0930` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1000` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1030` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1100` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1130` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1200` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1230` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1300` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1330` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1400` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1430` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1500` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1530` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1600` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1630` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1700` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1730` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1800` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1830` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1900` decimal(5,2) DEFAULT NULL,
`INT_VALUE_1930` decimal(5,2) DEFAULT NULL,
`INT_VALUE_2000` decimal(5,2) DEFAULT NULL,
`INT_VALUE_2030` decimal(5,2) DEFAULT NULL,
`INT_VALUE_2100` decimal(5,2) DEFAULT NULL,
`INT_VALUE_2130` decimal(5,2) DEFAULT NULL,
`INT_VALUE_2200` decimal(5,2) DEFAULT NULL,
`INT_VALUE_2230` decimal(5,2) DEFAULT NULL,
`INT_VALUE_2300` decimal(5,2) DEFAULT NULL,
`INT_VALUE_2330` decimal(5,2) DEFAULT NULL,
PRIMARY KEY (`CAGE_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
My thoughts were to either Normalize multiple temperature readings into a halfhour_read table such as
halfhour_read{
- cage_id
- datetime
- temperature reading
}
or Hash temperature_readings by either cage_id, or a todays(date) so that it is partitioned.
As far as I understand, the first option would bump the number of records from 115,065 to 5,523,120 and would grow quickly in comparison, yielding a future space problem.