1.插入測試數據
1.usera
插入500w數據
2.userb
插入500w數據
3.userall
(主表)
- usert1 (子表) 插入250w數據
- usert2 (子表) 插入250w數據
4.userall2
(主表)
- usert3 (子表) 插入250w數據
- usert4 (子表) 插入250w數據
CREATE TABLE usertb(
id serial,
uname varchar(20) ,
ucreatetime datetime ,
age int(11))
ENGINE=MYISAM
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
AUTO_INCREMENT=1
ROW_FORMAT=COMPACT;
CREATE TABLE usertall(
id serial,
uname varchar(20) ,
ucreatetime datetime ,
age int(11))
ENGINE=MERGE union(usert1,usert2) insert_method=last
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
AUTO_INCREMENT=1
ROW_FORMAT=COMPACT;
delimiter $$
SET AUTOCOMMIT = 0$$
create procedure test1()
begin
declare v_cnt decimal (10) default 0 ;
dd:loop
insert into userta values
(null,'用戶1',now(),20),
(null,'用戶2',now(),20),
(null,'用戶3',now(),20),
(null,'用戶4',now(),20),
(null,'用戶5',now(),20),
(null,'用戶6',now(),20),
(null,'用戶7',now(),20),
(null,'用戶8',now(),20),
(null,'用戶9',now(),20),
(null,'用戶0',now(),20);
commit;
set v_cnt = v_cnt+10 ;
if v_cnt = 5000000 then leave dd;
end if;
end loop dd ;
end;$$
delimiter;
call test1;
select * from userta; --3.63s
注意點
1.分表必須保證主表和子表表結構一致,不然報錯 Error Code : 1168 Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist