mysql优化(分区表)待续

mysql> create table aa(id int,name varchar(20));

Query OK, 0 rows affected (0.16 sec)

delimiter //
create procedure bb()
begin
declare i int default 10;
while i<=10000000 do
insert into aa values(i,'bob');
set i=i+1;
end while;
end //
delimiter ;

mysql> call bb();
Query OK, 1 row affected (3 min 13.13 sec)


mysql> select * from aa where id=999999;
+--------+------+
| id     | name |
+--------+------+
| 999999 | bob  |
+--------+------+

1 row in set (3.28 sec)  没有使用分区表查询花时328毫秒

mysql> alter table aa partition by range(id) ( 

partition p1 values less than (2500000), 

partition p2 values less than (5000000), 

partition p3 values less than (7500000), 

partition p4 values less than (maxvalue));
Query OK, 9999991 rows affected (16.24 sec)
Records: 9999991  Duplicates: 0  Warnings: 0

mysql> select * from aa where id=999999;
+--------+------+
| id     | name |
+--------+------+
| 999999 | bob  |
+--------+------+
1 row in set (0.84 sec)使用分区表查询花时84毫秒

使用分区表与不使用分区表查询速度有很大的差别

你可能感兴趣的:(mysql优化(分区表)待续)