I have a table with the following structure
SHOW CREATE TABLE data_temperature;
CREATE TABLE `data_temperature` (
`temperature_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`data_id` bigint(20) unsigned NOT NULL,
`x_id` varchar(32) DEFAULT NULL,
`x_sn` varchar(16) DEFAULT NULL,
`x_unit` char(1) DEFAULT NULL,
`x_value` decimal(6,2) DEFAULT NULL,
PRIMARY KEY (`temperature_id`),
KEY `created` (`created`),
KEY `data_id` (`data_id`),
KEY `x_value` (`x_value`)
) ENGINE=InnoDB AUTO_INCREMENT=6274618 DEFAULT CHARSET=latin1
I have a somewhat basic query pulling data from here that's really slow. So I've broken the query down into simpler terms and found that this very simple query is slow (17.52 seconds):
SELECT data_temperature.x_value FROM data_temperature WHERE data_temperature.created BETWEEN '2015-02-02 18:28:42' AND '2015-03-04 18:28:42';
The table has 6,274,617 rows. In fact, SELECT COUNT(*) FROM data_temperature
takes 3.66 seconds as well.
The system that this query is running on is my dev system, which is a quad-core running Ubuntu 14.04, 4GB of RAM, and a solid-state drive.
Is this about how long it should take to run a query like this, or am I doing something wrong? Is there a more efficient way to return the data?