转 http://blog.csdn.net/m582445672/article/details/7800694 1.创建一个测试表 [sql] view plaincopyprint? create table test( id varchar (20) not null , name varchar (20) not null , submit_timedatetime not null , index time_index(submit_time),
转 http://blog.csdn.net/m582445672/article/details/7800694
1.创建一个测试表
[sql] view plaincopyprint?
create table test ( id varchar(20) not null, name varchar(20) not null, submit_time datetime not null, index time_index (submit_time), index id_index (id) )engine=myisam partition by range columns(submit_time) ( partition p1 values less than ('2010-02-01'), partition p2 values less than ('2010-03-01'), partition p3 values less than ('2010-04-01'), partition p4 values less than ('2010-05-01'), partition p5 values less than ('2010-06-01'), partition p6 values less than ('2010-07-01'), partition p7 values less than ('2010-08-01'), partition p8 values less than ('2010-09-01'), partition p9 values less than ('2010-10-01'), partition p10 values less than ('2010-11-01'), partition p11 values less than ('2010-12-01') ); create table test ( id varchar(20) not null, name varchar(20) not null, submit_time datetime not null, index time_index (submit_time), index id_index (id))engine=myisampartition by range columns(submit_time)(partition p1 values less than ('2010-02-01'),partition p2 values less than ('2010-03-01'),partition p3 values less than ('2010-04-01'),partition p4 values less than ('2010-05-01'),partition p5 values less than ('2010-06-01'),partition p6 values less than ('2010-07-01'),partition p7 values less than ('2010-08-01'),partition p8 values less than ('2010-09-01'),partition p9 values less than ('2010-10-01'),partition p10 values less than ('2010-11-01'),partition p11 values less than ('2010-12-01') );
2.写一个存储过程,插入数据
[sql] view plaincopyprint?
delimiter // create procedure mark_test() begin declare v int default 0; while v do insert into test values (v,'testing partitions',adddate('2010-01-01', interval v hour)); set v = v + 1; end while; end // delimiter ; delimiter // create procedure mark_test()begin declare v int default 0; while v
3.实验开始
上面可以看到,这个是查某一个分区里面的某一些内容,所以完全可以用到index.效果很好..
上面可以看到,跨分区查询,效果也非常不错.
上面可以到看,跨分区查询是,如果某个分区没有用到索引(p4就是全表扫描),整个也没有用到index.但好的是,只扫描需要的分区
上面可以看到,如果你不用分区的字段查询,是很杯具的,因为mysql不知道你分区的index是分别存放到哪个分区上,所以要全index扫描,
3.顺便看看表结构
a. 图中test3 是innodb的存储引擎,
test3.frm是表结构.
test3.par是分区表的信息.
数据和索引都是存放在表空间里面在
b.图中test是myisam的存储引擎,
test.frm是表结构,
test.par是分区表的信息.
test#p#p10.myd是数据文件之一,
test#p#p10.myi是索引文件之一