File: temporary_table_optimization.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (287 lines) | stat: -rw-r--r-- 8,341 bytes parent folder | download
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
#
# WL#6469: Optimizing CREATE/DROP performance for temporary tables
#
--source include/no_valgrind_without_big.inc

#########################################################################
#									#
# Will test following scenarios:					#
# 1. Create/Drop of temp-table. (with and w/o explicit pk)		#
# 2. Truncate temp-table (result in table drop and recreate).		#
# 3. Alter of temp-table.						#
# 4. Import/Discard of temp-table (to check blocked action)		#
# 5. Renaming of temp-table						#
# 6. Creating temp-table with large prefix.				#
# 7. Check Temp table info not stored in I_S datafile and tables	#
#########################################################################


#-------------------------------------------------------------
#
# 1. Create/Drop of temp-table. (with and w/o explicit pk)		#
#
create temporary table t1 (i int) engine = innodb;
show create table information_schema.innodb_temp_table_info;
select count(*) from information_schema.innodb_temp_table_info;
insert into t1 values (1), (2), (3), (4);
select * from t1;
select * from t1 where i = 4;
drop table t1;
#
# recreate table wih same name to ensure entries are removed.
create temporary table t1 (i int) engine = innodb;
select count(*) from information_schema.innodb_temp_table_info;
insert into t1 values (1), (2), (3), (4);
select * from t1;
select * from t1 where i = 4;
drop table t1;
#
create temporary table t2 (i int) engine = innodb;
insert into t2 values (1), (2), (3), (4);
select * from t2;
select * from t2 where i = 4;
select count(*) from information_schema.innodb_temp_table_info;
drop table t2;
#
create temporary table t1 (i int, primary key pk(i)) engine = innodb;
create temporary table t2 (i int, primary key pk(i)) engine = innodb;
create temporary table t3 (i int, primary key pk(i)) engine = innodb;
insert into t1 values (1), (2), (3), (4);
insert into t2 values (1), (2), (3), (4);
insert into t3 values (1), (2), (3), (4);
select * from t1;
select * from t1 where i = 4;
select count(*) from information_schema.innodb_temp_table_info;
drop table t1;
select count(*) from information_schema.innodb_temp_table_info;
drop table t2;
select count(*) from information_schema.innodb_temp_table_info;
drop table t3;

#-------------------------------------------------------------
#
# 2. Truncate temp-table (result in table drop and recreate).		#
#
create temporary table t1
	(keyc int, c1 char(100), c2 char(100),
	 primary key(keyc)) engine = innodb;
delimiter |;
create procedure populate_t1()
begin
	declare i int default 1;
	while (i <= 200) DO
		insert into t1 values (i, 'a', 'b');
		set i = i + 1;
	end while;
end|
delimiter ;|
set autocommit=0;
select * from t1;
call populate_t1();
select count(*) from t1;
select * from t1 limit 10;
set autocommit=1;
truncate table t1;
select * from t1;
drop table t1;
#
# recreate table wih same name to ensure entries are removed.
create temporary table t1 (i int) engine = innodb;
insert into t1 values (1), (2), (3), (4);
select * from t1;
select * from t1 where i = 4;
drop table t1;
#
create temporary table t1
	(keyc int, c1 char(100), c2 char(100),
	 primary key(keyc))
	engine = innodb;
begin;
select * from t1;
call populate_t1();
select count(*) from t1;
rollback;
select * from t1;
begin;
call populate_t1();
commit;
select count(*) from t1;
truncate table t1;
select * from t1;
drop table t1;
#
drop procedure populate_t1;


#-------------------------------------------------------------
#
# 3. Alter of temp-table.
#
create temporary table t1 (t1_i int, t1_f float) engine = innodb;
insert into t1 values (1, 1.1), (2, 2.2), (3, 2.2), (4, 4.4);
#
explain select * from t1 where t1_i = 1;
alter table t1 add unique index pri_index(t1_i);
explain select * from t1 where t1_i = 1;
select * from t1 where t1_i = 1;
#
--error ER_DUP_ENTRY
alter table t1 add unique index sec_index(t1_f);
alter table t1 add index sec_index(t1_f);
explain select * from t1 where t1_f > 2.2;
select * from t1 where t1_f > 2.2;
#
alter table t1 add column (t1_c char(10));
select * from t1;
insert into t1 values (5, 5.5, 'krunal');
#
alter table t1 drop column t1_f;
show create table t1;
--error ER_BAD_FIELD_ERROR
select * from t1 where t1_f > 2.2;
#
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter table t1 add index sec_index2(t1_c), algorithm=inplace;
select count(*) from information_schema.innodb_temp_table_info;
#
drop table t1;

