~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Problem with INSERT ... SELECT
3
#
4
5
--disable_warnings
6
drop table if exists t1,t2,t3;
7
--enable_warnings
8
520.1.16 by Brian Aker
More test updates (one ulong fix)
9
create table t1 (bandID INT NOT NULL PRIMARY KEY, payoutID int NOT NULL);
1 by brian
clean slate
10
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
11
create table t2 (payoutID int NOT NULL PRIMARY KEY);
1 by brian
clean slate
12
insert into t2 (payoutID) SELECT DISTINCT payoutID FROM t1;
13
--error ER_DUP_ENTRY
14
insert into t2 (payoutID) SELECT payoutID+10 FROM t1;
15
insert ignore into t2 (payoutID) SELECT payoutID+10 FROM t1;
16
select * from t2;
17
drop table t1,t2;
18
19
#
20
# bug in bulk insert optimization
21
# test case by Fournier Jocelyn <joc@presence-pc.com>
22
#
23
1063.9.6 by Stewart Smith
insert_select test for MyISAM as temp table only: 1 open table twice, 3x can be myisam temp.
24
CREATE TEMPORARY TABLE `t1` (
520.1.16 by Brian Aker
More test updates (one ulong fix)
25
  `numeropost` bigint NOT NULL default '0',
26
  `icone` int NOT NULL default '0',
27
  `numreponse` bigint NOT NULL auto_increment,
1 by brian
clean slate
28
  `contenu` text NOT NULL,
29
  `pseudo` varchar(50) NOT NULL default '',
873.1.2 by Jay Pipes
Fixed Field_datetime to never accept any bad datetimes as a string. This broke
30
  `date` datetime,
520.1.16 by Brian Aker
More test updates (one ulong fix)
31
  `ip` bigint NOT NULL default '0',
32
  `signature` int NOT NULL default '0',
1 by brian
clean slate
33
  PRIMARY KEY  (`numeropost`,`numreponse`)
34
  ,KEY `ip` (`ip`),
35
  KEY `date` (`date`),
36
  KEY `pseudo` (`pseudo`),
37
  KEY `numreponse` (`numreponse`)
38
) ENGINE=MyISAM;
39
1063.9.6 by Stewart Smith
insert_select test for MyISAM as temp table only: 1 open table twice, 3x can be myisam temp.
40
CREATE TEMPORARY TABLE `t2` (
520.1.16 by Brian Aker
More test updates (one ulong fix)
41
  `numeropost` bigint NOT NULL default '0',
42
  `icone` int NOT NULL default '0',
43
  `numreponse` bigint NOT NULL auto_increment,
1 by brian
clean slate
44
  `contenu` text NOT NULL,
45
  `pseudo` varchar(50) NOT NULL default '',
873.1.2 by Jay Pipes
Fixed Field_datetime to never accept any bad datetimes as a string. This broke
46
  `date` datetime,
520.1.16 by Brian Aker
More test updates (one ulong fix)
47
  `ip` bigint NOT NULL default '0',
48
  `signature` int NOT NULL default '0',
1 by brian
clean slate
49
  PRIMARY KEY  (`numeropost`,`numreponse`),
50
  KEY `ip` (`ip`),
51
  KEY `date` (`date`),
52
  KEY `pseudo` (`pseudo`),
53
  KEY `numreponse` (`numreponse`)
54
) ENGINE=MyISAM;
55
56
INSERT INTO t2
57
(numeropost,icone,numreponse,contenu,pseudo,date,ip,signature) VALUES
58
(9,1,56,'test','joce','2001-07-25 13:50:53'
59
,3649052399,0);
60
61
62
INSERT INTO t1 (numeropost,icone,contenu,pseudo,date,signature,ip)
63
SELECT 1618,icone,contenu,pseudo,date,signature,ip FROM t2
64
WHERE numeropost=9 ORDER BY numreponse ASC;
65
66
show variables like '%bulk%';
67
68
INSERT INTO t1 (numeropost,icone,contenu,pseudo,date,signature,ip)
69
SELECT 1718,icone,contenu,pseudo,date,signature,ip FROM t2
70
WHERE numeropost=9 ORDER BY numreponse ASC;
71
72
DROP TABLE t1,t2;
73
74
#
75
# Test of insert ... select from same table
76
#
77
78
create table t1 (a int not null);
79
create table t2 (a int not null);
80
insert into t1 values (1);
81
insert into t1 values (a+2);
82
insert into t1 values (a+3);
83
insert into t1 values (4),(a+5);
84
insert into t1 select * from t1;
85
select * from t1;
86
insert into t1 select * from t1 as t2;
87
select * from t1;
88
insert into t2 select * from t1 as t2;
89
select * from t1;
2141.4.2 by Andrew Hutchings
Implicit joins of the form "SELECT * FROM t1, t2" without WHERE or ON now error.
90
insert into t1 select t2.a from t1,t2 where t1.a > 0;
1 by brian
clean slate
91
select * from t1;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
92
--error ER_NONUNIQ_TABLE
1 by brian
clean slate
93
insert into t1 select * from t1,t1;
94
drop table t1,t2;
95
96
#
97
# test replace ... select
98
#
99
100
create table t1 (a int not null primary key, b char(10));
101
create table t2 (a int not null, b char(10));
102
insert into t1 values (1,"t1:1"),(3,"t1:3");
103
insert into t2 values (2,"t2:2"), (3,"t2:3");
104
--error ER_DUP_ENTRY
105
insert into t1 select * from t2;
106
select * from t1;
107
# REPLACE .. SELECT is not yet supported by PS
108
replace into t1 select * from t2;
109
select * from t1;
110
drop table t1,t2;
111
112
#
113
# Test that caused uninitialized memory access in auto_increment_key update
114
#
115
520.1.16 by Brian Aker
More test updates (one ulong fix)
116
CREATE TABLE t1 ( USID INTEGER, ServerID int, 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, NASPort INTEGER, NASPortType INTEGER, ConnectSpeed INTEGER, CarrierType CHAR(32), CallingStationID CHAR(32), CalledStationID CHAR(32), AssignedAddr INTEGER, SessionTime INTEGER, PacketsIn INTEGER, OctetsIn INTEGER, PacketsOut INTEGER, OctetsOut INTEGER, TerminateCause INTEGER, UnauthTime int, AccessRequestTime DATETIME, AcctStartTime DATETIME, AcctLastTime DATETIME, LastModification TIMESTAMP NOT NULL);
117
CREATE TABLE t2 ( USID INTEGER AUTO_INCREMENT, ServerID int, State ENUM ('unknown', 'Access-Granted', 'Session-Active', 'Session-Closed' ) NOT NULL DEFAULT 'unknown', SessionID CHAR(32), User TEXT NOT NULL, NASAddr INTEGER, NASPort INTEGER, NASPortType INTEGER, ConnectSpeed INTEGER, CarrierType CHAR(32), CallingStationID CHAR(32), CalledStationID CHAR(32), AssignedAddr INTEGER, SessionTime INTEGER, PacketsIn INTEGER, OctetsIn INTEGER, PacketsOut INTEGER, OctetsOut INTEGER, TerminateCause INTEGER, UnauthTime int, AccessRequestTime DATETIME, AcctStartTime DATETIME, AcctLastTime DATETIME, LastModification TIMESTAMP NOT NULL, INDEX(USID,ServerID,NASAddr,SessionID), INDEX(AssignedAddr));
1 by brian
clean slate
118
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);
119
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;
120
drop table t1,t2;
121
122
#
123
# Another problem from Bug #2012
124
#
125
126
CREATE TABLE t1(
127
 Month date NOT NULL,
520.1.16 by Brian Aker
More test updates (one ulong fix)
128
 Type int NOT NULL auto_increment,
129
 Field int NOT NULL,
130
 Count int NOT NULL,
131
 PRIMARY KEY (Type),
1 by brian
clean slate
132
 UNIQUE KEY Month (Month,Type,Field)
133
);
134
	  
