1.创建一个测试表
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') );
delimiter // CREATE PROCEDURE mark_test() begin declare v int default 0; while v < 8000 do insert into test values (v,'testing partitions',adddate('2010-01-01', INTERVAL v hour)); set v = v + 1; end while; end // delimiter ;
上面可以看到,这个是查某一个分区里面的某一些内容,所以完全可以用到index.效果很好..
上面可以看到,跨分区查询,效果也非常不错.