summaryrefslogtreecommitdiff
path: root/mysql-test/suite/sys_vars/t/max_sort_length_func.test
blob: fd0b87750a1ecf1164ec8c7aaf5e1fb5b1be114d (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
############# mysql-test\t\max_sort_length_func.test ###########################
#                                                                              #
# Variable Name: sql_warnings                                                  #
# Scope: SESSION                                                               #
# Access Type: Dynamic                                                         #
# Data Type: NUMERIC                                                           #
# Default Value: 1024                                                          #
# Values:      4-8388608                                                       #
#                                                                              #
#                                                                              #
# Creation Date: 2008-03-02                                                    #
# Author:  Sharique Abdullah                                                   #
#                                                                              #
# Description: Test Cases of Dynamic System Variable max_sort_length           #
#              that checks behavior of this variable in the following ways     #
#              * Functionality based on different values                       #
#                                                                              #
# Reference:                                                                   #
#   http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html        #
#                                                                              #
################################################################################

#
# Setup
#

SET @start_value= @@global.max_sort_length;

SET @session_max_sort_length = @@Session.max_sort_length;


--disable_warnings
DROP TABLE IF EXISTS t;
--enable_warnings

#########################
#   Creating new table  #
#########################


--echo ** creating tables **
CREATE TABLE t
(
id INT AUTO_INCREMENT PRIMARY KEY,
c TEXT(30)
);

CREATE TABLE t1
(
id INT AUTO_INCREMENT PRIMARY KEY,
c BLOB(30)
);

CREATE TABLE t2
(
id INT AUTO_INCREMENT PRIMARY KEY,
c TEXT(30)
);



--echo '#--------------------FN_DYNVARS_098_01-------------------------#'
##########################################################
#    Test behavior of variable on new connection # 01    #
##########################################################


connect (test_con1,localhost,root,,);
connection test_con1;

# Value of session & global vairable here should be 10
SELECT @@global.max_sort_length = 10;
SELECT @@session.max_sort_length = 10;

# Setting global value of variable and inserting data in table
--echo ** Setting value to 30 and inserting data **
SET @@global.max_sort_length = 30;
SELECT @@global.max_sort_length;
INSERT INTO t set c = repeat('x',29);
INSERT INTO t set c = concat(repeat('x',28),'r','x');
INSERT INTO t set c = concat(repeat('x',28),'s','y');
INSERT INTO t set c = concat(repeat('x',28),'g','w');
SELECT c from t ORDER BY c, id;
--echo ** Results should be sorted **

# Setting session value of variable and inserting data in table
SET @@session.max_sort_length = 29;
SELECT @@session.max_sort_length;
INSERT INTO t set c = repeat('x',29);
INSERT INTO t set c = concat(repeat('x',28),'r','x');
INSERT INTO t set c = concat(repeat('x',28),'s','y');
INSERT INTO t set c = concat(repeat('x',28),'g','w');
SELECT c from t ORDER BY c, id;
--echo ** Results should be sorted **

--echo '#--------------------FN_DYNVARS_098_02-------------------------#'
##########################################################
#    Test behavior of variable on new connection # 02    #
##########################################################

connect (test_con2,localhost,root,,);
connection test_con2;


## Setting global value of variable and inserting data in table
SET @@global.max_sort_length = 30;
SELECT @@global.max_sort_length;
INSERT INTO t set c = repeat('x',29);
INSERT INTO t set c = concat(repeat('x',28),'r','x');
INSERT INTO t set c = concat(repeat('x',28),'s','y');
INSERT INTO t set c = concat(repeat('x',28),'g','w');
SELECT c from t ORDER BY c, id;

--echo ** Results should be sorted **

# Setting session value of variable and inserting data in table
SET @@session.max_sort_length = 20;
SELECT @@session.max_sort_length;
INSERT INTO t set c = repeat('x',29);
INSERT INTO t set c = concat(repeat('x',28),'r','x');
INSERT INTO t set c = concat(repeat('x',28),'s','y');
INSERT INTO t set c = concat(repeat('x',28),'g','w');
SELECT c from t ORDER BY c, id;

--echo ** Results should not be sorted **

--echo '#--------------------FN_DYNVARS_098_03-------------------------#'
#########################################################
#Check if sorting is applied with the max_sort_length=20#
#########################################################

###########################################
#   Setting new value for max_sort_length #
###########################################

SET max_sort_length=20;

###################################
#   Inserting values in  table t  #
###################################

INSERT INTO t set c = repeat('x',29);
INSERT INTO t set c = concat(repeat('x',28),'r','x');
INSERT INTO t set c = concat(repeat('x',28),'s','y');
INSERT INTO t set c = concat(repeat('x',28),'g','w');

SELECT c from t ORDER BY c, id;
--echo ** Results should not be sorted **

RESET QUERY CACHE;


--echo '#--------------------FN_DYNVARS_098_04-------------------------#'
#########################################################
#Check if sorting is applied with the max_sort_length=29#
#########################################################

SET max_sort_length=29;
SELECT c from t ORDER BY c, id;
--echo ** Results should be sorted **

--echo '#--------------------FN_DYNVARS_098_05-------------------------#'
#########################################################
#Check if sorting is applied with the max_sort_length=30#
#########################################################

SET max_sort_length=30;
SELECT c from t ORDER BY c, id;
--echo ** Results should be sorted **

--echo '#--------------------FN_DYNVARS_098_06-------------------------#'
##############################################################
#Check if sorting is applied with the max_sort_length=Default#
##############################################################


SET max_sort_length=default;
SELECT c from t ORDER BY c, id;
--echo ** Results should be sorted **


--echo '#--------------------FN_DYNVARS_098_07-------------------------#'
###########################################
#Check if sorting is applied on BLOB type #
###########################################
--echo Testing type BLOB
# Setting global value of variable and inserting data in table
SET @@global.max_sort_length = 30;
SELECT @@global.max_sort_length;
INSERT INTO t1 set c = repeat('x',29);
INSERT INTO t1 set c = concat(repeat('x',28),'r','x');
INSERT INTO t1 set c = concat(repeat('x',28),'s','y');
INSERT INTO t1 set c = concat(repeat('x',28),'g','w');
SELECT c from t1 ORDER BY c, id;
--echo ** Results should be sorted **

# Setting session value of variable and inserting data in table
SET @@session.max_sort_length = 20;
SELECT @@session.max_sort_length;
INSERT INTO t1 set c = repeat('x',29);
INSERT INTO t1 set c = concat(repeat('x',28),'r','x');
INSERT INTO t1 set c = concat(repeat('x',28),'s','y');
INSERT INTO t1 set c = concat(repeat('x',28),'g','w');
SELECT c from t1 ORDER BY c, id;
--echo ** Results should not be sorted **

--echo '#--------------------FN_DYNVARS_098_08-------------------------#'
###########################################
#Check if sorting is applied on CHAR type #
###########################################
--echo Testing type CHAR
# Setting global value of variable and inserting data in table
SET @@global.max_sort_length = 30;
SELECT @@global.max_sort_length;
INSERT INTO t2 set c = repeat('x',29);
INSERT INTO t2 set c = concat(repeat('x',28),'r','x');
INSERT INTO t2 set c = concat(repeat('x',28),'s','y');
INSERT INTO t2 set c = concat(repeat('x',28),'g','w');
SELECT c from t2 ORDER BY c, id;
--echo ** Results should not be sorted **

# Setting session value of variable and inserting data in table
SET @@session.max_sort_length = 20;
SELECT @@session.max_sort_length;
INSERT INTO t2 set c = repeat('x',29);
INSERT INTO t2 set c = concat(repeat('x',28),'r','x');
INSERT INTO t2 set c = concat(repeat('x',28),'s','y');
INSERT INTO t2 set c = concat(repeat('x',28),'g','w');
SELECT c from t2 ORDER BY c, id;
--echo ** Results should not be sorted **


#
# Cleanup
#

connection default;

disconnect test_con1;
disconnect test_con2;

SET @@SESSION.max_sort_length = @session_max_sort_length;

--disable_warnings
DROP TABLE IF EXISTS t;
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
--enable_warnings

SET @@global.max_sort_length= @start_value;