This file is indexed.

/usr/lib/mysql-testsuite/t/insert_select.test is in mysql-testsuite-5.6 5.6.16-1~exp1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#
# Problem with INSERT ... SELECT
#

--disable_warnings
drop table if exists t1,t2,t3;
--enable_warnings

create table t1 (bandID MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY, payoutID SMALLINT UNSIGNED NOT NULL);
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
create table t2 (payoutID SMALLINT UNSIGNED NOT NULL PRIMARY KEY);
insert into t2 (payoutID) SELECT DISTINCT payoutID FROM t1;
--error ER_DUP_ENTRY
insert into t2 (payoutID) SELECT payoutID+10 FROM t1;
insert ignore into t2 (payoutID) SELECT payoutID+10 FROM t1;
select * from t2;
drop table t1,t2;

#
# bug in bulk insert optimization
# test case by Fournier Jocelyn <joc@presence-pc.com>
#

CREATE TABLE `t1` (
  `numeropost` bigint(20) unsigned NOT NULL default '0',
  `icone` tinyint(4) unsigned NOT NULL default '0',
  `numreponse` bigint(20) unsigned NOT NULL auto_increment,
  `contenu` text NOT NULL,
  `pseudo` varchar(50) NOT NULL default '',
  `date` datetime NOT NULL default '0000-00-00 00:00:00',
  `ip` bigint(11) NOT NULL default '0',
  `signature` tinyint(1) unsigned NOT NULL default '0',
  PRIMARY KEY  (`numeropost`,`numreponse`)
  ,KEY `ip` (`ip`),
  KEY `date` (`date`),
  KEY `pseudo` (`pseudo`),
  KEY `numreponse` (`numreponse`)
) ENGINE=MyISAM;

CREATE TABLE `t2` (
  `numeropost` bigint(20) unsigned NOT NULL default '0',
  `icone` tinyint(4) unsigned NOT NULL default '0',
  `numreponse` bigint(20) unsigned NOT NULL auto_increment,
  `contenu` text NOT NULL,
  `pseudo` varchar(50) NOT NULL default '',
  `date` datetime NOT NULL default '0000-00-00 00:00:00',
  `ip` bigint(11) NOT NULL default '0',
  `signature` tinyint(1) unsigned NOT NULL default '0',
  PRIMARY KEY  (`numeropost`,`numreponse`),
  KEY `ip` (`ip`),
  KEY `date` (`date`),
  KEY `pseudo` (`pseudo`),
  KEY `numreponse` (`numreponse`)
) ENGINE=MyISAM;

INSERT INTO t2
(numeropost,icone,numreponse,contenu,pseudo,date,ip,signature) VALUES
(9,1,56,'test','joce','2001-07-25 13:50:53'
,3649052399,0);


INSERT INTO t1 (numeropost,icone,contenu,pseudo,date,signature,ip)
SELECT 1618,icone,contenu,pseudo,date,signature,ip FROM t2
WHERE numeropost=9 ORDER BY numreponse ASC;

show variables like '%bulk%';

INSERT INTO t1 (numeropost,icone,contenu,pseudo,date,signature,ip)
SELECT 1718,icone,contenu,pseudo,date,signature,ip FROM t2
WHERE numeropost=9 ORDER BY numreponse ASC;

DROP TABLE t1,t2;

#
# Test of insert ... select from same table
#

create table t1 (a int not null);
create table t2 (a int not null);
insert into t1 values (1);
insert into t1 values (a+2);
insert into t1 values (a+3);
insert into t1 values (4),(a+5);
insert into t1 select * from t1;
select * from t1;
insert into t1 select * from t1 as t2;
select * from t1;
insert into t2 select * from t1 as t2;
select * from t1;
insert into t1 select t2.a from t1,t2;
select * from t1;
--error 1066
insert into t1 select * from t1,t1;
drop table t1,t2;

#
# test replace ... select
#

create table t1 (a int not null primary key, b char(10));
create table t2 (a int not null, b char(10));
insert into t1 values (1,"t1:1"),(3,"t1:3");
insert into t2 values (2,"t2:2"), (3,"t2:3");
--error ER_DUP_ENTRY
insert into t1 select * from t2;
select * from t1;
# REPLACE .. SELECT is not yet supported by PS
replace into t1 select * from t2;
select * from t1;
drop table t1,t2;

#
# Test that caused uninitialized memory access in auto_increment_key update
#

