查询的时候通过建索引解决。
举例说明:
create table datasources
(
year_id smallint unsigned not null,
month_id tinyint unsigned not null,
datasource_id tinyint unsigned not null,
id int unsigned not null, -- needed for uniqueness
data int unsigned not null default 0,
primary key (year_id, month_id, datasource_id, id)
)
engine=innodb;
使用year_id,month_id,datasource_id, id这几个组合查询key就可以明显提高查询速度
记住:year_id是不要要带上的,否则后面的几个查询key不会生效
select * from datasources where year_id = 2011 and month_id between 1 and 3;
select * from datasources where year_id = 2011 and month_id = 4 and datasouce_id = 100;