sorting - Changing data organization on disk in MySQL -


we have data set static in mysql database, read times terrible (even indexes on columns being queried). theory since rows stored randomly (or in order of insertion), disk head has scan around find different rows, if knows due index, instead of reading them sequentially.

is possible change order data stored in on disk can read sequentially? unfortunately, can't add ton more ram @ moment have queries cached. if it's possible change order, can define order within order? in, sort column, sort column if first column equal.

could have indices?

additional details: non-relational single-table database 16 million rows, 1 gb of data total, 512 mb ram, mariadb 5.5.30 on ubuntu 12.04 standard hard drive. virtualized machine using openvz, 2 dedicated core e5-2620 2ghz cpu

create syntax:

create table `events` (   `id` int(11) not null auto_increment,   `provider` varchar(10) default null,   `location` varchar(5) default null,   `start_time` datetime default null,   `end_time` datetime default null,   `cost` int(11) default null,   primary key (`id`),   key `provider` (`provider`),   key `location` (`location`),   key `start_time` (`start_time`),   key `end_time` (`end_time`),   key `cost` (`cost`) ) engine=innodb auto_increment=16321002 default charset=utf8; 

select statement takes long time:

select * `events`  `events`.start_time >= '2013-05-03 23:00:00' , `events`.start_time <= '2013-06-04 22:00:00' , `flightroutes`.location = 'chicago' 

explain select:

1   simple  events  ref location,start_time location    18  const   3684    using index condition; using 

mysql can select one index upon filter (which makes sense, because having restricted results using index cannot determine how such restriction has affected other indices). therefore, tracks cardinality of each index , chooses 1 selective (i.e. has highest cardinality): in case, has chosen location index, typically leave 3,684 records must fetched , filtered using where find match desired range of start_time.

you should try creating composite index on (location, start_time):

alter table events add index (location, start_time) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -