summaryrefslogtreecommitdiff
path: root/mysql-test/main/order_by_pack_big.test
blob: 14cd22acde4c09fe027f5c12982b0416cf4e01ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
--source include/big_test.inc
--source include/have_sequence.inc
--source include/have_64bit.inc

set @save_rand_seed1=  @@RAND_SEED1;
set @save_rand_seed2=  @@RAND_SEED2;
set @@RAND_SEED1=810763568, @@RAND_SEED2=600681772;

create table t1(a int);
insert into t1 select seq from seq_1_to_10000 order by rand(),seq;
delimiter |;

--echo #
--echo # parameters:
--echo # mean           mean for the column to be considered
--echo # max_val        max_value for the column to be considered
--echo #
--echo # This function generate a sample of a normal distribution
--echo # This function return a point
--echo # of the normal distribution with a given mean.
--echo #

CREATE FUNCTION
generate_normal_distribution_sample(mean DOUBLE, max_val DOUBLE)RETURNS DOUBLE
BEGIN
  DECLARE z DOUBLE DEFAULT 0;
  SET z= (rand() + rand() + rand() + rand() + rand() + rand())/6;
  SET z= 2*(max_val-mean)*z;
  SET z= z + mean - (max_val-mean);
  return z;
END|

--echo #
--echo # parameters:
--echo # len      length of the random string to be generated
--echo #
--echo # This function generates a random string for the length passed
--echo # as an argument with characters in the range of [A,Z]
--echo #

CREATE FUNCTION generate_random_string(len INT) RETURNS varchar(128)
BEGIN
  DECLARE str VARCHAR(256) DEFAULT '';
  DECLARE x INT DEFAULT 0;
  WHILE (len > 0) DO
    SET x =round(rand()*25);
    SET str= CONCAT(str, CHAR(65 + x));
    SET len= len-1;
  END WHILE;
RETURN str;
END|

--echo #
--echo # parameters:
--echo # mean      mean for the column to be considered
--echo # min_val   min_value for the column to be considered
--echo # max_val   max_value for the column to be considered
--echo #
--echo # This function generate a normal distribution sample in the range of
--echo # [min_val, max_val]
--echo #

CREATE FUNCTION
clipped_normal_distribution(mean DOUBLE, min_val DOUBLE, max_val DOUBLE)
RETURNS INT
BEGIN
  DECLARE r DOUBLE DEFAULT 0;
  WHILE 1=1 DO
    set r= generate_normal_distribution_sample(mean, max_val);
    IF (r >= min_val AND r <= max_val) THEN
      RETURN round(r);
    end if;
  END WHILE;
 RETURN 0;
END|

delimiter ;|

create table t2 (id INT NOT NULL, a INT, b int);
insert into t2
select a, clipped_normal_distribution(12, 0, 64),
       clipped_normal_distribution(32, 0, 128)
from t1;

CREATE TABLE t3(
  id INT NOT NULL,
  names VARCHAR(64),
  address VARCHAR(128),
  PRIMARY KEY (id)
);

--echo #
--echo # table t3 stores random strings calculated from the length stored in
--echo # table t2
--echo #

insert into t3
select id, generate_random_string(a), generate_random_string(b) from t2;


let $query= select id DIV 100 as x,
            MD5(group_concat(substring(names,1,3), substring(address,1,3)
                order by id))
            FROM t3
            GROUP BY x;

--echo #
--echo # All records fit in memory
--echo #

set sort_buffer_size=262144*10;
--source include/analyze-format.inc
eval analyze format=json $query;
flush status;
eval $query;
show status like '%sort%';
set sort_buffer_size=default;

--echo #
--echo # Test for merge_many_buff
--echo #

set sort_buffer_size=32768;
--source include/analyze-format.inc
eval analyze format=json $query;
flush status;
eval $query;
show status like '%sort%';
set sort_buffer_size=default;

set @@RAND_SEED1= @save_rand_seed1;
set @@RAND_SEED2= @save_rand_seed2;

drop function generate_normal_distribution_sample;
drop function generate_random_string;
drop function clipped_normal_distribution;
drop table t1, t2, t3;