520.1.16 by Brian Aker
More test updates (one ulong fix)
135
insert into t1 Values (20030901, 1, 1, 100);
136
insert into t1 Values (20030901, 2, 2, 100);
137
insert into t1 Values (20030901, 3, 3, 100);
138
insert into t1 Values (20030901, 4, 4, 100);
139
insert into t1 Values (20030901, 5, 5, 100);
1 by brian
clean slate
140
141
select * from t1;
142
	  
143
Select null, Field, Count From t1 Where Month=20030901 and Type=2;
144
	  
145
create table t2(No int not null, Field int not null, Count int not null);
146
	  
147
insert into t2 Select 0, Field, Count From t1 Where Month=20030901 and Type=2;
148
	  
149
select * from t2;
150
151
drop table t1, t2;
152
153
#
154
# BUG#6034 - Error code 124:  Wrong medium type
155
#
156
CREATE TABLE t1 (
520.1.16 by Brian Aker
More test updates (one ulong fix)
157
  ID           int NOT NULL auto_increment,
158
  NO           int NOT NULL default '0',
159
  SEQ          int NOT NULL default '0',
1 by brian
clean slate
160
  PRIMARY KEY  (ID),
161
  KEY t1$NO    (SEQ,NO)
1063.9.6 by Stewart Smith
insert_select test for MyISAM as temp table only: 1 open table twice, 3x can be myisam temp.
162
);
1 by brian
clean slate
163
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);
164
select SQL_BUFFER_RESULT * from t1 WHERE (SEQ = 1);
165
drop table t1;
166
167
#
168
# Bug#10886 - Have to restore default values after update ON DUPLICATE KEY
169
#
170
create table t1 (f1 int);
171
create table t2 (ff1 int unique, ff2 int default 1);
172
insert into t1 values (1),(1),(2);
173
insert into t2(ff1) select f1 from t1 on duplicate key update ff2=ff2+1;
174
select * from t2;
175
drop table t1, t2;
176
#
177
# BUGS #9728 - 'Decreased functionality in "on duplicate key update"' 
178
#      #8147 - 'a column proclaimed ambigous in INSERT ... SELECT .. ON
179
#      DUPLICATE'
180
#
181
create table t1 (a int unique);
182
create table t2 (a int, b int);
183
create table t3 (c int, d int);
184
insert into t1 values (1),(2);
185
insert into t2 values (1,2);
186
insert into t3 values (1,6),(3,7);
187
select * from t1;
188
insert into t1 select a from t2 on duplicate key update a= t1.a + t2.b;
189
select * from t1;
190
insert into t1 select a+1 from t2 on duplicate key update t1.a= t1.a + t2.b+1;
191
select * from t1;
192
insert into t1 select t3.c from t3 on duplicate key update a= a + t3.d;
193
select * from t1;
194
insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= a + 10;
195
196
#Some error cases
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
197
--error ER_NON_UNIQ_ERROR
1 by brian
clean slate
198
insert into t1 select t2.a from t2 on duplicate key update a= a + t2.b;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
199
--error ER_BAD_FIELD_ERROR
1 by brian
clean slate
200
insert into t1 select t2.a from t2 on duplicate key update t2.a= a + t2.b;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
201
--error ER_BAD_FIELD_ERROR
1 by brian
clean slate
202
insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= t1.a + t2.b;
203
drop table t1,t2,t3;
204
205
#
206
# Bug #12695 Item_func_isnull::update_used_tables() did not update 
207
#            const_item_cache
208
create table t1(f1 varchar(5) key);
209
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
210
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
211
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
212
select * from t1;
213
drop table t1;
214
215
#
216
# Bug #13392 values() fails with 'ambiguous' or returns NULL 
217
#            with ON DUPLICATE and SELECT
218
create table t1(x int, y int);
219
create table t2(x int, z int);
220
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(x);
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
221
--error ER_BAD_FIELD_ERROR
1 by brian
clean slate
222
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(z);
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
223
--error ER_BAD_FIELD_ERROR
1 by brian
clean slate
224
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(t2.x);
225
drop table t1,t2; 
226
227
#
228
# Bug #9676: INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big 
229
#             tables
230
#
231
232
#Note: not an exsaustive test : just a check of the code path.
233
CREATE TABLE t1 (a int PRIMARY KEY);
234
INSERT INTO t1 values (1), (2);
235
236
flush status;
237
INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1;
1273.16.1 by Brian Aker
More removal of show code.
238
--replace_column 2 #
1 by brian
clean slate
239
show status like 'Handler_read%';
240
241
DROP TABLE t1;
242
243
#
244
# Bug #29717 INSERT INTO SELECT inserts values even if SELECT statement itself returns empty
245
#
246
247
CREATE TABLE t1 (
520.1.16 by Brian Aker
More test updates (one ulong fix)
248
    f1 int NOT NULL auto_increment PRIMARY KEY,
1 by brian
clean slate
249
    f2 varchar(100) NOT NULL default ''
250
);
251
CREATE TABLE t2 (
252
    f1 varchar(10) NOT NULL default '',
253
    f2 char(3) NOT NULL default '',
254
    PRIMARY KEY  (`f1`),
255
    KEY `k1` (`f2`, `f1`)
256
);
257
258
INSERT INTO t1 values(NULL, '');
259
INSERT INTO `t2` VALUES ('486878','WDT'),('486910','WDT');
260
SELECT COUNT(*) FROM t1;
261
262
SELECT min(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1;
263
264
INSERT INTO t1 (f2)
265
  SELECT min(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1;
266
267
SELECT COUNT(*) FROM t1;
268
SELECT * FROM t1;
269
DROP TABLE t1, t2;
270
271
# End of 4.1 tests
272
273
#
274
# Bug #18080: INSERT ... SELECT ... JOIN results in ambiguous field list error
275
#
276
CREATE TABLE t1 (x int, y int);
277
CREATE TABLE t2 (z int, y int);
278
CREATE TABLE t3 (a int, b int);
279
INSERT INTO t3 (SELECT x, y FROM t1 JOIN t2 USING (y) WHERE z = 1);
280
DROP TABLE IF EXISTS t1,t2,t3;
281
282
#
283
# Bug #21774: Column count doesn't match value count at row x
284
#
285
CREATE DATABASE bug21774_1;
286
CREATE DATABASE bug21774_2;
287
288
CREATE TABLE bug21774_1.t1(id VARCHAR(10) NOT NULL,label VARCHAR(255));
289
CREATE TABLE bug21774_2.t1(id VARCHAR(10) NOT NULL,label VARCHAR(255));
290
CREATE TABLE bug21774_1.t2(id VARCHAR(10) NOT NULL,label VARCHAR(255));
291
292
INSERT INTO bug21774_2.t1 SELECT t1.* FROM bug21774_1.t1;
293
294
use bug21774_1;
295
INSERT INTO bug21774_2.t1 SELECT t1.* FROM t1;
296
297
DROP DATABASE bug21774_1;
298
DROP DATABASE bug21774_2;
299
USE test;
300
301
#
302
# Bug#19978: INSERT .. ON DUPLICATE erroneously reports some records were
303
#            updated.
304
#
305
create table t1(f1 int primary key, f2 int);
306
--enable_info
307
insert into t1 values (1,1);
308
insert into t1 values (1,1) on duplicate key update f2=1;
309
insert into t1 values (1,1) on duplicate key update f2=2;
310
--disable_info
311
select * from t1;
312
drop table t1;
313
314
#
315
# Bug#16630: wrong result, when INSERT t1 SELECT ... FROM t1 ON DUPLICATE
316
#
317
CREATE TABLE t1 (f1 INT, f2 INT );
318
CREATE TABLE t2  (f1 INT PRIMARY KEY, f2 INT);
319
INSERT INTO t1 VALUES (1,1),(2,2),(10,10);
320
INSERT INTO t2 (f1, f2) SELECT f1, f2 FROM t1;
321
INSERT INTO t2 (f1, f2)
322
  SELECT f1, f1 FROM t2 src WHERE f1 < 2
323
  ON DUPLICATE KEY UPDATE f1 = 100 + src.f1;
324
SELECT * FROM t2;
325
DROP TABLE t1, t2;
326
327
#
328
# Bug #29095: incorrect pushing of LIMIT into the temporary
329
# table ignoring ORDER BY clause
330
#
331
332
CREATE TABLE t1 (
333
  id INT AUTO_INCREMENT PRIMARY KEY,
334
  prev_id INT,
335
  join_id INT DEFAULT 0);
336
337
INSERT INTO t1 (prev_id) VALUES (NULL), (1), (2);
338
SELECT * FROM t1;
339
340
CREATE TABLE t2 (join_id INT);
341
INSERT INTO t2 (join_id) VALUES (0);
342
343
INSERT INTO t1 (prev_id) SELECT id
344
  FROM t2 LEFT JOIN t1 ON t1.join_id = t2.join_id
345
  ORDER BY id DESC LIMIT 1;
346
SELECT * FROM t1;
347
348
DROP TABLE t1,t2;
349
350
--echo #
351
--echo # Bug#30384: Having SQL_BUFFER_RESULT option in the
352
--echo #            CREATE .. KEY(..) .. SELECT led to creating corrupted index.
353
--echo #
354
create table t1(f1 int);
355
insert into t1 values(1),(2),(3);
1063.9.6 by Stewart Smith
insert_select test for MyISAM as temp table only: 1 open table twice, 3x can be myisam temp.
356
create temporary table t2 (key(f1)) engine=myisam select sql_buffer_result f1 from t1;
1222.1.10 by Brian Aker
Removes options from DDL left in Cursor for admin operations (they were
357
check table t2;
1 by brian
clean slate
358
drop table t1,t2;
359
--echo ##################################################################
360