| 1 |
create table t1 (c1 int, c2 varchar(255), c3 geometry not null SRID 0, primary key(c1, c2), spatial index (c3))engine=innodb charset latin1; |
| 2 |
create function rand_string(str_length tinyint unsigned, str_type tinyint unsigned) returns varchar(255) charset latin1 |
| 3 |
begin |
| 4 |
declare counter int unsigned default 0; |
| 5 |
declare const_chars varchar(64) charset latin1 default '0123456789'; |
| 6 |
declare result varchar(255) charset latin1 default ''; |
| 7 |
if str_type = 1 then |
| 8 |
set const_chars = '0123456789'; |
| 9 |
elseif str_type = 2 then |
| 10 |
set const_chars = 'abcdefghijklmnopqrstuvwxyz'; |
| 11 |
elseif str_type = 3 then |
| 12 |
set const_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
| 13 |
elseif str_type = 4 then |
| 14 |
set const_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
| 15 |
elseif str_type = 5 then |
| 16 |
set const_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
| 17 |
else |
| 18 |
set const_chars = '0123456789'; |
| 19 |
end if; |
| 20 |
while counter < str_length do |
| 21 |
set result = concat(result,substr(const_chars,ceil(rand()*(length(const_chars)-1)),1)); |
| 22 |
set counter = counter + 1; |
| 23 |
end while; |
| 24 |
return result; |
| 25 |
end| |
| 26 |
create procedure insert_t1(IN total int) |
| 27 |
begin |
| 28 |
declare i int default 1; |
| 29 |
declare i2 int default 1; |
| 30 |
declare str varchar(100) charset latin1 default ''; |
| 31 |
declare dup_key int default 1; |
| 32 |
while i <= total DO |
| 33 |
set i2 = floor(0+(rand()*100)); |
| 34 |
set str = rand_string(i2, 5); |
| 35 |
select count(*) into dup_key from t1 where c2 = str and c1 = i; |
| 36 |
while dup_key <> 0 do |
| 37 |
set i2 = floor(0+(rand()*100)); |
| 38 |
set str = rand_string(i2, 5); |
| 39 |
select count(*) into dup_key from t1 where c2 = str and c1 = i; |
| 40 |
end while; |
| 41 |
insert into t1 values (i, str, Point(i, i)); |
| 42 |
set i = i + 1; |
| 43 |
end while; |
| 44 |
end| |
| 45 |
CALL insert_t1(10000); |
| 46 |
check table t1; |
| 47 |
Table Op Msg_type Msg_text |
| 48 |
test.t1 check status OK |
| 49 |
start transaction; |
| 50 |
CALL insert_t1(30000); |
| 51 |
rollback; |
| 52 |
check table t1; |
| 53 |
Table Op Msg_type Msg_text |
| 54 |
test.t1 check status OK |
| 55 |
drop procedure insert_t1; |
| 56 |
drop function rand_string; |
| 57 |
drop table t1; |