1# WL#6745 InnoDB R-tree support
2# This test case will test R-tree split.
3
4# Not supported in embedded
5--source include/not_embedded.inc
6
7--source include/have_innodb.inc
8--source include/have_debug.inc
9--source include/big_test.inc
10--source include/not_valgrind.inc
11
12# Create table with R-tree index.
13create table t1 (c1 int, c2 varchar(255), c3 geometry not null, primary key(c1, c2), spatial index (c3))engine=innodb;
14
15# Insert enough values to let R-tree split.
16delimiter |;
17
18create function rand_string(str_length tinyint unsigned, str_type tinyint unsigned) returns varchar(255)
19begin
20    declare counter int unsigned default 0;
21    declare const_chars varchar(64) default '0123456789';
22    declare result varchar(255) default '';
23
24    if str_type = 1 then
25        set const_chars = '0123456789';
26    elseif str_type = 2 then
27        set const_chars = 'abcdefghijklmnopqrstuvwxyz';
28    elseif str_type = 3 then
29        set const_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
30    elseif str_type = 4 then
31        set const_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
32    elseif str_type = 5 then
33        set const_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
34    else
35        set const_chars = '0123456789';
36    end if;
37
38    while counter < str_length do
39        set result = concat(result,substr(const_chars,ceil(rand()*(length(const_chars)-1)),1));
40    set counter = counter + 1;
41    end while;
42
43    return result;
44end|
45
46create procedure insert_t1(IN total int)
47begin
48        declare i int default 1;
49        declare i2 int default 1;
50        declare str varchar(100) default '';
51        declare dup_key int default 1;
52        while i <= total DO
53                set i2 = floor(0+(rand()*100));
54                set str = rand_string(i2, 5);
55                select count(*) into dup_key from t1 where c2 = str and c1 = i;
56                while dup_key <> 0 do
57                    set i2 = floor(0+(rand()*100));
58                    set str = rand_string(i2, 5);
59                    select count(*) into dup_key from t1 where c2 = str and c1 = i;
60                end while;
61                insert into t1 values (i, str, Point(i, i));
62                set i = i + 1;
63        end while;
64end|
65
66delimiter ;|
67
68CALL insert_t1(10000);
69check table t1;
70
71start transaction;
72CALL insert_t1(30000);
73rollback;
74check table t1;
75
76# Clean up.
77drop procedure insert_t1;
78drop function rand_string;
79drop table t1;
80
81