CREATE TABLE t1 ( USID INTEGER UNSIGNED, ServerID TINYINT UNSIGNED, State ENUM ('unknown', 'Access-Granted', 'Session-Active', 'Session-Closed' ) NOT NULL DEFAULT 'unknown', SessionID CHAR(32), User CHAR(32) NOT NULL DEFAULT '<UNKNOWN>', NASAddr INTEGER UNSIGNED, NASPort INTEGER UNSIGNED, NASPortType INTEGER UNSIGNED, ConnectSpeed INTEGER UNSIGNED, CarrierType CHAR(32), CallingStationID CHAR(32), CalledStationID CHAR(32), AssignedAddr INTEGER UNSIGNED, SessionTime INTEGER UNSIGNED, PacketsIn INTEGER UNSIGNED, OctetsIn INTEGER UNSIGNED, PacketsOut INTEGER UNSIGNED, OctetsOut INTEGER UNSIGNED, TerminateCause INTEGER UNSIGNED, UnauthTime TINYINT UNSIGNED, AccessRequestTime DATETIME, AcctStartTime DATETIME, AcctLastTime DATETIME, LastModification TIMESTAMP NOT NULL);
CREATE TABLE t2 ( USID INTEGER UNSIGNED AUTO_INCREMENT, ServerID TINYINT UNSIGNED, State ENUM ('unknown', 'Access-Granted', 'Session-Active', 'Session-Closed' ) NOT NULL DEFAULT 'unknown', SessionID CHAR(32), User TEXT NOT NULL, NASAddr INTEGER UNSIGNED, NASPort INTEGER UNSIGNED, NASPortType INTEGER UNSIGNED, ConnectSpeed INTEGER UNSIGNED, CarrierType CHAR(32), CallingStationID CHAR(32), CalledStationID CHAR(32), AssignedAddr INTEGER UNSIGNED, SessionTime INTEGER UNSIGNED, PacketsIn INTEGER UNSIGNED, OctetsIn INTEGER UNSIGNED, PacketsOut INTEGER UNSIGNED, OctetsOut INTEGER UNSIGNED, TerminateCause INTEGER UNSIGNED, UnauthTime TINYINT UNSIGNED, AccessRequestTime DATETIME, AcctStartTime DATETIME, AcctLastTime DATETIME, LastModification TIMESTAMP NOT NULL, INDEX(USID,ServerID,NASAddr,SessionID), INDEX(AssignedAddr));
INSERT INTO t1 VALUES (39,42,'Access-Granted','46','491721000045',2130706433,17690,NULL,NULL,'Localnet','491721000045','49172200000',754974766,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'2003-07-18 00:11:21',NULL,NULL,20030718001121);
INSERT INTO t2 SELECT USID, ServerID, State, SessionID, User, NASAddr, NASPort, NASPortType, ConnectSpeed, CarrierType, CallingStationID, CalledStationID, AssignedAddr, SessionTime, PacketsIn, OctetsIn, PacketsOut, OctetsOut, TerminateCause, UnauthTime, AccessRequestTime, AcctStartTime, AcctLastTime, LastModification from t1 LIMIT 1;
drop table t1,t2;

#
# Another problem from Bug #2012
#

CREATE TABLE t1(
 Month date NOT NULL,
 Type tinyint(3) unsigned NOT NULL auto_increment,
 Field int(10) unsigned NOT NULL,
 Count int(10) unsigned NOT NULL,
 UNIQUE KEY Month (Month,Type,Field)
);
	  
insert into t1 Values
(20030901, 1, 1, 100),
(20030901, 1, 2, 100),
(20030901, 2, 1, 100),
(20030901, 2, 2, 100),
(20030901, 3, 1, 100);

select * from t1;
	  
Select null, Field, Count From t1 Where Month=20030901 and Type=2;
	  
create table t2(No int not null, Field int not null, Count int not null);
	  
insert into t2 Select null, Field, Count From t1 Where Month=20030901 and Type=2;
	  
select * from t2;

drop table t1, t2;

#
# BUG#6034 - Error code 124:  Wrong medium type
#
CREATE TABLE t1 (
  ID           int(11) NOT NULL auto_increment,
  NO           int(11) NOT NULL default '0',
  SEQ          int(11) NOT NULL default '0',
  PRIMARY KEY  (ID),
  KEY t1$NO    (SEQ,NO)
) ENGINE=MyISAM;
INSERT INTO t1 (SEQ, NO) SELECT "1" AS SEQ, IF(MAX(NO) IS NULL, 0, MAX(NO)) + 1 AS NO FROM t1 WHERE (SEQ = 1);
select SQL_BUFFER_RESULT * from t1 WHERE (SEQ = 1);
drop table t1;

