File: temptable_basic.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 (301 lines) | stat: -rw-r--r-- 6,655 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
--source include/have_debug.inc

#============
# Basic temptable tests
#============

# ---------------------------------------------------------------------
# Prepare
#

SET @@GLOBAL.internal_tmp_mem_storage_engine = TempTable;

CREATE TABLE t_int (c INT);
CREATE TABLE t_char (c CHAR(20));
CREATE TABLE t_varchar (c VARCHAR(20));
CREATE TABLE t_text (c TEXT);
CREATE TABLE t_blob (c BLOB);
CREATE TABLE t_json (c JSON);
CREATE TABLE t_point (c POINT);
CREATE TABLE t_geom (c GEOMETRY);

INSERT INTO t_int VALUES
	(1),
	(2),
	(2),
	(3),
	(4),
	(NULL);

INSERT INTO t_char VALUES
	('abcde'),
	('fghij'),
	('fghij'),
	('klmno  '),
	('stxyz'),
	(''),
	(NULL);

INSERT INTO t_varchar VALUES
	('abcde'),
	('fghij'),
	('fghij'),
	('klmno  '),
	('stxyz'),
	(''),
	(NULL);

INSERT INTO t_text VALUES
	('abcde'),
	('fghij'),
	('fghij'),
	('klmno  '),
	('stxyz'),
	(''),
	(NULL);

INSERT INTO t_blob VALUES
	('abcde'),
	('fghij'),
	('fghij'),
	('klmno  '),
	('stxyz'),
	(''),
	(NULL);

INSERT INTO t_json VALUES
	('{"k1": "value", "k2": [10, 20]}'),
	('["hot", "cold"]'),
	('["hot", "cold"]'),
	('["a", "b", 1]'),
	('{"key": "value"}'),
	(NULL);

INSERT INTO t_point VALUES
	(ST_PointFromText('POINT(10 10)')),
	(ST_PointFromText('POINT(50 10)')),
	(ST_PointFromText('POINT(50 10)')),
	(ST_PointFromText('POINT(-1 -2)')),
	(ST_PointFromText('POINT(10 50)')),
	(NULL);

INSERT INTO t_geom VALUES
	(ST_PointFromText('POINT(10 10)')),
	(ST_MultiPointFromText('MULTIPOINT(0 0,10 10,10 20,20 20)')),
	(ST_MultiPointFromText('MULTIPOINT(0 0,10 10,10 20,20 20)')),
	(ST_PolygonFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))')),
	(ST_LineFromText('LINESTRING(0 0,0 10,10 0)')),
	(NULL);

--skip_if_hypergraph  # Depends on the query plan.
SHOW STATUS LIKE 'Created_tmp_tables';
SHOW STATUS LIKE 'Created_tmp_disk_tables';

--echo # ---------------------------------------------------------------------
--echo # Scenario 1:
--echo #

--sorted_result
SELECT DISTINCT * FROM
    t_int AS t1,
    t_int AS t2;

--sorted_result
SELECT DISTINCT * FROM
    t_char AS t1,
    t_char AS t2;

--sorted_result
SELECT DISTINCT * FROM
    t_varchar AS t1,
    t_varchar AS t2;

--sorted_result
SELECT DISTINCT * FROM
    t_text AS t1,
    t_text AS t2;

--sorted_result
SELECT DISTINCT * FROM
    t_blob AS t1,
    t_blob AS t2;

--skip_if_hypergraph  # Different warnings.
--sorted_result
SELECT DISTINCT * FROM
    t_json AS t1,
    t_json AS t2;

--sorted_result
SELECT DISTINCT ST_AsText(t1.c),ST_AsText(t2.c) FROM
    t_point AS t1,
    t_point AS t2;

--sorted_result
SELECT DISTINCT ST_AsText(t1.c),ST_AsText(t2.c) FROM
    t_geom AS t1,
    t_geom AS t2;

--echo # ---------------------------------------------------------------------
--echo # Scenario 2:
--echo #

--sorted_result
SELECT c,COUNT(*) FROM t_int GROUP BY c;

--sorted_result
SELECT c,COUNT(*) FROM t_char GROUP BY c;

--sorted_result
SELECT c,COUNT(*) FROM t_varchar GROUP BY c;

--sorted_result
SELECT c,COUNT(*) FROM t_text GROUP BY c;

--sorted_result
SELECT c,COUNT(*) FROM t_blob GROUP BY c;

--sorted_result
--skip_if_hypergraph  # Throws a sort warning on JSON.
SELECT c,COUNT(*) FROM t_json GROUP BY c;

