summaryrefslogtreecommitdiff
path: root/mysql-test/main/column_compression.test
blob: 52235b078115d8302b83a1ee296b443b7eb08965 (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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
--source include/have_innodb.inc
--source include/have_csv.inc

let $MYSQLD_DATADIR= `select @@datadir`;

SET column_compression_zlib_wrap=true;
let $typec= BLOB COMPRESSED;
let $typeu= BLOB;
--source column_compression.inc

let $typec= TEXT COMPRESSED;
let $typeu= TEXT;
--source column_compression.inc

let $typec= VARBINARY(10000) COMPRESSED;
let $typeu= VARBINARY(10000);
--source column_compression.inc

let $typec= VARCHAR(10000) COMPRESSED;
let $typeu= VARCHAR(10000);
--source column_compression.inc

let $typec= TEXT COMPRESSED CHARSET ucs2;
let $typeu= TEXT;
--source column_compression.inc

SET column_compression_zlib_wrap=DEFAULT;
let $typec= BLOB COMPRESSED;
let $typeu= BLOB;
--source column_compression.inc

--enable_prepare_warnings
--error ER_PARSE_ERROR
CREATE TABLE t1(a CHAR(100) COMPRESSED);
--error ER_WRONG_FIELD_SPEC
CREATE TABLE t1(a CHAR(100) NOT NULL COMPRESSED);
--error ER_PARSE_ERROR
CREATE TABLE t1(a INT COMPRESSED);
--error ER_UNKNOWN_COMPRESSION_METHOD
CREATE TABLE t1(a BLOB COMPRESSED=unknown);
--error ER_PARSE_ERROR
CREATE TABLE t1(a BLOB COMPRESSED COMPRESSED);
CREATE TABLE t1(a INT);
--error ER_PARSE_ERROR
ALTER TABLE t1 MODIFY a INT COMPRESSED;
--error ER_WRONG_FIELD_SPEC
ALTER TABLE t1 MODIFY a INT NOT NULL COMPRESSED;
DROP TABLE t1;

--echo # Test CSV
CREATE TABLE t1(a BLOB COMPRESSED NOT NULL) ENGINE=CSV;
INSERT INTO t1 VALUES(REPEAT('a', 110));
SELECT LENGTH(a) FROM t1;
ALTER TABLE t1 ENGINE=MyISAM;
SELECT LENGTH(a) FROM t1;
ALTER TABLE t1 ENGINE=CSV;
SELECT LENGTH(a) FROM t1;
SHOW CREATE TABLE t1;
--cat_file $MYSQLD_DATADIR/test/t1.CSV
DROP TABLE t1;

--echo # Test fields that don't fit data
CREATE TABLE t1(a VARCHAR(9) COMPRESSED);
--error ER_DATA_TOO_LONG
INSERT INTO t1 VALUES(REPEAT('a', 10));
INSERT INTO t1 VALUES(REPEAT(' ', 10));
SELECT a, LENGTH(a) FROM t1;
DROP TABLE t1;

CREATE TABLE t1(a TINYTEXT COMPRESSED);
SET column_compression_threshold=300;
INSERT INTO t1 VALUES(REPEAT('a', 254));
INSERT INTO t1 VALUES(REPEAT(' ', 254));
--error ER_DATA_TOO_LONG
INSERT INTO t1 VALUES(REPEAT('a', 255));
INSERT INTO t1 VALUES(REPEAT(' ', 255));
--error ER_DATA_TOO_LONG
INSERT INTO t1 VALUES(REPEAT('a', 256));
INSERT INTO t1 VALUES(REPEAT(' ', 256));
--error ER_DATA_TOO_LONG
INSERT INTO t1 VALUES(REPEAT('a', 257));
INSERT INTO t1 VALUES(REPEAT(' ', 257));
SET column_compression_threshold=DEFAULT;
SELECT LEFT(a, 10), LENGTH(a) FROM t1 ORDER BY 1;
DROP TABLE t1;

--echo # Corner case: VARCHAR(255) COMPRESSED must have 2 bytes pack length
CREATE TABLE t1(a VARCHAR(255) COMPRESSED);
SHOW CREATE TABLE t1;
SET column_compression_threshold=300;
INSERT INTO t1 VALUES(REPEAT('a', 255));
SET column_compression_threshold=DEFAULT;
SELECT a, LENGTH(a) FROM t1;
DROP TABLE t1;

CREATE TABLE t1(a VARCHAR(65531) COMPRESSED);
SET column_compression_threshold=65537;
INSERT INTO t1 VALUES(REPEAT('a', 65530));
INSERT INTO t1 VALUES(REPEAT(' ', 65530));
INSERT INTO t1 VALUES(REPEAT('a', 65531));
INSERT INTO t1 VALUES(REPEAT(' ', 65531));
--error ER_DATA_TOO_LONG
INSERT INTO t1 VALUES(REPEAT('a', 65532));
INSERT INTO t1 VALUES(REPEAT(' ', 65532));
--error ER_DATA_TOO_LONG
INSERT INTO t1 VALUES(REPEAT('a', 65533));
INSERT INTO t1 VALUES(REPEAT(' ', 65533));
SET column_compression_threshold=DEFAULT;
SELECT LEFT(a, 10), LENGTH(a) FROM t1 ORDER BY 1, 2;
DROP TABLE t1;


--echo #
--echo # MDEV-14929 - AddressSanitizer: memcpy-param-overlap in
--echo #              Field_longstr::compress
--echo #
CREATE TABLE t1(b BLOB COMPRESSED);
INSERT INTO t1 VALUES('foo'),('bar');
SET SESSION optimizer_switch = 'derived_merge=off';
SELECT * FROM ( SELECT * FROM t1 ) AS sq ORDER BY b;
SET SESSION optimizer_switch=DEFAULT;
DROP TABLE t1;


--echo #
--echo # MDEV-15762 - VARCHAR(0) COMPRESSED crashes the server
--echo #
CREATE TABLE t1(a VARCHAR(0) COMPRESSED);
--error ER_DATA_TOO_LONG
INSERT INTO t1 VALUES('a');
INSERT INTO t1 VALUES(' ');
SELECT LENGTH(a) FROM t1;
DROP TABLE t1;


--echo #
--echo # MDEV-15763 - VARCHAR(1) COMPRESSED crashes the server
--echo #
CREATE TABLE t1(a VARCHAR(1) COMPRESSED);
SET column_compression_threshold=0;
INSERT INTO t1 VALUES('a');
SET column_compression_threshold=DEFAULT;
DROP TABLE t1;


--echo #
--echo # MDEV-15938 - TINYTEXT CHARACTER SET utf8 COMPRESSED truncates data
--echo #
CREATE TABLE t1(a TINYTEXT COMPRESSED, b TINYTEXT) CHARACTER SET utf8;
INSERT INTO t1 VALUES (REPEAT(_latin1'a', 254), REPEAT(_latin1'a', 254));
SELECT CHAR_LENGTH(a), CHAR_LENGTH(b), LEFT(a, 10), LEFT(b, 10) FROM t1;
DROP TABLE t1;


--echo #
--echo # MDEV-16134 Wrong I_S.COLUMNS.CHARACTER_XXX_LENGTH value for compressed columns
--echo #

CREATE TABLE t1
(
  a VARCHAR(10) COMPRESSED CHARACTER SET latin1,
  b VARCHAR(10) COMPRESSED CHARACTER SET utf8
);
SELECT COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1' AND COLUMN_NAME IN ('a','b')
ORDER BY COLUMN_NAME;
DROP TABLE t1;


--echo #
--echo # MDEV-15592 - Column COMPRESSED should select a 'high order' datatype
--echo #
CREATE TABLE t1(a TINYTEXT COMPRESSED);
INSERT INTO t1 VALUES(REPEAT('a', 255));
SELECT LEFT(a, 10), LENGTH(a) FROM t1;
DROP TABLE t1;


--echo #
--echo # MDEV-16729 VARCHAR COMPRESSED is created with a wrong length for multi-byte character sets
--echo #

CREATE OR REPLACE TABLE t1 (a VARCHAR(1000) COMPRESSED CHARACTER SET utf8);
SHOW CREATE TABLE t1;
SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1';
DROP TABLE t1;


--echo #
--echo # MDEV-17363 - Compressed columns cannot be restored from dump
--echo #
--error ER_WRONG_FIELD_SPEC
CREATE TABLE t1(a INT NOT NULL COMPRESSED);
SHOW WARNINGS;

CREATE TABLE t1(
  a JSON COMPRESSED,
  b VARCHAR(1000) COMPRESSED BINARY,
  c NVARCHAR(1000) COMPRESSED BINARY,
  d TINYTEXT COMPRESSED BINARY
);
SHOW CREATE TABLE t1;
DROP TABLE t1;


--echo #
--echo # VARCHAR and TEXT variants
--echo #

--let type=VARCHAR(10)
--source include/column_compression_syntax_varchar.inc

--let type=TINYTEXT
--source include/column_compression_syntax_varchar.inc

--let type=TEXT
--source include/column_compression_syntax_varchar.inc

--let type=MEDIUMTEXT
--source include/column_compression_syntax_varchar.inc

--let type=LONGTEXT
--source include/column_compression_syntax_varchar.inc


--echo #
--echo # VARBINARY and BLOB variables
--echo #

--let type=VARCHAR(10)
--source include/column_compression_syntax_varbinary.inc

--let type=TINYBLOB
--source include/column_compression_syntax_varbinary.inc

--let type=BLOB
--source include/column_compression_syntax_varbinary.inc

--let type=MEDIUMBLOB
--source include/column_compression_syntax_varbinary.inc

--let type=LONGBLOB
--source include/column_compression_syntax_varbinary.inc


--echo #
--echo # NVARCHAR
--echo #

CREATE TABLE t1 (a NVARCHAR(10) COMPRESSED);
SHOW CREATE TABLE t1;
DROP TABLE t1;
--error ER_PARSE_ERROR
CREATE TABLE t1 (a NVARCHAR(10) COMPRESSED BINARY COMPRESSED);
--error ER_PARSE_ERROR
CREATE TABLE t1 (a NVARCHAR(10) COMPRESSED DEFAULT '' COMPRESSED);

--echo #
--echo # MDEV-21348 - Memory leak in Storage-Engine Independent Column
--echo #              Compression
--echo #
CREATE TABLE t1(a BLOB COMPRESSED);
SET column_compression_threshold=0;
INSERT INTO t1 VALUES('aa');
SET column_compression_threshold=DEFAULT;
DROP TABLE t1;

--echo #
--echo # End of 10.3 tests
--echo #


--echo #
--echo # Start of 10.5 tests
--echo #

--echo #
--echo # MDEV-19727 Add Type_handler::Key_part_spec_init_ft
--echo #

#
# Indexes on COMPRESSED columns are generally prohibited, so we don't have
# to override Type_handler_xxx_compressed::Key_part_spec_init_ft().
# Note, we could support FULLTEXT indexes on compressed columns eventually.
#

--error ER_COMPRESSED_COLUMN_USED_AS_KEY
CREATE TABLE t1 (a VARCHAR(1000) COMPRESSED, FULLTEXT INDEX(a));

--error ER_COMPRESSED_COLUMN_USED_AS_KEY
CREATE TABLE t1 (a TEXT COMPRESSED, FULLTEXT INDEX(a));

--disable_prepare_warnings
--echo #
--echo # End of 10.5 tests
--echo #