#
# Bug#10886 - Have to restore default values after update ON DUPLICATE KEY
#
create table t1 (f1 int);
create table t2 (ff1 int unique, ff2 int default 1);
insert into t1 values (1),(1),(2);
insert into t2(ff1) select f1 from t1 on duplicate key update ff2=ff2+1;
select * from t2;
drop table t1, t2;
#
# BUGS #9728 - 'Decreased functionality in "on duplicate key update"' 
#      #8147 - 'a column proclaimed ambigous in INSERT ... SELECT .. ON
#      DUPLICATE'
#
create table t1 (a int unique);
create table t2 (a int, b int);
create table t3 (c int, d int);
insert into t1 values (1),(2);
insert into t2 values (1,2);
insert into t3 values (1,6),(3,7);
select * from t1;
insert into t1 select a from t2 on duplicate key update a= t1.a + t2.b;
select * from t1;
insert into t1 select a+1 from t2 on duplicate key update t1.a= t1.a + t2.b+1;
select * from t1;
insert into t1 select t3.c from t3 on duplicate key update a= a + t3.d;
select * from t1;
insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= a + 10;

#Some error cases
--error 1052
insert into t1 select t2.a from t2 on duplicate key update a= a + t2.b;
--error 1054
insert into t1 select t2.a from t2 on duplicate key update t2.a= a + t2.b;
--error 1054
insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= t1.a + t2.b;
drop table t1,t2,t3;

#
# Bug #12695 Item_func_isnull::update_used_tables() did not update 
#            const_item_cache
create table t1(f1 varchar(5) key);
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
select * from t1;
drop table t1;

#
# Bug #13392 values() fails with 'ambiguous' or returns NULL 
#            with ON DUPLICATE and SELECT
create table t1(x int, y int);
create table t2(x int, z int);
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(x);
--error 1054
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(z);
--error 1054
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(t2.x);
drop table t1,t2; 

#
# Bug #9676: INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big 
#             tables
#

#Note: not an exsaustive test : just a check of the code path.
CREATE TABLE t1 (a int PRIMARY KEY);
INSERT INTO t1 values (1), (2);

flush status;
INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1;
show status like 'Handler_read%';

DROP TABLE t1;

#
# Bug #29717 INSERT INTO SELECT inserts values even if SELECT statement itself returns empty
#

CREATE TABLE t1 (
    f1 int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
    f2 varchar(100) NOT NULL default ''
);
CREATE TABLE t2 (
    f1 varchar(10) NOT NULL default '',
    f2 char(3) NOT NULL default '',
    PRIMARY KEY  (`f1`),
    KEY `k1` (`f2`, `f1`)
);

INSERT INTO t1 values(NULL, '');
INSERT INTO `t2` VALUES ('486878','WDT'),('486910','WDT');
SELECT COUNT(*) FROM t1;