#-------------------------------------------------------------
#
# 4. Import/Discard of temp-table (to check blocked action)
#
create temporary table t1 (i int, f float) engine = innodb;
insert into t1 values (10, 1.1), (20, 2.2);
select * from t1;
#
--error ER_CANNOT_DISCARD_TEMPORARY_TABLE
alter table t1 discard tablespace;
--error ER_CANNOT_DISCARD_TEMPORARY_TABLE
alter table t1 import tablespace;
drop table t1;

#-------------------------------------------------------------
#
# 5. Renaming of temp-table						#
#
create temporary table t1 (i int) engine=innodb;
insert into t1 values (1), (2), (3);
select * from t1;
#
alter table t1 rename t2;
--error ER_NO_SUCH_TABLE
select * from t1;
select * from t2;
insert into t2 values (1), (2), (6), (7);
select * from t2;
drop table t2;


#-------------------------------------------------------------
#
# 6. Creating temp-table with large prefix.				#
#

SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
# This will lead to warnings on innodb_page_size=8k or 4k:
# 8k: Specified key was too long; max key length is 1536 bytes
# 4k: Specified key was too long; max key length is 768 bytes
--disable_warnings
#
create temporary table t (
	a int not null,
	b blob not null,
	index sk (b(3021))
	) row_format = dynamic engine=innodb;
drop table t;
#
create temporary table t (
	a int not null,
	b blob not null,
	index sk (b(3021))
	) row_format = dynamic engine=innodb;
drop table t;
#
create temporary table t (
	a int not null,
	b blob not null,
	index sk (b(3021))
	) row_format = dynamic engine=innodb;
drop table t;
#
# Enabling the default 'strict' mode since as part of fix for bug#26848813, an
# error is reported when index> 767 bytes and in non-strict mode only a warning
# is reported
SET sql_mode = 'NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES';
SET innodb_strict_mode=OFF;
--error ER_TOO_LONG_KEY
create temporary table t (
	a int not null,
	b blob not null,
	index sk (b(3021))
	) row_format = compact engine=innodb;

SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
#
create temporary table t (
	a int not null,
	b blob not null,
	index sk (b(3021))
	) row_format = dynamic engine=innodb;
drop table t;
#
create temporary table t (
	a int not null,
	b blob not null,
	index sk (b(3021))
	) row_format = compressed engine=innodb;
drop table t;
#
#
# Enabling the default 'strict' mode since as part of fix for bug#26848813, an
# error is reported when index> 767 bytes and in non-strict mode only a warning
# is reported
SET sql_mode = 'NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES';
--error ER_TOO_LONG_KEY
create temporary table t (
	a int not null,
	b blob not null,
	index sk (b(3021))
	) row_format = compact engine=innodb;
#
SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
create temporary table t (
	a int not null,
	b blob not null,
	index sk (b(3021))
	) row_format = dynamic engine=innodb;
drop table t;
--enable_warnings
#

#-------------------------------------------------------------
#
# 7. Temp table info not stored in I_S
#
--disable_warnings
DROP TABLE IF EXISTS t1,t2,t3;
--enable_warnings

CREATE TABLE t6469_1 ( i INT ) ENGINE = Innodb;
CREATE TEMPORARY TABLE t6469_2 ( i INT ) ENGINE = Innodb;
CREATE TEMPORARY table t6469_3 ( i INT ) ENGINE = Innodb ROW_FORMAT=compressed;
SELECT count(*) FROM information_schema.files WHERE file_name LIKE '%t6469%';
SELECT count(*) FROM information_schema.INNODB_DATAFILES WHERE PATH LIKE '%t6469%';
SELECT count(*) FROM information_schema.INNODB_TABLES WHERE NAME LIKE '%t6469%';

DROP TABLE t6469_1,t6469_2,t6469_3;
SELECT * FROM information_schema.files WHERE file_name LIKE '%t6469%';
SELECT * FROM information_schema.INNODB_DATAFILES WHERE PATH LIKE '%t6469%';
SELECT TABLE_ID, NAME, FLAG, N_COLS, SPACE, ROW_FORMAT, ZIP_PAGE_SIZE, SPACE_TYPE,
INSTANT_COLS, TOTAL_ROW_VERSIONS FROM information_schema.INNODB_TABLES WHERE NAME LIKE '%t6469%';

#-------------------------------------------------------------
#
# remove test-bed.
#
SET sql_mode=default;