--sorted_result
SELECT ST_AsText(c),COUNT(*) FROM t_point GROUP BY c;

--sorted_result
SELECT ST_AsText(c),COUNT(*) FROM t_geom GROUP BY c;

--skip_if_hypergraph  # Depends on the query plan.
SHOW STATUS LIKE 'Created_tmp_tables';
SHOW STATUS LIKE 'Created_tmp_disk_tables';

# ---------------------------------------------------------------------
# Cleanup
#

DROP TABLE t_int;
DROP TABLE t_char;
DROP TABLE t_varchar;
DROP TABLE t_text;
DROP TABLE t_blob;
DROP TABLE t_json;
DROP TABLE t_point;
DROP TABLE t_geom;

# ---------------------------------------------------------------------
# Scenario 3
#

CREATE TABLE t_pk (
  pk INT NOT NULL,
  PRIMARY KEY (pk)
);

INSERT INTO t_pk VALUES
        (1),
	(2),
	(3);

SELECT COUNT(t_pk.pk) FROM t_pk
    WHERE 1 IN (SELECT 1 FROM t_pk AS SQ2_alias1
        WHERE 1 IN (SELECT 1 FROM t_pk AS C_SQ1_alias1)
    );

DROP TABLE t_pk;

# ---------------------------------------------------------------------
# Bug #29654465 SEGMENTATION FAULT WITH QUERY USING JSON_TABLE
#

CREATE TABLE t_json(json_col JSON);

INSERT INTO t_json VALUES (
    '[
        { "name":"John Johnson", "nickname": {"stringValue": "Johnny"}},
        { "name":"John Smith"}
     ]'),
     ('[
        { "name":"John Smith"},
        { "name":"John Johnson", "nickname": {"stringValue": "Johnny"}}
     ]');
SELECT attrs.* FROM t_json, JSON_TABLE(json_col, '$[*]' COLUMNS (nickname JSON PATH '$.nickname')) as attrs;

DROP TABLE t_json;

--echo #
--echo # Bug #30677984: UNINITIALISED VALUE ERROR WITH VALGRIND IN SQL_TMP_TABLE.CC
--echo #

CREATE TABLE t1 (
  pk INTEGER NOT NULL,
  f1 varchar(255)
);
INSERT INTO t1 VALUES (5,'N');

CREATE TABLE t2 (
  pk int,
  f2 varchar(10)
);
INSERT INTO t2 VALUES (5,'he');
INSERT INTO t2 VALUES (5,'l');

CREATE TABLE t3 (
  f2 varchar(10),
  f3 varchar(255)
);
INSERT INTO t3 VALUES ('L','2.0');

set optimizer_switch='block_nested_loop=off';

SELECT SUM(t3.f3)
FROM t1
  LEFT JOIN t2 ON t1.pk = t2.pk
  LEFT JOIN t3 ON t2.f2 = t3.f2
GROUP BY t1.f1;

set optimizer_switch=default;

DROP TABLE t1, t2, t3;

--echo #
--echo # Bug #31116036: TEMPTABLE WASTES 1MB FOR EACH CONNECTION IN THREAD CACHE
--echo #

# Start fresh, make sure that memory is low
truncate performance_schema.memory_summary_global_by_event_name;
select * from performance_schema.memory_summary_global_by_event_name where event_name like 'memory/temptable%';

# Trigger some work from a new session
--echo # conn1
connect (conn1, localhost, root,,);
show variables like '%tmp_mem_storage%';

# Check the memory consumption
select * from performance_schema.memory_summary_global_by_event_name where event_name like 'memory/temptable%';

# Switch back to default connection. Check consumption again.
connection default;
select * from performance_schema.memory_summary_global_by_event_name where event_name like 'memory/temptable%';

# Now, disconnect one session
disconnect conn1;
let $count_sessions=1;
--source include/wait_until_count_sessions.inc

# We expect that memory consumption is again low (as from fresh start)
connection default;
select * from performance_schema.memory_summary_global_by_event_name where event_name like 'memory/temptable%';

--echo #
--echo # Bug #31091089 TEMPTABLE: ASSERTION `P - M_MYSQL_BUF < M_LENGTH' FAILED.
--echo #

CREATE TABLE t1 (
  f1 CHAR(0) NOT NULL,
  f2 INT NOT NULL
);
INSERT INTO t1(f1, f2) VALUES('', 1);
SELECT AVG(f1) from t1 GROUP BY f2, f1;
DROP TABLE t1;

SET @@GLOBAL.internal_tmp_mem_storage_engine = default;