SELECT min(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1;

INSERT INTO t1 (f2)
  SELECT min(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1;

SELECT COUNT(*) FROM t1;
SELECT * FROM t1;
DROP TABLE t1, t2;

# End of 4.1 tests

#
# Bug #18080: INSERT ... SELECT ... JOIN results in ambiguous field list error
#
CREATE TABLE t1 (x int, y int);
CREATE TABLE t2 (z int, y int);
CREATE TABLE t3 (a int, b int);
INSERT INTO t3 (SELECT x, y FROM t1 JOIN t2 USING (y) WHERE z = 1);
DROP TABLE IF EXISTS t1,t2,t3;

#
# Bug #21774: Column count doesn't match value count at row x
#
CREATE DATABASE bug21774_1;
CREATE DATABASE bug21774_2;

CREATE TABLE bug21774_1.t1(id VARCHAR(10) NOT NULL,label VARCHAR(255));
CREATE TABLE bug21774_2.t1(id VARCHAR(10) NOT NULL,label VARCHAR(255));
CREATE TABLE bug21774_1.t2(id VARCHAR(10) NOT NULL,label VARCHAR(255));

INSERT INTO bug21774_2.t1 SELECT t1.* FROM bug21774_1.t1;

use bug21774_1;
INSERT INTO bug21774_2.t1 SELECT t1.* FROM t1;

DROP DATABASE bug21774_1;
DROP DATABASE bug21774_2;
USE test;

#
# Bug#19978: INSERT .. ON DUPLICATE erroneously reports some records were
#            updated.
#
create table t1(f1 int primary key, f2 int);
--enable_info
insert into t1 values (1,1);
insert into t1 values (1,1) on duplicate key update f2=1;
insert into t1 values (1,1) on duplicate key update f2=2;
--disable_info
select * from t1;
drop table t1;

#
# Bug#16630: wrong result, when INSERT t1 SELECT ... FROM t1 ON DUPLICATE
#
CREATE TABLE t1 (f1 INT, f2 INT );
CREATE TABLE t2  (f1 INT PRIMARY KEY, f2 INT);
INSERT INTO t1 VALUES (1,1),(2,2),(10,10);
INSERT INTO t2 (f1, f2) SELECT f1, f2 FROM t1;
INSERT INTO t2 (f1, f2)
  SELECT f1, f1 FROM t2 src WHERE f1 < 2
  ON DUPLICATE KEY UPDATE f1 = 100 + src.f1;
SELECT * FROM t2;
DROP TABLE t1, t2;

#
# Bug#44306: Assertion fail on duplicate key error in 'INSERT ... SELECT' 
# statements
#
CREATE TABLE t1 ( a INT KEY, b INT );
INSERT INTO t1 VALUES ( 0, 1 );
--error ER_DUP_ENTRY
INSERT INTO t1 ( b ) SELECT MAX( b ) FROM t1 WHERE b = 2;
DROP TABLE t1;

#
# Bug #26207: inserts don't work with shortened index
#
SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

CREATE TABLE t1 (c VARCHAR(30), INDEX ix_c (c(10)));
CREATE TABLE t2 (d VARCHAR(10)); 
INSERT INTO t1 (c) VALUES ('7_chars'), ('13_characters'); 

EXPLAIN
  SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters') FROM t1;

SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters') FROM t1;

INSERT INTO t2 (d) 
  SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters') FROM t1;

INSERT INTO t2 (d) 
  SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='7_chars') FROM t1;

INSERT INTO t2 (d)
  SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c IN (SELECT t1.c FROM t1)) 
  FROM t1;

SELECT * FROM t2;
DROP TABLE t1,t2;

#
# Bug #29095: incorrect pushing of LIMIT into the temporary
# table ignoring ORDER BY clause
#

CREATE TABLE t1 (
  id INT AUTO_INCREMENT PRIMARY KEY,
  prev_id INT,
  join_id INT DEFAULT 0);

INSERT INTO t1 (prev_id) VALUES (NULL), (1), (2);
SELECT * FROM t1;

CREATE TABLE t2 (join_id INT);
INSERT INTO t2 (join_id) VALUES (0);

INSERT INTO t1 (prev_id) SELECT id
  FROM t2 LEFT JOIN t1 ON t1.join_id = t2.join_id
  ORDER BY id DESC LIMIT 1;
SELECT * FROM t1;

DROP TABLE t1,t2;

--echo #
--echo # Bug#30384: Having SQL_BUFFER_RESULT option in the
--echo #            CREATE .. KEY(..) .. SELECT led to creating corrupted index.
--echo #
create table t1(f1 int);
insert into t1 values(1),(2),(3);
create table t2 (key(f1)) engine=myisam select sql_buffer_result f1 from t1;
check table t2 extended;
drop table t1,t2;
--echo ##################################################################

--echo #
--echo # Bug #46075: Assertion failed: 0, file .\protocol.cc, line 416
--echo #

CREATE TABLE t1(a INT);
# To force MyISAM temp. table in the following INSERT ... SELECT.
SET max_heap_table_size = 16384;
# To overflow the temp. table.
SET @old_myisam_data_pointer_size = @@myisam_data_pointer_size;
SET GLOBAL myisam_data_pointer_size = 2;

INSERT INTO t1 VALUES (1), (2), (3), (4), (5);

call mtr.add_suppression("mysqld.*: The table '.*#sql.*' is full");
--error ER_RECORD_FILE_FULL,ER_RECORD_FILE_FULL
INSERT IGNORE INTO t1 SELECT t1.a FROM t1,t1 t2,t1 t3,t1 t4,t1 t5,t1 t6,t1 t7;

# Cleanup
SET GLOBAL myisam_data_pointer_size = @old_myisam_data_pointer_size;
DROP TABLE t1;

--echo End of 5.0 tests