~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/subselect.test

  • Committer: Brian Aker
  • Date: 2009-07-11 19:23:04 UTC
  • mfrom: (1089.1.14 merge)
  • Revision ID: brian@gaz-20090711192304-ootijyl5yf9jq9kd
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 
54
54
SELECT 1 as a,(SELECT a+a) b,(SELECT b);
55
55
 
56
 
create table t1 (a int);
57
 
create table t2 (a int, b int);
58
 
create table t3 (a int);
59
 
create table t4 (a int not null, b int not null);
 
56
create table t1 (a int) ENGINE=MyISAM;
 
57
create table t2 (a int, b int) ENGINE=MyISAM;
 
58
create table t3 (a int) ENGINE=MyISAM;
 
59
create table t4 (a int not null, b int not null) ENGINE=MyISAM;
60
60
insert into t1 values (2);
61
61
insert into t2 values (1,7),(2,7);
62
62
insert into t4 values (4,8),(3,8),(5,9);
111
111
select b,max(a) as ma from t4 group by b having ma < (select max(t2.a) from t2 where t2.b=t4.b);
112
112
delete from t2 where a=2 and b=10;
113
113
select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 where t2.b=t4.b);
114
 
create table t5 (a int);
 
114
create table t5 (a int) ENGINE=MyISAM;
115
115
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
116
116
insert into t5 values (5);
117
117
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
120
120
explain extended select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
121
121
-- error 1242
122
122
select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
123
 
create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq));
124
 
create table t7( uq int primary key, name char(25));
 
123
create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq)) ENGINE=MyISAM;
 
124
create table t7( uq int primary key, name char(25)) ENGINE=MyISAM;
125
125
insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta");
126
126
insert into t6 values (1,1),(1,2),(2,2),(1,3);
127
127
select * from t6 where exists (select * from t7 where uq = clinic_uq);
134
134
# different tipes & group functions
135
135
drop table t1,t2,t3;
136
136
 
137
 
CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0');
 
137
CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0') ENGINE=MyISAM;
138
138
INSERT INTO t3 VALUES ('W','a'),('A','c'),('J','b');
139
 
CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0');
 
139
CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0') ENGINE=MyISAM;
140
140
INSERT INTO t2 VALUES ('W','1'),('A','3'),('J','2');
141
 
CREATE TABLE t1 (a varchar(20),b date NOT NULL default '0000-00-00');
 
141
CREATE TABLE t1 (a varchar(20),b date NULL) ENGINE=MyISAM;
142
142
INSERT INTO t1 VALUES ('W','1732-02-22'),('A','1735-10-30'),('J','1743-04-13');
143
143
SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1);
144
144
SELECT * FROM t2 WHERE b = (SELECT MIN(b) FROM t2);
145
145
SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3);
146
146
 
147
147
CREATE TABLE `t8` (
148
 
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
149
 
  `email` varchar(60) character set latin1 NOT NULL default '',
 
148
  `pseudo` varchar(35) NOT NULL default '',
 
149
  `email` varchar(60) NOT NULL default '',
150
150
  PRIMARY KEY  (`pseudo`),
151
151
  UNIQUE KEY `email` (`email`)
152
 
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
 
152
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
153
153
 
154
154
INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
155
155
INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
169
169
 
170
170
#searchconthardwarefr3 forumconthardwarefr7
171
171
CREATE TABLE `t1` (
172
 
  `topic` bigint unsigned NOT NULL default '0',
173
 
  `date` date NOT NULL default '0000-00-00',
174
 
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
 
172
  `topic` bigint NOT NULL default '0',
 
173
  `date` date NULL,
 
174
  `pseudo` varchar(35) NOT NULL default '',
175
175
  PRIMARY KEY  (`pseudo`,`date`,`topic`),
176
176
  KEY `topic` (`topic`)
177
177
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
189
189
 
190
190
#forumconthardwarefr7 searchconthardwarefr7
191
191
CREATE TABLE `t1` (
192
 
  `numeropost` bigint unsigned NOT NULL auto_increment,
193
 
  `maxnumrep` int unsigned NOT NULL default '0',
 
192
  `numeropost` bigint NOT NULL auto_increment,
 
193
  `maxnumrep` int NOT NULL default '0',
194
194
  PRIMARY KEY  (`numeropost`),
195
195
  UNIQUE KEY `maxnumrep` (`maxnumrep`)
196
196
) ENGINE=MyISAM ROW_FORMAT=FIXED;
199
199
 
200
200
CREATE TABLE `t2` (
201
201
      `mot` varchar(30) NOT NULL default '',
202
 
      `topic` bigint unsigned NOT NULL default '0',
203
 
      `date` date NOT NULL default '0000-00-00',
 
202
      `topic` bigint NOT NULL default '0',
 
203
      `date` date NULL,
204
204
      `pseudo` varchar(35) NOT NULL default '',
205
205
       PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`)
206
206
    ) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
232
232
 
233
233
#forumconthardwarefr7
234
234
CREATE TABLE `t1` (
235
 
  `numeropost` bigint unsigned NOT NULL auto_increment,
236
 
  `maxnumrep` int unsigned NOT NULL default '0',
 
235
  `numeropost` bigint NOT NULL auto_increment,
 
236
  `maxnumrep` int NOT NULL default '0',
237
237
  PRIMARY KEY  (`numeropost`),
238
238
  UNIQUE KEY `maxnumrep` (`maxnumrep`)
239
239
) ENGINE=MyISAM ROW_FORMAT=FIXED;
245
245
select numeropost as a FROM t1 ORDER BY (SELECT 1 FROM t1 HAVING a=1);
246
246
drop table t1;
247
247
 
248
 
create table t1 (a int);
 
248
create table t1 (a int) ENGINE=MyISAM;
249
249
insert into t1 values (1),(2),(3);
250
250
(select * from t1) union (select * from t1) order by (select a from t1 limit 1);
251
251
drop table t1;
252
252
 
253
253
#iftest
254
 
CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b');
 
254
CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b') ENGINE=MyISAM;
255
255
INSERT INTO t1 VALUES ();
256
256
-- error 1242
257
257
SELECT field FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) a HAVING field='b');
259
259
 
260
260
# threadhardwarefr7
261
261
CREATE TABLE `t1` (
262
 
  `numeropost` bigint unsigned NOT NULL default '0',
263
 
  `numreponse` int unsigned NOT NULL auto_increment,
 
262
  `numeropost` bigint NOT NULL default '0',
 
263
  `numreponse` int NOT NULL auto_increment,
264
264
  `pseudo` varchar(35) NOT NULL default '',
265
265
  PRIMARY KEY  (`numeropost`,`numreponse`),
266
266
  UNIQUE KEY `numreponse` (`numreponse`),
278
278
EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1');
279
279
drop table t1;
280
280
 
281
 
CREATE TABLE t1 (a int);
 
281
CREATE TABLE t1 (a int) ENGINE=MyISAM;
282
282
INSERT INTO t1 VALUES (1);
283
283
SELECT 1 FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1;
284
284
drop table t1;
285
285
 
286
286
#update with subselects
287
 
create table t1 (a int NOT NULL, b int, primary key (a));
288
 
create table t2 (a int NOT NULL, b int, primary key (a));
 
287
create table t1 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
 
288
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
289
289
insert into t1 values (0, 10),(1, 11),(2, 12);
290
290
insert into t2 values (1, 21),(2, 22),(3, 23);
291
291
select * from t1;
298
298
drop table t1, t2;
299
299
 
300
300
#delete with subselects
301
 
create table t1 (a int NOT NULL, b int, primary key (a));
302
 
create table t2 (a int NOT NULL, b int, primary key (a));
 
301
create table t1 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
 
302
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
303
303
insert into t1 values (0, 10),(1, 11),(2, 12);
304
304
insert into t2 values (1, 21),(2, 12),(3, 23);
305
305
select * from t1;
314
314
 
315
315
#multi-delete with subselects
316
316
 
317
 
create table t11 (a int NOT NULL, b int, primary key (a));
318
 
create table t12 (a int NOT NULL, b int, primary key (a));
319
 
create table t2 (a int NOT NULL, b int, primary key (a));
 
317
create table t11 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
 
318
create table t12 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
 
319
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
320
320
insert into t11 values (0, 10),(1, 11),(2, 12);
321
321
insert into t12 values (33, 10),(22, 11),(2, 12);
322
322
insert into t2 values (1, 21),(2, 12),(3, 23);
323
323
select * from t11;
 
324
--sorted_result
324
325
select * from t12;
325
326
-- error 1093
326
327
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
328
329
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
329
330
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
330
331
select * from t11;
 
332
--sorted_result
331
333
select * from t12;
332
334
drop table t11, t12, t2;
333
335
 
334
336
#insert with subselects
335
 
CREATE TABLE t1 (x int);
336
 
create table t2 (a int);
337
 
create table t3 (b int);
 
337
CREATE TABLE t1 (x int) ENGINE=MyISAM;
 
338
create table t2 (a int) ENGINE=MyISAM;
 
339
create table t3 (b int) ENGINE=MyISAM;
338
340
insert into t2 values (1);
339
341
insert into t3 values (1),(2);
340
342
-- error 1093
344
346
INSERT INTO t1 (x) VALUES ((SELECT a FROM t2));
345
347
select * from t1;
346
348
insert into t2 values (1);
347
 
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
 
349
INSERT INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
348
350
-- sleep 1
349
351
select * from t1;
350
352
INSERT INTO t1 (x) select (SELECT SUM(a)+1 FROM t2) FROM t2;
353
355
INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2;
354
356
select * from t1;
355
357
-- error 1054
356
 
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
357
 
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
 
358
INSERT INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
 
359
INSERT INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
358
360
-- sleep 1
359
361
select * from t1;
360
362
#
364
366
drop table t1, t2, t3;
365
367
 
366
368
#replace with subselects
367
 
CREATE TABLE t1 (x int not null, y int, primary key (x));
368
 
create table t2 (a int);
369
 
create table t3 (a int);
 
369
CREATE TABLE t1 (x int not null, y int, primary key (x)) ENGINE=MyISAM;
 
370
create table t2 (a int) ENGINE=MyISAM;
 
371
create table t3 (a int) ENGINE=MyISAM;
370
372
insert into t2 values (1);
371
373
insert into t3 values (1),(2);
372
374
select * from t1;
378
380
select * from t1;
379
381
replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+2 FROM t2));
380
382
select * from t1;
381
 
replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a FROM t2));
382
 
select * from t1;
383
 
replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a+1 FROM t2));
384
 
select * from t1;
385
 
replace LOW_PRIORITY into t1 (x, y) VALUES ((SELECT a+1 FROM t2), (SELECT a FROM t2));
 
383
replace into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a FROM t2));
 
384
-- sleep 1
 
385
--sorted_result
 
386
select * from t1;
 
387
replace into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a+1 FROM t2));
 
388
-- sleep 1
 
389
select * from t1;
 
390
replace into t1 (x, y) VALUES ((SELECT a+1 FROM t2), (SELECT a FROM t2));
 
391
--sorted_result
386
392
select * from t1;
387
393
drop table t1, t2, t3;
388
394
 
389
395
-- error 1096
390
396
SELECT * FROM (SELECT 1) b WHERE 1 IN (SELECT *);
391
397
 
392
 
CREATE TABLE t2 (id int default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1;
 
398
CREATE TABLE t2 (id int default NULL, KEY id (id)) ENGINE=MyISAM;
393
399
INSERT INTO t2 VALUES (1),(2);
394
400
SELECT * FROM t2 WHERE id IN (SELECT 1);
395
401
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1);
406
410
-- error 1093
407
411
INSERT INTO t2 VALUES ((SELECT id FROM t2));
408
412
SELECT * FROM t2;
409
 
CREATE TABLE t1 (id int default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1;
 
413
CREATE TABLE t1 (id int default NULL, KEY id (id)) ENGINE=MyISAM;
410
414
INSERT INTO t1 values (1),(1);
411
415
-- error 1242
412
416
UPDATE t2 SET id=(SELECT * FROM t1);
413
417
drop table t2, t1;
414
418
 
415
419
#NULL test
416
 
create table t1 (a int);
 
420
create table t1 (a int) ENGINE=MyISAM;
417
421
insert into t1 values (1),(2),(3);
418
422
select 1 IN (SELECT * from t1);
419
423
select 10 IN (SELECT * from t1);
427
431
select 1 > ANY (SELECT * from t1);
428
432
select 10 > ANY (SELECT * from t1);
429
433
drop table t1;
430
 
create table t1 (a varchar(20));
 
434
create table t1 (a varchar(20)) ENGINE=MyISAM;
431
435
insert into t1 values ('A'),('BC'),('DEF');
432
436
select 'A' IN (SELECT * from t1);
433
437
select 'XYZS' IN (SELECT * from t1);
441
445
select 'A' > ANY (SELECT * from t1);
442
446
select 'XYZS' > ANY (SELECT * from t1);
443
447
drop table t1;
444
 
create table t1 (a float);
 
448
create table t1 (a float) ENGINE=MyISAM;
445
449
insert into t1 values (1.5),(2.5),(3.5);
446
450
select 1.5 IN (SELECT * from t1);
447
451
select 10.5 IN (SELECT * from t1);
455
459
select 1.5 > ANY (SELECT * from t1);
456
460
select 10.5 > ANY (SELECT * from t1);
457
461
explain extended select (select a+1) from t1;
 
462
--sorted_result
458
463
select (select a+1) from t1;
459
464
drop table t1;
460
465
 
462
467
# Null with keys
463
468
#
464
469
 
465
 
CREATE TABLE t1 (a int NOT NULL default '0', PRIMARY KEY  (a));
466
 
CREATE TABLE t2 (a int default '0', INDEX (a));
 
470
CREATE TABLE t1 (a int NOT NULL default '0', PRIMARY KEY  (a)) ENGINE=MyISAM;
 
471
CREATE TABLE t2 (a int default '0', INDEX (a)) ENGINE=MyISAM;
467
472
INSERT INTO t1 VALUES (1),(2),(3),(4);
468
473
INSERT INTO t2 VALUES (1),(2),(3);
469
474
SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
470
475
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
471
 
CREATE TABLE t3 (a int default '0');
 
476
CREATE TABLE t3 (a int default '0') ENGINE=MyISAM;
472
477
INSERT INTO t3 VALUES (1),(2),(3);
473
478
SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
474
479
explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
475
480
drop table t1,t2,t3;
476
481
 
477
482
#LIMIT is not supported now
478
 
create table t1 (a float);
479
 
select 10.5 IN (SELECT * from t1 LIMIT 1);
480
 
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
481
 
drop table t1;
482
 
 
483
 
create table t1 (a int, b int, c varchar(10));
484
 
create table t2 (a int);
485
 
insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c');
486
 
insert into t2 values (1),(2),(NULL);
487
 
select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a'),(select c from t1 where a=t2.a)  from t2;
488
 
select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b'),(select c from t1 where a=t2.a) from t2;
489
 
select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c'),(select c from t1 where a=t2.a) from t2;
490
 
drop table t1,t2;
491
 
 
492
 
create table t1 (a int, b real, c varchar(10));
493
 
insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');
494
 
select ROW(1, 1, 'a') IN (select a,b,c from t1);
495
 
select ROW(1, 2, 'a') IN (select a,b,c from t1);
496
 
select ROW(1, 1, 'a') IN (select b,a,c from t1);
497
 
select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null);
498
 
select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null);
499
 
select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null);
500
 
select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a');
501
 
select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a');
502
 
select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
503
 
select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
504
 
drop table t1;
 
483
#create table t1 (a float) ENGINE=MyISAM;
 
484
#-- error 1235
 
485
#select 10.5 IN (SELECT * from t1 LIMIT 1);
 
486
#-- error 1235
 
487
#select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
 
488
#drop table t1;
 
489
#
 
490
#create table t1 (a int, b int, c varchar(10)) ENGINE=MyISAM;
 
491
#create table t2 (a int) ENGINE=MyISAM;
 
492
#insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c');
 
493
#insert into t2 values (1),(2),(NULL);
 
494
#select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a'),(select c from t1 where a=t2.a)  from t2;
 
495
#select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b'),(select c from t1 where a=t2.a) from t2;
 
496
#select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c'),(select c from t1 where a=t2.a) from t2;
 
497
#drop table t1,t2;
 
498
#
 
499
#create table t1 (a int, b real, c varchar(10)) ENGINE=MyISAM;
 
500
#insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');
 
501
#select ROW(1, 1, 'a') IN (select a,b,c from t1);
 
502
#select ROW(1, 2, 'a') IN (select a,b,c from t1);
 
503
#select ROW(1, 1, 'a') IN (select b,a,c from t1);
 
504
#select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null);
 
505
#select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null);
 
506
#select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null);
 
507
#select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a');
 
508
#select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a');
 
509
#select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
 
510
#-- error 1235
 
511
#select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
 
512
#drop table t1;
505
513
 
506
514
#test of uncacheable subqueries
507
 
CREATE TABLE t1 (a int);
 
515
CREATE TABLE t1 (a int) ENGINE=MyISAM;
508
516
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
509
517
EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1;
510
518
drop table t1;
511
519
 
512
520
 
513
521
CREATE TABLE `t1` (
514
 
  `mot` varchar(30) character set latin1 NOT NULL default '',
515
 
  `topic` bigint unsigned NOT NULL default '0',
516
 
  `date` date NOT NULL default '0000-00-00',
517
 
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
 
522
  `mot` varchar(30) NOT NULL default '',
 
523
  `topic` bigint NOT NULL default '0',
 
524
  `date` date NULL DEFAULT '2009-01-20',
 
525
  `pseudo` varchar(35) NOT NULL default '',
518
526
  PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`),
519
527
  KEY `pseudo` (`pseudo`,`date`,`topic`),
520
528
  KEY `topic` (`topic`)
521
 
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
 
529
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
522
530
 
523
531
CREATE TABLE `t2` (
524
 
  `mot` varchar(30) character set latin1 NOT NULL default '',
525
 
  `topic` bigint unsigned NOT NULL default '0',
526
 
  `date` date NOT NULL default '0000-00-00',
527
 
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
 
532
  `mot` varchar(30) NOT NULL default '',
 
533
  `topic` bigint NOT NULL default '0',
 
534
  `date` date NULL default '1997-08-29',
 
535
  `pseudo` varchar(35) NOT NULL default '',
528
536
  PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`),
529
537
  KEY `pseudo` (`pseudo`,`date`,`topic`),
530
538
  KEY `topic` (`topic`)
531
 
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
 
539
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
532
540
 
533
541
CREATE TABLE `t3` (
534
 
  `numeropost` bigint unsigned NOT NULL auto_increment,
535
 
  `maxnumrep` int unsigned NOT NULL default '0',
 
542
  `numeropost` bigint NOT NULL auto_increment,
 
543
  `maxnumrep` int NOT NULL default '0',
536
544
  PRIMARY KEY  (`numeropost`),
537
545
  UNIQUE KEY `maxnumrep` (`maxnumrep`)
538
 
) ENGINE=MyISAM CHARSET=latin1;
 
546
) ENGINE=MyISAM;
539
547
INSERT INTO t1 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
540
548
 
541
549
INSERT INTO t2 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
555
560
drop table t1, t2, t3;
556
561
 
557
562
SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
558
 
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT 1)) a;
559
 
SHOW CREATE TABLE t1;
560
 
drop table t1;
561
 
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
562
 
SHOW CREATE TABLE t1;
563
 
drop table t1;
564
 
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a;
565
 
SHOW CREATE TABLE t1;
566
 
drop table t1;
567
 
CREATE TABLE t1 SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a;
 
563
CREATE TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT 1)) a;
 
564
SHOW CREATE TABLE t1;
 
565
drop table t1;
 
566
CREATE TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
 
567
SHOW CREATE TABLE t1;
 
568
drop table t1;
 
569
CREATE TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a;
 
570
SHOW CREATE TABLE t1;
 
571
drop table t1;
 
572
CREATE TABLE t1 ENGINE=MyISAM SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a;
568
573
select * from t1;
569
574
SHOW CREATE TABLE t1;
570
575
drop table t1;
571
576
 
572
 
create table t1 (a int);
 
577
create table t1 (a int) ENGINE=MyISAM;
573
578
insert into t1 values (1), (2), (3);
574
579
explain extended select a,(select (select rand() from t1 limit 1)  from t1 limit 1)
575
580
from t1;
604
609
  Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
605
610
  Region char(26) NOT NULL default '',
606
611
  SurfaceArea float(10,2) NOT NULL default '0.00',
607
 
  IndepYear smallint default NULL,
 
612
  IndepYear int default NULL,
608
613
  Population int NOT NULL default '0',
609
614
  LifeExpectancy float(3,1) default NULL,
610
615
  GNP float(10,2) default NULL,
628
633
# constants in IN
629
634
#
630
635
CREATE TABLE `t1` (
631
 
  `id` bigint unsigned NOT NULL auto_increment,
632
 
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
 
636
  `id` bigint NOT NULL auto_increment,
 
637
  `pseudo` varchar(35) NOT NULL default '',
633
638
  PRIMARY KEY  (`id`),
634
639
  UNIQUE KEY `pseudo` (`pseudo`)
635
640
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
644
649
CREATE TABLE `t1` (
645
650
  `i` int NOT NULL default '0',
646
651
  PRIMARY KEY  (`i`)
647
 
) ENGINE=MyISAM CHARSET=latin1;
 
652
) ENGINE=MyISAM;
648
653
 
649
654
INSERT INTO t1 VALUES (1);
650
655
UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i));
659
664
#
660
665
CREATE TABLE t1 (
661
666
  id int default NULL
662
 
) ENGINE=MyISAM CHARSET=latin1;
 
667
) ENGINE=MyISAM;
663
668
INSERT INTO t1 VALUES (1),(1),(2),(2),(1),(3);
664
669
CREATE TABLE t2 (
665
670
  id int default NULL,
666
671
  name varchar(15) default NULL
667
 
) ENGINE=MyISAM CHARSET=latin1;
 
672
) ENGINE=MyISAM;
668
673
 
669
674
INSERT INTO t2 VALUES (4,'vita'), (1,'vita'), (2,'vita'), (1,'vita');
670
675
update t1, t2 set t2.name='lenka' where t2.id in (select id from t1);
674
679
#
675
680
# correct NULL in <CONSTANT> IN (SELECT ...)
676
681
#
677
 
create table t1 (a int, unique index indexa (a)); 
 
682
create table t1 (a int, unique index indexa (a)) ENGINE=MyISAM; 
678
683
insert into t1 values (-1), (-4), (-2), (NULL); 
679
684
select -10 IN (select a from t1 FORCE INDEX (indexa)); 
680
685
drop table t1;
682
687
#
683
688
# Test optimization for sub selects
684
689
#
685
 
create table t1 (id int not null auto_increment primary key, salary int, key(salary));
 
690
create table t1 (id int not null auto_increment primary key, salary int, key(salary)) ENGINE=MyISAM;
686
691
insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000);
687
692
explain extended SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1);
688
693
drop table t1;
689
694
 
690
695
CREATE TABLE t1 (
691
 
  ID int unsigned NOT NULL auto_increment,
692
 
  SUB_ID int unsigned NOT NULL default '0',
693
 
  REF_ID int unsigned default NULL,
694
 
  REF_SUB int unsigned default '0',
 
696
  ID int NOT NULL auto_increment,
 
697
  SUB_ID int NOT NULL default '0',
 
698
  REF_ID int default NULL,
 
699
  REF_SUB int default '0',
695
700
  PRIMARY KEY (ID,SUB_ID),
696
701
  UNIQUE KEY t1_PK (ID,SUB_ID),
697
702
  KEY t1_FK (REF_ID,REF_SUB),
698
703
  KEY t1_REFID (REF_ID)
699
 
) ENGINE=MyISAM CHARSET=cp1251;
 
704
) ENGINE=MyISAM;
700
705
INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
701
706
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
702
707
DROP TABLE t1;
704
709
#
705
710
# uninterruptable update
706
711
#
707
 
create table t1 (a int, b int);
708
 
create table t2 (a int, b int);
 
712
create table t1 (a int, b int) ENGINE=MyISAM;
 
713
create table t2 (a int, b int) ENGINE=MyISAM;
709
714
 
710
715
insert into t1 values (1,0), (2,0), (3,0);
711
716
insert into t2 values (1,1), (2,1), (3,1), (2,2);
720
725
#
721
726
 
722
727
CREATE TABLE `t1` (
723
 
  `id` bigint unsigned NOT NULL auto_increment,
 
728
  `id` bigint NOT NULL auto_increment,
724
729
  `pseudo` varchar(35) NOT NULL default '',
725
730
  `email` varchar(60) NOT NULL default '',
726
731
  PRIMARY KEY  (`id`),
727
732
  UNIQUE KEY `email` (`email`),
728
733
  UNIQUE KEY `pseudo` (`pseudo`)
729
 
) ENGINE=MyISAM CHARSET=latin1 PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
 
734
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
730
735
INSERT INTO t1 (id,pseudo,email) VALUES (1,'test','test'),(2,'test1','test1');
731
736
SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT id*1);
732
737
drop table if exists t1;
736
741
#
737
742
# IN subselect optimization test
738
743
#
739
 
create table t1 (a int not null, b int, primary key (a));
740
 
create table t2 (a int not null, primary key (a));
741
 
create table t3 (a int not null, b int, primary key (a));
 
744
create table t1 (a int not null, b int, primary key (a)) ENGINE=MyISAM;
 
745
create table t2 (a int not null, primary key (a)) ENGINE=MyISAM;
 
746
create table t3 (a int not null, b int, primary key (a)) ENGINE=MyISAM;
742
747
insert into t1 values (1,10), (2,20), (3,30),  (4,40);
743
748
insert into t2 values (2), (3), (4), (5);
744
749
insert into t3 values (10,3), (20,4), (30,5);
749
754
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
750
755
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
751
756
drop table t1, t2, t3;
752
 
create table t1 (a int, b int, index a (a,b));
753
 
create table t2 (a int, index a (a));
754
 
create table t3 (a int, b int, index a (a));
 
757
create table t1 (a int, b int, index a (a,b)) ENGINE=MyISAM;
 
758
create table t2 (a int, index a (a)) ENGINE=MyISAM;
 
759
create table t3 (a int, b int, index a (a)) ENGINE=MyISAM;
755
760
insert into t1 values (1,10), (2,20), (3,30), (4,40);
756
761
disable_query_log;
757
762
# making table large enough
783
788
#
784
789
# alloc_group_fields() working
785
790
#
786
 
create table t1 (a int, b int);
787
 
create table t2 (a int, b int);
788
 
create table t3 (a int, b int);
 
791
create table t1 (a int, b int) ENGINE=MyISAM;
 
792
create table t2 (a int, b int) ENGINE=MyISAM;
 
793
create table t3 (a int, b int) ENGINE=MyISAM;
789
794
insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10);
790
795
insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1);
791
796
insert into t3 values (3,3), (2,2), (1,1); 
795
800
#
796
801
# aggregate functions in HAVING test
797
802
#
798
 
create table t1 (s1 int);
799
 
create table t2 (s1 int);
 
803
create table t1 (s1 int) ENGINE=MyISAM;
 
804
create table t2 (s1 int) ENGINE=MyISAM;
800
805
insert into t1 values (1);
801
806
insert into t2 values (1);
802
807
select * from t1 where exists (select s1 from t2 having max(t2.s1)=t1.s1);
806
811
# update subquery with wrong field (to force name resolving
807
812
# in UPDATE name space)
808
813
#
809
 
create table t1 (s1 int);
810
 
create table t2 (s1 int);
 
814
create table t1 (s1 int) ENGINE=MyISAM;
 
815
create table t2 (s1 int) ENGINE=MyISAM;
811
816
insert into t1 values (1);
812
817
insert into t2 values (1);
813
818
-- error 1054
817
822
#
818
823
# collation test
819
824
#
820
 
CREATE TABLE t1 (s1 CHAR(5) COLLATE latin1_german1_ci,
821
 
                 s2 CHAR(5) COLLATE latin1_swedish_ci);
822
 
INSERT INTO t1 VALUES ('z','?');
823
 
select * from t1 where s1 > (select max(s2) from t1);
824
 
select * from t1 where s1 > any (select max(s2) from t1);
825
 
drop table t1;
 
825
#CREATE TABLE t1 (s1 CHAR(5) COLLATE latin1_german1_ci,
 
826
#                 s2 CHAR(5) COLLATE latin1_swedish_ci) ENGINE=MyISAM;
 
827
#INSERT INTO t1 VALUES ('z','?');
 
828
#-- error 1267
 
829
#select * from t1 where s1 > (select max(s2) from t1);
 
830
#-- error 1267
 
831
#select * from t1 where s1 > any (select max(s2) from t1);
 
832
#drop table t1;
826
833
 
827
834
#
828
835
# aggregate functions reinitialization
829
836
#
830
 
create table t1(toid int,rd int);
831
 
create table t2(userid int,pmnew int,pmtotal int);
 
837
create table t1(toid int,rd int) ENGINE=MyISAM;
 
838
create table t2(userid int,pmnew int,pmtotal int) ENGINE=MyISAM;
832
839
insert into t2 values(1,0,0),(2,0,0);
833
840
insert into t1 values(1,0),(1,0),(1,0),(1,12),(1,15),(1,123),(1,12312),(1,12312),(1,123),(2,0),(2,0),(2,1),(2,2);
834
841
select userid,pmtotal,pmnew, (select count(rd) from t1 where toid=t2.userid) calc_total, (select count(rd) from t1 where rd=0 and toid=t2.userid) calc_new from t2 where userid in (select distinct toid from t1);
839
844
#
840
845
# row union
841
846
#
842
 
create table t1 (s1 char(5));
 
847
create table t1 (s1 char(5)) ENGINE=MyISAM;
843
848
-- error 1241
844
849
select (select 'a','b' from t1 union select 'a','b' from t1) from t1;
845
850
insert into t1 values ('tttt');
851
856
#
852
857
# IN optimisation test results
853
858
#
854
 
create table t1 (s1 char(5), index s1(s1));
855
 
create table t2 (s1 char(5), index s1(s1));
 
859
create table t1 (s1 char(5), index s1(s1)) ENGINE=MyISAM;
 
860
create table t2 (s1 char(5), index s1(s1)) ENGINE=MyISAM;
856
861
insert into t1 values ('a1'),('a2'),('a3');
857
862
insert into t2 values ('a1'),('a2');
858
863
select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
868
873
#
869
874
# correct ALL optimisation
870
875
#
871
 
create table t2 (a int, b int);
872
 
create table t3 (a int);
 
876
create table t2 (a int, b int) ENGINE=MyISAM;
 
877
create table t3 (a int) ENGINE=MyISAM;
873
878
insert into t3 values (6),(7),(3);
874
879
select * from t3 where a >= all (select b from t2);
875
880
explain extended select * from t3 where a >= all (select b from t2);
899
904
# correct used_tables()
900
905
#
901
906
 
902
 
CREATE TABLE `t1` ( `id` bigint NOT NULL auto_increment, `taskid` bigint NOT NULL default '0', `dbid` int NOT NULL default '0', `create_date` datetime NOT NULL default '0000-00-00 00:00:00', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY  (`id`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=3 ;
 
907
CREATE TABLE `t1` ( `id` bigint NOT NULL auto_increment, `taskid` bigint NOT NULL default '0', `dbid` int NOT NULL default '0', `create_date` datetime, `last_update` datetime, PRIMARY KEY  (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 ;
903
908
INSERT INTO `t1` (`id`, `taskid`, `dbid`, `create_date`,`last_update`) VALUES (1, 1, 15, '2003-09-29 10:31:36', '2003-09-29 10:31:36'), (2, 1, 21, now(), now());
904
 
CREATE TABLE `t2` (`db_id` int NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` smallint NOT NULL default '0',`secondary_uid` smallint NOT NULL default '0',PRIMARY KEY  (`db_id`),UNIQUE KEY `name_2` (`name`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2147483647;
 
909
CREATE TABLE `t2` (`db_id` int NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` int NOT NULL default '0',`secondary_uid` int NOT NULL default '0',PRIMARY KEY  (`db_id`),UNIQUE KEY `name_2` (`name`)) ENGINE=MyISAM AUTO_INCREMENT=2147483647;
905
910
INSERT INTO `t2` (`db_id`, `name`, `primary_uid`, `secondary_uid`) VALUES (18, 'Not Set 1', 0, 0),(19, 'Valid', 1, 2),(20, 'Valid 2', 1, 2),(21, 'Should Not Return', 1, 2),(26, 'Not Set 2', 0, 0),(-1, 'ALL DB\'S', 0, 0);
906
 
CREATE TABLE `t3` (`taskgenid` bigint NOT NULL auto_increment,`dbid` int NOT NULL default '0',`taskid` int NOT NULL default '0',`mon` tinyint NOT NULL default '1',`tues` tinyint NOT NULL default '1',`wed` tinyint NOT NULL default '1',`thur` tinyint NOT NULL default '1',`fri` tinyint NOT NULL default '1',`sat` tinyint NOT NULL default '0',`sun` tinyint NOT NULL default '0',`how_often` smallint NOT NULL default '1',`userid` smallint NOT NULL default '0',`active` tinyint NOT NULL default '1',PRIMARY KEY  (`taskgenid`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2 ;
 
911
CREATE TABLE `t3` (`taskgenid` bigint NOT NULL auto_increment,`dbid` int NOT NULL default '0',`taskid` int NOT NULL default '0',`mon` int NOT NULL default '1',`tues` int NOT NULL default '1',`wed` int NOT NULL default '1',`thur` int NOT NULL default '1',`fri` int NOT NULL default '1',`sat` int NOT NULL default '0',`sun` int NOT NULL default '0',`how_often` int NOT NULL default '1',`userid` int NOT NULL default '0',`active` int NOT NULL default '1',PRIMARY KEY  (`taskgenid`)) ENGINE=MyISAM AUTO_INCREMENT=2 ;
907
912
INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1);
908
 
CREATE TABLE `t4` (`task_id` smallint NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
 
913
CREATE TABLE `t4` (`task_id` int NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM;
909
914
INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
910
915
select  dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4  WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid;
911
916
SELECT dbid, name FROM t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND ((date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01')) AND t4.task_id = taskid;
914
919
#
915
920
# cardinality check
916
921
#
917
 
CREATE TABLE t1 (id int default NULL) ENGINE=MyISAM CHARSET=latin1;
 
922
CREATE TABLE t1 (id int default NULL) ENGINE=MyISAM;
918
923
INSERT INTO t1 VALUES (1),(5);
919
 
CREATE TABLE t2 (id int default NULL) ENGINE=MyISAM CHARSET=latin1;
 
924
CREATE TABLE t2 (id int default NULL) ENGINE=MyISAM;
920
925
INSERT INTO t2 VALUES (2),(6);
921
926
-- error 1241
922
927
select * from t1 where (1,2,6) in (select * from t2);
925
930
#
926
931
# optimized ALL/ANY with union
927
932
#
928
 
create table t1 (s1 char);
 
933
create table t1 (s1 char) ENGINE=MyISAM;
929
934
insert into t1 values ('e');
930
935
select * from t1 where 'f' > any (select s1 from t1);
931
936
select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
935
940
#
936
941
# filesort in subquery (restoring join_tab)
937
942
#
938
 
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
 
943
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM;
939
944
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
940
 
CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM CHARSET=latin1;
 
945
CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM;
941
946
INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6');
942
947
select c.number as phone,(select p.code from t2 p where c.number like concat(p.code, '%') order by length(p.code) desc limit 1) as code from t1 c;
943
948
drop table t1, t2;
945
950
#
946
951
# unresolved field error
947
952
#
948
 
create table t1 (s1 int); 
949
 
create table t2 (s1 int);
 
953
create table t1 (s1 int) ENGINE=MyISAM; 
 
954
create table t2 (s1 int) ENGINE=MyISAM;
950
955
-- error 1054
951
956
select * from t1 where (select count(*) from t2 where t1.s2) = 1;
952
957
-- error 1054
958
963
#
959
964
# fix_fields() in add_ref_to_table_cond()
960
965
#
961
 
CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB));
962
 
CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA));
 
966
CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB)) ENGINE=MyISAM;
 
967
CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA)) ENGINE=MyISAM;
963
968
INSERT INTO t1 VALUES (1,1,'1A3240'), (1,2,'4W2365');
964
969
INSERT INTO t2 VALUES (100, 200, 'C');
965
970
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
966
971
DROP TABLE t1, t2;
967
972
 
968
 
CREATE TABLE t1 (a int);
 
973
CREATE TABLE t1 (a int) ENGINE=MyISAM;
969
974
INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5);
970
975
SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100;
971
976
DROP TABLE t1;
976
981
 
977
982
CREATE TABLE `t1` (
978
983
  `id` int NOT NULL auto_increment,
979
 
  `id_cns` tinyint unsigned NOT NULL default '0',
 
984
  `id_cns` int NOT NULL default '0',
980
985
  `tipo` enum('','UNO','DUE') NOT NULL default '',
981
 
  `anno_dep` smallint unsigned NOT NULL default '0',
982
 
  `particolare` bigint unsigned NOT NULL default '0',
983
 
  `generale` bigint unsigned NOT NULL default '0',
984
 
  `bis` tinyint unsigned NOT NULL default '0',
 
986
  `anno_dep` int NOT NULL default '0',
 
987
  `particolare` bigint NOT NULL default '0',
 
988
  `generale` bigint NOT NULL default '0',
 
989
  `bis` int NOT NULL default '0',
985
990
  PRIMARY KEY  (`id`),
986
991
  UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`),
987
 
  UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`)
988
 
);
 
992
  UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`))
 
993
 ENGINE=MyISAM;
989
994
INSERT INTO `t1` VALUES (1,16,'UNO',1987,2048,9681,0),(2,50,'UNO',1987,1536,13987,0),(3,16,'UNO',1987,2432,14594,0),(4,16,'UNO',1987,1792,13422,0),(5,16,'UNO',1987,1025,10240,0),(6,16,'UNO',1987,1026,7089,0);
990
995
CREATE TABLE `t2` (
991
 
  `id` tinyint unsigned NOT NULL auto_increment,
992
 
  `max_anno_dep` smallint unsigned NOT NULL default '0',
993
 
  PRIMARY KEY  (`id`)
994
 
);
 
996
  `id` int NOT NULL auto_increment,
 
997
  `max_anno_dep` int NOT NULL default '0',
 
998
  PRIMARY KEY  (`id`)) ENGINE=MyISAM;
995
999
INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990);
996
1000
 
997
1001
SELECT cns.id, cns.max_anno_dep, cns.max_anno_dep = (SELECT s.anno_dep FROM t1 AS s WHERE s.id_cns = cns.id ORDER BY s.anno_dep DESC LIMIT 1) AS PIPPO FROM t2 AS cns;
1001
1005
#
1002
1006
# GLOBAL LIMIT
1003
1007
#
1004
 
create table t1 (a int);
 
1008
create table t1 (a int) ENGINE=MyISAM;
1005
1009
insert into t1 values (1), (2), (3);
1006
1010
SET SQL_SELECT_LIMIT=1;
1007
1011
select sum(a) from (select * from t1) as a;
1013
1017
# Bug #3118: subselect + order by
1014
1018
#
1015
1019
 
1016
 
CREATE TABLE t1 (a int, b int, INDEX (a));
 
1020
CREATE TABLE t1 (a int, b int, INDEX (a)) ENGINE=MyISAM;
1017
1021
INSERT INTO t1 VALUES (1, 1), (1, 2), (1, 3);
1018
1022
SELECT * FROM t1 WHERE a = (SELECT MAX(a) FROM t1 WHERE a = 1) ORDER BY b;
1019
1023
DROP TABLE t1;
1020
1024
 
1021
1025
# Item_cond fix field
1022
1026
#
1023
 
create table t1(val varchar(10));
 
1027
create table t1(val varchar(10)) ENGINE=MyISAM;
1024
1028
insert into t1 values ('aaa'), ('bbb'),('eee'),('mmm'),('ppp');
1025
1029
select count(*) from t1 as w1 where w1.val in (select w2.val from t1 as w2 where w2.val like 'm%') and w1.val in (select w3.val from t1 as w3 where w3.val like 'e%');
1026
1030
drop table t1;
1028
1032
#
1029
1033
# ref_or_null replacing with ref
1030
1034
#
1031
 
create table t1 (id int not null, text varchar(20) not null default '', primary key (id));
 
1035
create table t1 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM;
1032
1036
insert into t1 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text11'), (12, 'text12');
1033
1037
select * from t1 where id not in (select id from t1 where id < 8);
1034
1038
select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
1035
1039
explain extended select * from t1 where id not in (select id from t1 where id < 8);
1036
1040
explain extended select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
1037
1041
insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
1038
 
create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
 
1042
create table t2 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM;
1039
1043
insert into t2 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text1'), (12, 'text2'), (13, 'text3'), (14, 'text4'), (15, 'text5'), (16, 'text6'), (17, 'text7'), (18, 'text8'), (19, 'text9'), (20, 'text10'),(21, 'text1'), (22, 'text2'), (23, 'text3'), (24, 'text4'), (25, 'text5'), (26, 'text6'), (27, 'text7'), (28, 'text8'), (29, 'text9'), (30, 'text10'), (31, 'text1'), (32, 'text2'), (33, 'text3'), (34, 'text4'), (35, 'text5'), (36, 'text6'), (37, 'text7'), (38, 'text8'), (39, 'text9'), (40, 'text10'), (41, 'text1'), (42, 'text2'), (43, 'text3'), (44, 'text4'), (45, 'text5'), (46, 'text6'), (47, 'text7'), (48, 'text8'), (49, 'text9'), (50, 'text10');
1040
1044
select * from t1 a left join t2 b on (a.id=b.id or b.id is null) join t1 c on (if(isnull(b.id), 1000, b.id)=c.id);
1041
1045
explain extended select * from t1 a left join t2 b on (a.id=b.id or b.id is null) join t1 c on (if(isnull(b.id), 1000, b.id)=c.id);
1044
1048
#
1045
1049
# Static tables & rund() in subqueries
1046
1050
#
1047
 
create table t1 (a int);
 
1051
create table t1 (a int) ENGINE=MyISAM;
1048
1052
insert into t1 values (1);
1049
1053
explain select benchmark(1000, (select a from t1 where a=rand()));
1050
1054
drop table t1;
1052
1056
#
1053
1057
# bug 3188
1054
1058
#
1055
 
create table t1(id int);
1056
 
create table t2(id int);
1057
 
create table t3(flag int);
 
1059
create table t1(id int) ENGINE=MyISAM;
 
1060
create table t2(id int) ENGINE=MyISAM;
 
1061
create table t3(flag int) ENGINE=MyISAM;
1058
1062
-- error 1064
1059
1063
select (select * from t3 where id not null) from t1, t2;
1060
1064
drop table t1,t2,t3;
1062
1066
#
1063
1067
# aggregate functions (Bug #3505)
1064
1068
#
1065
 
CREATE TABLE t1 (id INT);
1066
 
CREATE TABLE t2 (id INT);
 
1069
CREATE TABLE t1 (id INT) ENGINE=MyISAM;
 
1070
CREATE TABLE t2 (id INT) ENGINE=MyISAM;
1067
1071
INSERT INTO t1 VALUES (1), (2);
1068
1072
INSERT INTO t2 VALUES (1);
1069
1073
SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id);
1075
1079
#
1076
1080
# ALL/ANY test
1077
1081
#
1078
 
CREATE TABLE t1 ( a int, b int );
 
1082
CREATE TABLE t1 ( a int, b int ) ENGINE=MyISAM;
1079
1083
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
1080
1084
SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 );
1081
1085
SELECT a FROM t1 WHERE a < ANY ( SELECT a FROM t1 WHERE b = 2 );
1210
1214
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a < t1.a), '-') from t1 a;
1211
1215
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a = t1.a), '-') from t1 a;
1212
1216
DROP TABLE t1;
1213
 
CREATE TABLE t1 ( a double, b double );
 
1217
CREATE TABLE t1 ( a double, b double ) ENGINE=MyISAM;
1214
1218
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
1215
1219
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2e0);
1216
1220
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2e0);
1225
1229
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2e0);
1226
1230
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2e0);
1227
1231
DROP TABLE t1;
1228
 
CREATE TABLE t1 ( a char(1), b char(1));
 
1232
CREATE TABLE t1 ( a char(1), b char(1)) ENGINE=MyISAM;
1229
1233
INSERT INTO t1 VALUES ('1','1'),('2','2'),('3','3');
1230
1234
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = '2');
1231
1235
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = '2');
1245
1249
#
1246
1250
# SELECT(EXISTS * ...)optimisation
1247
1251
#
1248
 
create table t1 (a int, b int);
 
1252
create table t1 (a int, b int) ENGINE=MyISAM;
1249
1253
insert into t1 values (1,2),(3,4);
1250
1254
select * from t1 up where exists (select * from t1 where t1.a=up.a);
1251
1255
explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
1255
1259
# Bug #4102: subselect in HAVING
1256
1260
#
1257
1261
 
1258
 
CREATE TABLE t1 (t1_a int);
 
1262
CREATE TABLE t1 (t1_a int) ENGINE=MyISAM;
1259
1263
INSERT INTO t1 VALUES (1);
1260
 
CREATE TABLE t2 (t2_a int, t2_b int, PRIMARY KEY (t2_a, t2_b));
 
1264
CREATE TABLE t2 (t2_a int, t2_b int, PRIMARY KEY (t2_a, t2_b)) ENGINE=MyISAM;
1261
1265
INSERT INTO t2 VALUES (1, 1), (1, 2);
1262
1266
SELECT * FROM t1, t2 table2 WHERE t1_a = 1 AND table2.t2_a = 1
1263
1267
  HAVING table2.t2_b = (SELECT MAX(t2_b) FROM t2 WHERE t2_a = table2.t2_a);
1267
1271
# Test problem with NULL and derived tables (Bug #4097)
1268
1272
#
1269
1273
 
1270
 
CREATE TABLE t1 (id int default NULL,name varchar(10) default NULL);
 
1274
CREATE TABLE t1 (id int default NULL,name varchar(10) default NULL) ENGINE=MyISAM;
1271
1275
INSERT INTO t1 VALUES (1,'Tim'),(2,'Rebecca'),(3,NULL);
1272
 
CREATE TABLE t2 (id int default NULL, pet varchar(10) default NULL);
 
1276
CREATE TABLE t2 (id int default NULL, pet varchar(10) default NULL) ENGINE=MyISAM;
1273
1277
INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix');
1274
1278
SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id;
1275
1279
drop table t1,t2;
1277
1281
#
1278
1282
# Aggregate function comparation with ALL/ANY/SOME subselect
1279
1283
#
1280
 
CREATE TABLE `t1` ( `a` int default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 
1284
CREATE TABLE `t1` ( `a` int default NULL) ENGINE=MyISAM;
1281
1285
insert into t1 values (1);
1282
 
CREATE TABLE `t2` ( `b` int default NULL, `a` int default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 
1286
CREATE TABLE `t2` ( `b` int default NULL, `a` int default NULL) ENGINE=MyISAM;
1283
1287
insert into t2 values (1,2);
1284
1288
select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1);
1285
1289
drop table t1,t2;
1287
1291
#
1288
1292
# BUG#5003 - like in subselect
1289
1293
#
1290
 
CREATE TABLE t1(`IZAVORGANG_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`KUERZEL` VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_bin,`IZAANALYSEART_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`IZAPMKZ_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin);
 
1294
CREATE TABLE t1(`IZAVORGANG_ID` VARCHAR(11) COLLATE utf8_bin,`KUERZEL` VARCHAR(10) COLLATE utf8_bin,`IZAANALYSEART_ID` VARCHAR(11) COLLATE utf8_bin,`IZAPMKZ_ID` VARCHAR(11) COLLATE utf8_bin) ENGINE=MyISAM;
1291
1295
CREATE INDEX AK01IZAVORGANG ON t1(izaAnalyseart_id,Kuerzel);
1292
1296
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000001','601','D0000000001','I0000000001');
1293
1297
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000002','602','D0000000001','I0000000001');
1299
1303
#
1300
1304
# Optimized IN with compound index
1301
1305
#
1302
 
CREATE TABLE `t1` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
1303
 
CREATE TABLE `t2` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
 
1306
CREATE TABLE `t1` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`)) ENGINE=MyISAM;
 
1307
CREATE TABLE `t2` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`)) ENGINE=MyISAM;
1304
1308
insert into t1 values (1,1),(1,2),(2,1),(2,2);
1305
1309
insert into t2 values (1,2),(2,2);
1306
1310
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
1315
1319
#
1316
1320
# resolving fields of grouped outer SELECT
1317
1321
#
1318
 
CREATE TABLE t1 (howmanyvalues bigint, avalue int);
 
1322
CREATE TABLE t1 (howmanyvalues bigint, avalue int) ENGINE=MyISAM;
1319
1323
INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4);
1320
1324
SELECT howmanyvalues, count(*) from t1 group by howmanyvalues;
1321
1325
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
1325
1329
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues;
1326
1330
drop table t1;
1327
1331
 
1328
 
create table t1 (x int);
 
1332
create table t1 (x int) ENGINE=MyISAM;
1329
1333
select  (select b.x from t1 as b where b.x=a.x) from t1 as a where a.x=2 group by a.x;
1330
1334
drop table t1;
1331
1335
 
1333
1337
# Test of correct maybe_null flag returning by subquwery for temporary table
1334
1338
# creation
1335
1339
#
1336
 
CREATE TABLE `t1` ( `master` int unsigned NOT NULL default '0', `map` smallint unsigned NOT NULL default '0', `slave` int unsigned NOT NULL default '0', `access` int unsigned NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`));
 
1340
CREATE TABLE `t1` ( `master` int NOT NULL default '0', `map` int NOT NULL default '0', `slave` int NOT NULL default '0', `access` int NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`)) ENGINE=MyISAM;
1337
1341
INSERT INTO `t1` VALUES (1,0,0,700),(1,1,1,400),(1,5,5,400),(1,12,12,400),(1,12,32,400),(4,12,32,400);
1338
 
CREATE TABLE `t2` ( `id` int unsigned NOT NULL default '0', `pid` int unsigned NOT NULL default '0', `map` smallint unsigned NOT NULL default '0', `level` tinyint unsigned NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY  (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ;
 
1342
CREATE TABLE `t2` ( `id` int NOT NULL default '0', `pid` int NOT NULL default '0', `map` int NOT NULL default '0', `level` int NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY  (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ENGINE=MyISAM ;
1339
1343
INSERT INTO `t2` VALUES (6,5,12,7,'a'),(12,0,0,7,'a'),(12,1,0,7,'a'),(12,5,5,7,'a'),(12,5,12,7,'a');
1340
1344
-- error 1054
1341
1345
SELECT b.sc FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b;
1352
1356
#
1353
1357
# primary query with temporary table and subquery with groupping
1354
1358
#
1355
 
create table t1 (a int, b int);
1356
 
create table t2 (a int, b int);
 
1359
create table t1 (a int, b int) ENGINE=MyISAM;
 
1360
create table t2 (a int, b int) ENGINE=MyISAM;
1357
1361
insert into t1 values (1,1),(1,2),(1,3),(2,4),(2,5);
1358
1362
insert into t2 values (1,3),(2,1);
1359
1363
select distinct a,b, (select max(b) from t2 where t1.b=t2.a) from t1 order by t1.b;
1362
1366
#
1363
1367
# Equal operation under row and empty subquery
1364
1368
#
1365
 
create table t1 (s1 int,s2 int);
 
1369
create table t1 (s1 int,s2 int) ENGINE=MyISAM;
1366
1370
insert into t1 values (20,15);
1367
1371
select * from t1 where  (('a',null) <=> (select 'a',s2 from t1 where s1 = 0));
1368
1372
drop table t1;
1370
1374
#
1371
1375
# ALL/ANY with NULL
1372
1376
#
1373
 
create table t1 (s1 int);
 
1377
create table t1 (s1 int) ENGINE=MyISAM;
1374
1378
insert into t1 values (1),(null);
1375
1379
select * from t1 where s1 < all (select s1 from t1);
1376
1380
select s1, s1 < all (select s1 from t1) from t1;
1385
1389
  Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
1386
1390
  Region char(26) NOT NULL default '',
1387
1391
  SurfaceArea float(10,2) NOT NULL default '0.00',
1388
 
  IndepYear smallint default NULL,
 
1392
  IndepYear int default NULL,
1389
1393
  Population int NOT NULL default '0',
1390
1394
  LifeExpectancy float(3,1) default NULL,
1391
1395
  GNP float(10,2) default NULL,
1410
1414
# Test for BUG#7885: Server crash when 'any' subselect compared to
1411
1415
# non-existant field.
1412
1416
#
1413
 
create table t1 (a1 int);
1414
 
create table t2 (b1 int);
 
1417
create table t1 (a1 int) ENGINE=MyISAM;
 
1418
create table t2 (b1 int) ENGINE=MyISAM;
1415
1419
--error 1054
1416
1420
select * from t1 where a2 > any(select b1 from t2);
1417
1421
select * from t1 where a1 > any(select b1 from t2);
1421
1425
#
1422
1426
# Comparison subquery with * and row
1423
1427
#
1424
 
create table t1 (a integer, b integer);
 
1428
create table t1 (a integer, b integer) ENGINE=MyISAM;
1425
1429
select (select * from t1) = (select 1,2);
1426
1430
select (select 1,2) = (select * from t1);
1427
1431
# queries whih can be converted to IN
1432
1436
#
1433
1437
# Comparison subquery and row with nested rows
1434
1438
#
1435
 
create table t1 (a integer, b integer);
 
1439
create table t1 (a integer, b integer) ENGINE=MyISAM;
1436
1440
-- error 1241
1437
1441
select row(1,(2,2)) in (select * from t1 );
1438
1442
-- error 1241
1465
1469
  endDate datetime NOT NULL,
1466
1470
  createDate datetime NOT NULL,
1467
1471
  modifyDate timestamp NOT NULL,
1468
 
  attributes text NOT NULL
1469
 
);
 
1472
  attributes text NOT NULL)
 
1473
  engine=myisam;
 
1474
 
1470
1475
INSERT INTO t1 VALUES (1,41,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''),
1471
1476
(1,86,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
1472
1477
(1,87,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
1480
1485
CREATE TABLE t2 (
1481
1486
  userId int NOT NULL,
1482
1487
  courseId int NOT NULL,
1483
 
  date datetime NOT NULL
1484
 
);
 
1488
  date datetime NOT NULL)
 
1489
  engine=myisam;
 
1490
 
1485
1491
INSERT INTO t2 VALUES (5141,71,'2003-11-18'),
1486
1492
(5141,72,'2003-11-25'),(5141,41,'2004-08-06'),
1487
1493
(5141,52,'2004-08-06'),(5141,53,'2004-08-06'),
1497
1503
  endDate datetime NOT NULL,
1498
1504
  createDate datetime NOT NULL,
1499
1505
  modifyDate timestamp NOT NULL,
1500
 
  ordering int
1501
 
);
 
1506
  ordering int)
 
1507
  engine=myisam;
 
1508
 
1502
1509
INSERT INTO t3 VALUES (12,9,'1000-01-01','3999-12-31','2004-01-29','2004-01-29',NULL);
1503
1510
 
1504
1511
CREATE TABLE t4 (
1509
1516
  ordering int,
1510
1517
  description text,
1511
1518
  createDate datetime NOT NULL,
1512
 
  modifyDate timestamp NOT NULL
1513
 
);
 
1519
  modifyDate timestamp NOT NULL)
 
1520
  engine=myisam;
 
1521
 
1514
1522
INSERT INTO t4 VALUES (9,5,'stationer','stationer',0,'Stationer','2004-01-29','2004-01-29'),
1515
1523
(12,5,'group2','group2',0,'group2','2004-01-29','2004-01-29');
1516
1524
 
1518
1526
  userId int NOT NULL,
1519
1527
  groupId int NOT NULL,
1520
1528
  createDate datetime NOT NULL,
1521
 
  modifyDate timestamp NOT NULL
1522
 
);
 
1529
  modifyDate timestamp NOT NULL) ENGINE=MyISAM;
 
1530
 
1523
1531
INSERT INTO t5 VALUES (5141,12,'2004-08-06','2004-08-06');
1524
1532
 
1525
1533
select
1559
1567
#
1560
1568
# Transformation in left expression of subquery (BUG#8888)
1561
1569
#
1562
 
create table t1 (a int);
 
1570
create table t1 (a int) ENGINE=MyISAM;
1563
1571
insert into t1 values (1), (2), (3);
1564
1572
SELECT 1 FROM t1 WHERE (SELECT 1) in (SELECT 1);
1565
1573
drop table t1;
1567
1575
#
1568
1576
# single row subqueries and row operations (code covarage improvement)
1569
1577
#
1570
 
create table t1 (a int, b int);
 
1578
create table t1 (a int, b int) ENGINE=MyISAM;
1571
1579
insert into t1 values (1,2);
1572
1580
-- error 1241
1573
1581
select 1 = (select * from t1);
1586
1594
#
1587
1595
# Item_int_with_ref check (BUG#10020)
1588
1596
#
1589
 
CREATE TABLE `t1` (
1590
 
  `itemid` bigint unsigned NOT NULL auto_increment,
1591
 
  `sessionid` bigint unsigned default NULL,
1592
 
  `time` int unsigned NOT NULL default '0',
1593
 
  `data` text collate latin1_general_ci NOT NULL,
1594
 
  PRIMARY KEY  (`itemid`)
1595
 
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
1596
 
INSERT INTO `t1` VALUES (1, 1, 1, '');
1597
 
CREATE TABLE `t2` (
1598
 
  `sessionid` bigint unsigned NOT NULL auto_increment,
1599
 
  `pid` int unsigned NOT NULL default '0',
1600
 
  `date` int unsigned NOT NULL default '0',
1601
 
  `ip` varchar(15) collate latin1_general_ci NOT NULL default '',
1602
 
  PRIMARY KEY  (`sessionid`)
1603
 
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
1604
 
INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
1605
 
SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30;
1606
 
drop tables t1,t2;
 
1597
#CREATE TABLE `t1` (
 
1598
#  `itemid` bigint NOT NULL auto_increment,
 
1599
#  `sessionid` bigint default NULL,
 
1600
#  `time` int NOT NULL default '0',
 
1601
#  `data` text collate latin1_general_ci NOT NULL,
 
1602
#  PRIMARY KEY  (`itemid`)
 
1603
#);
 
1604
#INSERT INTO `t1` VALUES (1, 1, 1, '');
 
1605
#CREATE TABLE `t2` (
 
1606
#  `sessionid` bigint NOT NULL auto_increment,
 
1607
#  `pid` int NOT NULL default '0',
 
1608
#  `date` int NOT NULL default '0',
 
1609
#  `ip` varchar(15) collate latin1_general_ci NOT NULL default '',
 
1610
#  PRIMARY KEY  (`sessionid`)
 
1611
#);
 
1612
#INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
 
1613
#SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30;
 
1614
#drop tables t1,t2;
1607
1615
 
1608
1616
# BUG#11821 : Select from subselect using aggregate function on an enum
1609
1617
# segfaults:
1610
 
create table t1 (fld enum('0','1'));
 
1618
create table t1 (fld enum('0','1')) ENGINE=MyISAM;
1611
1619
insert into t1 values ('1');
1612
1620
select * from (select max(fld) from t1) as foo;
1613
1621
drop table t1;
1616
1624
# Bug #11867: queries with ROW(,elems>) IN (SELECT DISTINCT <cols> FROM ...)
1617
1625
#
1618
1626
 
1619
 
CREATE TABLE t1 (one int, two int, flag char(1));
1620
 
CREATE TABLE t2 (one int, two int, flag char(1));
 
1627
CREATE TABLE t1 (one int, two int, flag char(1)) ENGINE=MyISAM;
 
1628
CREATE TABLE t2 (one int, two int, flag char(1)) ENGINE=MyISAM;
1621
1629
INSERT INTO t1 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
1622
1630
INSERT INTO t2 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
1623
1631
 
1647
1655
# Bug #12392: where cond with IN predicate for rows and NULL values in table 
1648
1656
#
1649
1657
 
1650
 
CREATE TABLE t1 (a char(5), b char(5));
 
1658
CREATE TABLE t1 (a char(5), b char(5)) ENGINE=MyISAM;
1651
1659
INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
1652
1660
 
1653
1661
SELECT * FROM t1 WHERE (a,b) IN (('aaa','aaa'), ('aaa','bbb'));
1658
1666
# Bug #11479: subquery over left join with an empty inner table 
1659
1667
#
1660
1668
 
1661
 
CREATE TABLE t1 (a int);
1662
 
CREATE TABLE t2 (a int, b int);
1663
 
CREATE TABLE t3 (b int NOT NULL);
 
1669
CREATE TABLE t1 (a int) ENGINE=MyISAM;
 
1670
CREATE TABLE t2 (a int, b int) ENGINE=MyISAM;
 
1671
CREATE TABLE t3 (b int NOT NULL) ENGINE=MyISAM;
1664
1672
INSERT INTO t1 VALUES (1), (2), (3), (4);
1665
1673
INSERT INTO t2 VALUES (1,10), (3,30);
1666
1674
 
1676
1684
# Bug#18503: Queries with a quantified subquery returning empty set may
1677
1685
# return a wrong result. 
1678
1686
#
1679
 
CREATE TABLE t1 (f1 INT);
1680
 
CREATE TABLE t2 (f2 INT);
 
1687
CREATE TABLE t1 (f1 INT) ENGINE=MyISAM;
 
1688
CREATE TABLE t2 (f2 INT) ENGINE=MyISAM;
1681
1689
INSERT INTO t1 VALUES (1);
1682
1690
SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2);
1683
1691
SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE 1=0);
1687
1695
DROP TABLE t1, t2;
1688
1696
 
1689
1697
# BUG#20975 Wrong query results for subqueries within NOT
1690
 
create table t1 (s1 char);
 
1698
create table t1 (s1 char) ENGINE=MyISAM;
1691
1699
insert into t1 values (1),(2);
1692
1700
 
1693
1701
select * from t1 where (s1 < any (select s1 from t1));
1708
1716
#
1709
1717
create table t1 (
1710
1718
  retailerID varchar(8) NOT NULL,
1711
 
  statusID   int unsigned NOT NULL,
 
1719
  statusID   int NOT NULL,
1712
1720
  changed    datetime NOT NULL,
1713
 
  UNIQUE KEY retailerID (retailerID, statusID, changed)
1714
 
);
 
1721
  UNIQUE KEY retailerID (retailerID, statusID, changed))
 
1722
  ENGINE=MyISAM;
1715
1723
 
1716
1724
INSERT INTO t1 VALUES("0026", "1", "2005-12-06 12:18:56");
1717
1725
INSERT INTO t1 VALUES("0026", "2", "2006-01-06 12:25:53");
1730
1738
# Bug #21180: Subselect with index for both WHERE and ORDER BY 
1731
1739
#             produces empty result
1732
1740
#
1733
 
create table t1(a int, primary key (a));
 
1741
create table t1(a int, primary key (a)) ENGINE=MyISAM;
1734
1742
insert into t1 values (10);
1735
1743
 
1736
 
create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
 
1744
create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)) ENGINE=MyISAM;
1737
1745
insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
1738
1746
 
1739
1747
explain SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r 
1761
1769
  field1 int NOT NULL,                 
1762
1770
  field2 int NOT NULL,                 
1763
1771
  field3 int NOT NULL,                 
1764
 
  PRIMARY KEY  (field1,field2,field3)  
1765
 
);
 
1772
  PRIMARY KEY  (field1,field2,field3))
 
1773
  ENGINE=MyISAM;
 
1774
 
1766
1775
CREATE TABLE t2 (             
1767
1776
  fieldA int NOT NULL,            
1768
1777
  fieldB int NOT NULL,            
1769
 
  PRIMARY KEY  (fieldA,fieldB)     
1770
 
); 
 
1778
  PRIMARY KEY  (fieldA,fieldB))
 
1779
  ENGINE=MyISAM;
1771
1780
 
1772
1781
INSERT INTO t1 VALUES
1773
1782
  (1,1,1), (1,1,2), (1,2,1), (1,2,2), (1,2,3), (1,3,1);
1794
1803
#             with possible NULL values by index access from the outer query
1795
1804
#
1796
1805
 
1797
 
CREATE TABLE t1(a int, INDEX (a));
 
1806
CREATE TABLE t1(a int, INDEX (a)) ENGINE=MyISAM;
1798
1807
INSERT INTO t1 VALUES (1), (3), (5), (7);
1799
1808
INSERT INTO t1 VALUES (NULL);
1800
1809
 
1801
 
CREATE TABLE t2(a int);
 
1810
CREATE TABLE t2(a int) ENGINE=MyISAM;
1802
1811
INSERT INTO t2 VALUES (1),(2),(3);
1803
1812
 
1804
1813
EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2;
1809
1818
#
1810
1819
# Bug #11302: getObject() returns a String for a sub-query of type datetime
1811
1820
#
1812
 
CREATE TABLE t1 (a DATETIME);
 
1821
CREATE TABLE t1 (a DATETIME) ENGINE=MyISAM;
1813
1822
INSERT INTO t1 VALUES ('1998-09-23'), ('2003-03-25');
1814
1823
 
1815
 
CREATE TABLE t2 AS SELECT 
 
1824
CREATE TABLE t2 ENGINE=MyISAM AS SELECT 
1816
1825
  (SELECT a FROM t1 WHERE a < '2000-01-01') AS sub_a 
1817
1826
   FROM t1 WHERE a > '2000-01-01';
1818
1827
SHOW CREATE TABLE t2;
1819
1828
 
1820
 
CREATE TABLE t3 AS (SELECT a FROM t1 WHERE a < '2000-01-01') UNION (SELECT a FROM t1 WHERE a > '2000-01-01'); 
 
1829
CREATE TABLE t3 ENGINE=MyISAM AS (SELECT a FROM t1 WHERE a < '2000-01-01') UNION (SELECT a FROM t1 WHERE a > '2000-01-01'); 
1821
1830
SHOW CREATE TABLE t3;
1822
1831
 
1823
1832
DROP TABLE t1,t2,t3;
1827
1836
#            that return more than one row
1828
1837
#
1829
1838
 
1830
 
CREATE TABLE t1 (a int);
 
1839
CREATE TABLE t1 (a int) ENGINE=MyISAM;
1831
1840
INSERT INTO t1 VALUES (2), (4), (1), (3);
1832
1841
 
1833
 
CREATE TABLE t2 (b int, c int);
 
1842
CREATE TABLE t2 (b int, c int) ENGINE=MyISAM;
1834
1843
INSERT INTO t2 VALUES
1835
1844
  (2,1), (1,3), (2,1), (4,4), (2,2), (1,4);
1836
1845
 
1885
1894
#
1886
1895
#decimal-related tests
1887
1896
#
1888
 
create table t1 (df decimal(5,1));
 
1897
create table t1 (df decimal(5,1)) ENGINE=MyISAM;
1889
1898
insert into t1 values(1.1);
1890
1899
insert into t1 values(2.2);
1891
1900
 
1893
1902
select * from t1 where df >= all (select avg(df) from t1 group by df);
1894
1903
drop table t1;
1895
1904
 
1896
 
create table t1 (df decimal(5,1));
 
1905
create table t1 (df decimal(5,1)) ENGINE=MyISAM;
1897
1906
insert into t1 values(1.1);
1898
1907
select 1.1 * exists(select * from t1);
1899
1908
drop table t1;
1900
1909
 
1901
1910
CREATE TABLE t1 (
1902
1911
  grp int default NULL,
1903
 
  a decimal(10,2) default NULL);
 
1912
  a decimal(10,2) default NULL) ENGINE=MyISAM;
1904
1913
 
1905
1914
insert into t1 values (1, 1), (2, 2), (2, 3), (3, 4), (3, 5), (3, 6), (NULL, NULL);
1906
1915
select * from t1;
1911
1920
# Test for bug #9338: lame substitution of c1 instead of c2 
1912
1921
#
1913
1922
 
1914
 
CREATE table t1 ( c1 integer );
 
1923
CREATE table t1 ( c1 integer ) ENGINE=MyISAM;
1915
1924
INSERT INTO t1 VALUES ( 1 );
1916
1925
INSERT INTO t1 VALUES ( 2 );
1917
1926
INSERT INTO t1 VALUES ( 3 );
1918
1927
 
1919
 
CREATE TABLE t2 ( c2 integer );
 
1928
CREATE TABLE t2 ( c2 integer ) ENGINE=MyISAM;
1920
1929
INSERT INTO t2 VALUES ( 1 );
1921
1930
INSERT INTO t2 VALUES ( 4 );
1922
1931
INSERT INTO t2 VALUES ( 5 );
1931
1940
#
1932
1941
# Test for bug #9516: wrong evaluation of not_null_tables attribute in SQ 
1933
1942
#
1934
 
CREATE TABLE t1 ( c1 integer );
 
1943
CREATE TABLE t1 ( c1 integer ) ENGINE=MyISAM;
1935
1944
INSERT INTO t1 VALUES ( 1 );
1936
1945
INSERT INTO t1 VALUES ( 2 );
1937
1946
INSERT INTO t1 VALUES ( 3 );
1938
1947
INSERT INTO t1 VALUES ( 6 ); 
1939
1948
 
1940
 
CREATE TABLE t2 ( c2 integer );
 
1949
CREATE TABLE t2 ( c2 integer ) ENGINE=MyISAM;
1941
1950
INSERT INTO t2 VALUES ( 1 );
1942
1951
INSERT INTO t2 VALUES ( 4 );
1943
1952
INSERT INTO t2 VALUES ( 5 );
1944
1953
INSERT INTO t2 VALUES ( 6 );
1945
1954
 
1946
 
CREATE TABLE t3 ( c3 integer );
 
1955
CREATE TABLE t3 ( c3 integer ) ENGINE=MyISAM;
1947
1956
INSERT INTO t3 VALUES ( 7 );
1948
1957
INSERT INTO t3 VALUES ( 8 );
1949
1958
 
1956
1965
# Correct building of equal fields list (do not include outer
1957
1966
# fields) (BUG#6384)
1958
1967
#
1959
 
CREATE TABLE t1 (EMPNUM   CHAR(3));
1960
 
CREATE TABLE t2 (EMPNUM   CHAR(3) );
 
1968
CREATE TABLE t1 (EMPNUM   CHAR(3)) ENGINE=MyISAM;
 
1969
CREATE TABLE t2 (EMPNUM   CHAR(3) ) ENGINE=MyISAM;
1961
1970
INSERT INTO t1 VALUES ('E1'),('E2');
1962
1971
INSERT INTO t2 VALUES ('E1');
1963
1972
DELETE FROM t1
1972
1981
# Test for bug #11487: range access in a subquery
1973
1982
#
1974
1983
 
1975
 
CREATE TABLE t1(select_id BIGINT, values_id BIGINT);
 
1984
CREATE TABLE t1(select_id BIGINT, values_id BIGINT) ENGINE=MyISAM;
1976
1985
INSERT INTO t1 VALUES (1, 1);
1977
1986
CREATE TABLE t2 (select_id BIGINT, values_id BIGINT, 
1978
 
                 PRIMARY KEY(select_id,values_id));
 
1987
                 PRIMARY KEY(select_id,values_id)) ENGINE=MyISAM;
1979
1988
INSERT INTO t2 VALUES (0, 1), (0, 2), (0, 3), (1, 5);
1980
1989
 
1981
1990
SELECT values_id FROM t1 
1992
2001
 
1993
2002
# BUG#11821 : Select from subselect using aggregate function on an enum
1994
2003
# segfaults:
1995
 
create table t1 (fld enum('0','1'));
 
2004
create table t1 (fld enum('0','1')) ENGINE=MyISAM;
1996
2005
insert into t1 values ('1');
1997
2006
select * from (select max(fld) from t1) as foo;
1998
2007
drop table t1;
2001
2010
# Test for bug #11762: subquery with an aggregate function in HAVING
2002
2011
#
2003
2012
 
2004
 
CREATE TABLE t1 (a int, b int);
2005
 
CREATE TABLE t2 (c int, d int);
2006
 
CREATE TABLE t3 (e int);
 
2013
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
 
2014
CREATE TABLE t2 (c int, d int) ENGINE=MyISAM;
 
2015
CREATE TABLE t3 (e int) ENGINE=MyISAM;
2007
2016
 
2008
2017
INSERT INTO t1 VALUES 
2009
2018
  (1,10), (2,10), (1,20), (2,20), (3,20), (2,30), (4,40);
2085
2094
# Test for bug #16603: GROUP BY in a row subquery with a quantifier 
2086
2095
#                      when an index is defined on the grouping field
2087
2096
 
2088
 
CREATE TABLE t1 (a varchar(5), b varchar(10));
 
2097
CREATE TABLE t1 (a varchar(5), b varchar(10)) ENGINE=MyISAM;
2089
2098
INSERT INTO t1 VALUES
2090
2099
  ('AAA', 5), ('BBB', 4), ('BBB', 1), ('CCC', 2),
2091
2100
  ('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8);
2105
2114
#
2106
2115
# Bug#17366: Unchecked Item_int results in server crash
2107
2116
#
2108
 
create table t1( f1 int,f2 int);
 
2117
create table t1( f1 int,f2 int) ENGINE=MyISAM;
2109
2118
insert into t1 values (1,1),(2,2);
2110
2119
select tt.t from (select 'crash1' as t, f2 from t1) as tt left join t1 on tt.t = 'crash2' and tt.f2 = t1.f2 where tt.t = 'crash1';
2111
2120
drop table t1;
2114
2123
# Bug #18306: server crash on delete using subquery.
2115
2124
#
2116
2125
 
2117
 
create table t1 (c int, key(c));                              
 
2126
create table t1 (c int, key(c)) ENGINE=MyISAM;                              
2118
2127
insert into t1 values (1142477582), (1142455969);
2119
 
create table t2 (a int, b int);
 
2128
create table t2 (a int, b int) ENGINE=MyISAM;
2120
2129
insert into t2 values (2, 1), (1, 0);
2121
2130
delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1;
2122
2131
drop table t1, t2;
2124
2133
#
2125
2134
# Bug#19077: A nested materialized derived table is used before being populated.
2126
2135
#
2127
 
create table t1 (i int, j bigint);
 
2136
create table t1 (i int, j bigint) ENGINE=MyISAM;
2128
2137
insert into t1 values (1, 2), (2, 2), (3, 2);
2129
2138
select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3;
2130
2139
drop table t1;
2132
2141
2133
2142
# Bug#19700: subselect returning BIGINT always returned it as SIGNED
2134
2143
#
2135
 
CREATE TABLE t1 (i BIGINT UNSIGNED);
2136
 
INSERT INTO t1 VALUES (10000000000000000000); # > MAX SIGNED BIGINT 9323372036854775807
 
2144
CREATE TABLE t1 (i BIGINT) ENGINE=MyISAM;
 
2145
INSERT INTO t1 VALUES (10000000000000000); # > MAX SIGNED BIGINT 9323372036854775807
2137
2146
INSERT INTO t1 VALUES (1);
2138
2147
 
2139
 
CREATE TABLE t2 (i BIGINT UNSIGNED);
2140
 
INSERT INTO t2 VALUES (10000000000000000000); # same as first table
 
2148
CREATE TABLE t2 (i BIGINT) ENGINE=MyISAM;
 
2149
INSERT INTO t2 VALUES (10000000000000000); # same as first table
2141
2150
INSERT INTO t2 VALUES (1);
2142
2151
 
2143
2152
/* simple test */
2147
2156
SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2);
2148
2157
 
2149
2158
/* subquery test with cast*/
2150
 
SELECT t1.i FROM t1 WHERE t1.i = CAST((SELECT MAX(i) FROM t2) AS UNSIGNED);
 
2159
SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2);
2151
2160
 
2152
2161
DROP TABLE t1;
2153
2162
DROP TABLE t2;
2157
2166
#
2158
2167
 
2159
2168
CREATE TABLE t1 (
2160
 
  id bigint unsigned NOT NULL auto_increment,
 
2169
  id bigint NOT NULL auto_increment,
2161
2170
  name varchar(255) NOT NULL,
2162
 
  PRIMARY KEY  (id)
2163
 
);
 
2171
  PRIMARY KEY  (id))
 
2172
  ENGINE=MyISAM;
 
2173
 
2164
2174
INSERT INTO t1 VALUES
2165
2175
  (1, 'Balazs'), (2, 'Joe'), (3, 'Frank');
2166
2176
 
2167
2177
CREATE TABLE t2 (
2168
 
  id bigint unsigned NOT NULL auto_increment,
2169
 
  mid bigint unsigned NOT NULL,
 
2178
  id bigint NOT NULL auto_increment,
 
2179
  mid bigint NOT NULL,
2170
2180
  date date NOT NULL,
2171
 
  PRIMARY KEY  (id)
2172
 
);
 
2181
  PRIMARY KEY  (id))
 
2182
  ENGINE=MyISAM;
 
2183
 
2173
2184
INSERT INTO t2 VALUES 
2174
2185
  (1, 1, '2006-03-30'), (2, 2, '2006-04-06'), (3, 3, '2006-04-13'),
2175
2186
  (4, 2, '2006-04-20'), (5, 1, '2006-05-01');
2199
2210
CREATE TABLE t1 (
2200
2211
  i1 int NOT NULL default '0',
2201
2212
  i2 int NOT NULL default '0',
2202
 
  t datetime NOT NULL default '0000-00-00 00:00:00',
2203
 
  PRIMARY KEY  (i1,i2,t)
2204
 
);
 
2213
  t datetime,
 
2214
  PRIMARY KEY  (i1,i2,t))
 
2215
  ENGINE=MyISAM;
 
2216
 
2205
2217
INSERT INTO t1 VALUES 
2206
2218
(24,1,'2005-03-03 16:31:31'),(24,1,'2005-05-27 12:40:07'),
2207
2219
(24,1,'2005-05-27 12:40:08'),(24,1,'2005-05-27 12:40:10'),
2214
2226
  i1 int NOT NULL default '0',
2215
2227
  i2 int NOT NULL default '0',
2216
2228
  t datetime default NULL,
2217
 
  PRIMARY KEY  (i1)
2218
 
);
 
2229
  PRIMARY KEY  (i1))
 
2230
  ENGINE=MyISAM;
 
2231
 
2219
2232
INSERT INTO t2 VALUES (24,1,'2006-06-20 12:29:40');
2220
2233
 
2221
2234
EXPLAIN
2234
2247
# Bug#14654 : Cannot select from the same table twice within a UNION
2235
2248
# statement 
2236
2249
#
2237
 
CREATE TABLE t1 (i INT);
 
2250
CREATE TABLE t1 (i INT) ENGINE=MyISAM;
2238
2251
 
2239
2252
(SELECT i FROM t1) UNION (SELECT i FROM t1);
2240
2253
SELECT * FROM t1 WHERE NOT EXISTS 
2261
2274
#
2262
2275
# Bug #21540: Subqueries with no from and aggregate functions return 
2263
2276
#              wrong results
2264
 
CREATE TABLE t1 (a INT, b INT);
2265
 
CREATE TABLE t2 (a INT);
 
2277
CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM;
 
2278
CREATE TABLE t2 (a INT) ENGINE=MyISAM;
2266
2279
INSERT INTO t2 values (1);
2267
2280
INSERT INTO t1 VALUES (1,1),(1,2),(2,3),(3,4);
2268
2281
SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a;
2285
2298
#             slow with big sort_buffer_size 
2286
2299
#
2287
2300
 
2288
 
CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b));
 
2301
CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b)) ENGINE=MyISAM;
2289
2302
CREATE TABLE t2 (x int auto_increment, y int, z int,
2290
 
                 PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b));
 
2303
                 PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b)) ENGINE=MyISAM;
2291
2304
disable_query_log;
2292
2305
set autocommit=0;
2293
2306
begin;
2325
2338
#             correlated and uncorrelated selects
2326
2339
#
2327
2340
 
2328
 
CREATE TABLE t1 (id char(4) PRIMARY KEY, c int);
2329
 
CREATE TABLE t2 (c int);
 
2341
CREATE TABLE t1 (id char(4) PRIMARY KEY, c int) ENGINE=MyISAM;
 
2342
CREATE TABLE t2 (c int) ENGINE=MyISAM;
2330
2343
 
2331
2344
INSERT INTO t1 VALUES ('aa', 1);
2332
2345
INSERT INTO t2 VALUES (1);
2344
2357
                SELECT c from t2 WHERE c=t1.c);
2345
2358
 
2346
2359
INSERT INTO t2 VALUES (2);
2347
 
CREATE TABLE t3 (c int);
 
2360
CREATE TABLE t3 (c int) ENGINE=MyISAM;
2348
2361
INSERT INTO t3 VALUES (1);
2349
2362
 
2350
2363
SELECT * FROM t1
2366
2379
 
2367
2380
CREATE TABLE t1 (
2368
2381
  id_1 int NOT NULL,
2369
 
  t varchar(4) DEFAULT NULL
2370
 
);
 
2382
  t varchar(4) DEFAULT NULL)
 
2383
  ENGINE=MyISAM;
2371
2384
 
2372
2385
CREATE TABLE t2 (
2373
2386
  id_2 int NOT NULL,
2374
 
  t varchar(4) DEFAULT NULL
2375
 
);
 
2387
  t varchar(4) DEFAULT NULL)
 
2388
  ENGINE=MyISAM;
2376
2389
 
2377
2390
CREATE TABLE t1xt2 (
2378
2391
  id_1 int NOT NULL,
2379
 
  id_2 int NOT NULL
2380
 
);
 
2392
  id_2 int NOT NULL)
 
2393
  ENGINE=MyISAM;
2381
2394
 
2382
2395
INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd');
2383
2396
 
2457
2470
# Bug #26728: derived table with concatanation of literals in select list
2458
2471
#  
2459
2472
 
2460
 
CREATE TABLE t1 (a int);
 
2473
CREATE TABLE t1 (a int) ENGINE=MyISAM;
2461
2474
INSERT INTO t1 VALUES (3), (1), (2);           
2462
2475
 
2463
2476
SELECT 'this is ' 'a test.' AS col1, a AS col2 FROM t1;
2469
2482
# Bug #27257: COUNT(*) aggregated in outer query
2470
2483
#  
2471
2484
 
2472
 
CREATE TABLE t1 (a int, b int);
2473
 
CREATE TABLE t2 (m int, n int);
 
2485
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
 
2486
CREATE TABLE t2 (m int, n int) ENGINE=MyISAM;
2474
2487
INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
2475
2488
INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
2476
2489
 
2492
2505
# Bug #27229: GROUP_CONCAT in subselect with COUNT() as an argument 
2493
2506
#  
2494
2507
 
2495
 
CREATE TABLE t1 (a int, b int);
2496
 
CREATE TABLE t2 (m int, n int);
 
2508
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
 
2509
CREATE TABLE t2 (m int, n int) ENGINE=MyISAM;
2497
2510
INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
2498
2511
INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
2499
2512
 
2510
2523
#
2511
2524
# Bug#27321: Wrong subquery result in a grouping select
2512
2525
#
2513
 
CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b));
 
2526
CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b)) ENGINE=MyISAM;
2514
2527
INSERT INTO t1 VALUES (1,1,0,'a'), (1,2,0,'b'), (1,3,0,'c'), (1,4,0,'d'),
2515
2528
(1,5,0,'e'), (2,1,0,'f'), (2,2,0,'g'), (2,3,0,'h'), (3,4,0,'i'), (3,3,0,'j'),
2516
2529
(3,2,0,'k'), (3,1,0,'l'), (1,9,0,'m'), (1,0,10,'n'), (2,0,5,'o'), (3,0,7,'p');
2548
2561
# Bug #27363: nested aggregates in outer, subquery / sum(select
2549
2562
# count(outer))
2550
2563
#
2551
 
CREATE TABLE t1 (a INT); INSERT INTO t1 values (1),(1),(1),(1);
2552
 
CREATE TABLE t2 (x INT); INSERT INTO t1 values (1000),(1001),(1002);
 
2564
CREATE TABLE t1 (a INT) ENGINE=MyISAM; INSERT INTO t1 values (1),(1),(1),(1);
 
2565
CREATE TABLE t2 (x INT) ENGINE=MyISAM; INSERT INTO t1 values (1000),(1001),(1002);
2553
2566
 
2554
2567
--error ER_INVALID_GROUP_FUNC_USE
2555
2568
SELECT SUM( (SELECT COUNT(a) FROM t2) ) FROM t1;
2571
2584
#
2572
2585
# Bug #27807: Server crash when executing subquery with EXPLAIN
2573
2586
#  
2574
 
CREATE TABLE t1 (a int, b int, KEY (a)); 
 
2587
CREATE TABLE t1 (a int, b int, KEY (a)) ENGINE=MyISAM; 
2575
2588
INSERT INTO t1 VALUES (1,1),(2,1);
2576
2589
EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b);
2577
2590
DROP TABLE t1;
2580
2593
# Bug #28377: grouping query with a correlated subquery in WHERE condition
2581
2594
#  
2582
2595
 
2583
 
CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id));
 
2596
CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)) ENGINE=MyISAM;
2584
2597
INSERT INTO t1 VALUES
2585
2598
  (3,'FL'), (2,'GA'), (4,'FL'), (1,'GA'), (5,'NY'), (7,'FL'), (6,'NY');
2586
 
CREATE TABLE t2 (id int NOT NULL, INDEX idx(id));
 
2599
CREATE TABLE t2 (id int NOT NULL, INDEX idx(id)) ENGINE=MyISAM;
2587
2600
INSERT INTO t2 VALUES (7), (5), (1), (3);
2588
2601
 
2589
2602
SELECT id, st FROM t1 
2605
2618
#             over a grouping subselect
2606
2619
2607
2620
 
2608
 
CREATE TABLE t1 (a int);
 
2621
CREATE TABLE t1 (a int) ENGINE=MyISAM;
2609
2622
 
2610
2623
INSERT INTO t1 VALUES (1), (2);
2611
2624
 
2621
2634
CREATE TABLE t1 (
2622
2635
  a varchar(255) default NULL,
2623
2636
  b timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2624
 
  INDEX idx(a,b)
2625
 
);
 
2637
  INDEX idx(a,b))
 
2638
  ENGINE=MyISAM;
 
2639
 
2626
2640
CREATE TABLE t2 (
2627
 
  a varchar(255) default NULL
2628
 
);
 
2641
  a varchar(255) default NULL)
 
2642
  ENGINE=MyISAM;
2629
2643
 
2630
2644
INSERT INTO t1 VALUES ('abcdefghijk','2007-05-07 06:00:24');
2631
2645
INSERT INTO t1 SELECT * FROM t1;
2651
2665
# Bug #27333: subquery grouped for aggregate of outer query / no aggregate
2652
2666
# of subquery
2653
2667
#
2654
 
CREATE TABLE t1 (a INTEGER, b INTEGER);
2655
 
CREATE TABLE t2 (x INTEGER);
 
2668
CREATE TABLE t1 (a INTEGER, b INTEGER) ENGINE=MyISAM;
 
2669
CREATE TABLE t2 (x INTEGER) ENGINE=MyISAM;
2656
2670
INSERT INTO t1 VALUES (1,11), (2,22), (2,22);
2657
2671
INSERT INTO t2 VALUES (1), (2);
2658
2672
 
2668
2682
DROP TABLE t1,t2;
2669
2683
 
2670
2684
# second test case from 27333
2671
 
CREATE TABLE t1 (a INT, b INT);
 
2685
CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM;
2672
2686
INSERT INTO t1 VALUES (1, 2), (1,3), (1,4), (2,1), (2,2);
2673
2687
 
2674
2688
# returns no rows, when it should
2678
2692
DROP TABLE t1;
2679
2693
 
2680
2694
#test cases from 29297
2681
 
CREATE TABLE t1 (a INT);
2682
 
CREATE TABLE t2 (a INT);
 
2695
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
 
2696
CREATE TABLE t2 (a INT) ENGINE=MyISAM;
2683
2697
INSERT INTO t1 VALUES (1),(2);
2684
2698
INSERT INTO t2 VALUES (1),(2);
2685
2699
SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=0) FROM t1;
2692
2706
# Bug #31884: Assertion + crash in subquery in the SELECT clause.
2693
2707
#
2694
2708
 
2695
 
CREATE TABLE t1 (a1 INT, a2 INT);
2696
 
CREATE TABLE t2 (b1 INT, b2 INT);
 
2709
CREATE TABLE t1 (a1 INT, a2 INT) ENGINE=MyISAM;
 
2710
CREATE TABLE t2 (b1 INT, b2 INT) ENGINE=MyISAM;
2697
2711
 
2698
2712
INSERT INTO t1 VALUES (100, 200);
2699
2713
INSERT INTO t1 VALUES (101, 201);
2707
2721
# Bug #30788: Inconsistent retrieval of char/varchar
2708
2722
#
2709
2723
 
2710
 
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10));
 
2724
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10)) ENGINE=MyISAM;
2711
2725
INSERT INTO t1 VALUES ('a', 'aa');
2712
2726
INSERT INTO t1 VALUES ('a', 'aaa');
2713
2727
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
2716
2730
EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
2717
2731
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
2718
2732
 
2719
 
CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10));
 
2733
CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10)) ENGINE=MyISAM;
2720
2734
INSERT INTO t2 SELECT * FROM t1;
2721
2735
CREATE INDEX I1 ON t2 (a);
2722
2736
CREATE INDEX I2 ON t2 (b);
2733
2747
# occasions
2734
2748
#
2735
2749
 
2736
 
CREATE TABLE t1(a INT, b INT);
 
2750
CREATE TABLE t1(a INT, b INT) ENGINE=MyISAM;
2737
2751
INSERT INTO t1 VALUES (1,1), (1,2), (2,3), (2,4);
2738
2752
 
2739
2753
--error ER_BAD_FIELD_ERROR
2763
2777
# Bug #32036: EXISTS within a WHERE clause with a UNION crashes MySQL 5.122
2764
2778
#
2765
2779
 
2766
 
CREATE TABLE t1 (a INT);
2767
 
CREATE TABLE t2 (a INT);
 
2780
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
 
2781
CREATE TABLE t2 (a INT) ENGINE=MyISAM;
2768
2782
 
2769
2783
INSERT INTO t1 VALUES (1),(2);
2770
2784
INSERT INTO t2 VALUES (1),(2);
2786
2800
CREATE TABLE t4 (
2787
2801
  f7 varchar(32) collate utf8_bin NOT NULL default '',
2788
2802
  f10 varchar(32) collate utf8_bin default NULL,
2789
 
  PRIMARY KEY  (f7)
2790
 
);
 
2803
  PRIMARY KEY  (f7))
 
2804
  ENGINE=MyISAM;
 
2805
 
2791
2806
INSERT INTO t4 VALUES(1,1), (2,null);
2792
2807
 
2793
2808
CREATE TABLE t2 (
2795
2810
  f2 varchar(50) collate utf8_bin default NULL,
2796
2811
  f3 varchar(10) collate utf8_bin default NULL,
2797
2812
  PRIMARY KEY  (f4),
2798
 
  UNIQUE KEY uk1 (f2)
2799
 
);
 
2813
  UNIQUE KEY uk1 (f2))
 
2814
  ENGINE=MyISAM;
 
2815
 
2800
2816
INSERT INTO t2 VALUES(1,1,null), (2,2,null);
2801
2817
 
2802
 
CREATE TABLE t1 (
 
2818
CREATE TABLE t1  (
2803
2819
  f8 varchar(32) collate utf8_bin NOT NULL default '',
2804
2820
  f1 varchar(10) collate utf8_bin default NULL,
2805
2821
  f9 varchar(32) collate utf8_bin default NULL,
2806
 
  PRIMARY KEY  (f8)
2807
 
);
 
2822
  PRIMARY KEY  (f8))
 
2823
  ENGINE=MyISAM;
 
2824
 
2808
2825
INSERT INTO t1 VALUES (1,'P',1), (2,'P',1), (3,'R',2);
2809
2826
 
2810
2827
CREATE TABLE t3 (
2811
2828
  f6 varchar(32) collate utf8_bin NOT NULL default '',
2812
2829
  f5 varchar(50) collate utf8_bin default NULL,
2813
 
  PRIMARY KEY (f6)
2814
 
);
 
2830
  PRIMARY KEY (f6))
 
2831
  ENGINE=MyISAM;
 
2832
 
2815
2833
INSERT INTO t3 VALUES (1,null), (2,null);
2816
2834
 
2817
2835
SELECT
2841
2859
#
2842
2860
 
2843
2861
create table t_out (subcase char(3),
2844
 
                    a1 char(2), b1 char(2), c1 char(2));
2845
 
create table t_in  (a2 char(2), b2 char(2), c2 char(2));
 
2862
                    a1 char(2), b1 char(2), c1 char(2)) ENGINE=MyISAM;
 
2863
create table t_in  (a2 char(2), b2 char(2), c2 char(2)) ENGINE=MyISAM;
2846
2864
 
2847
2865
insert into t_out values ('A.1','2a', NULL, '2a');
2848
2866
#------------------------- A.2 - impossible
3016
3034
#
3017
3035
# Bug#20835 (literal string with =any values)
3018
3036
#
3019
 
CREATE TABLE t1 (s1 char(1));
 
3037
CREATE TABLE t1 (s1 char(1)) ENGINE=MyISAM;
3020
3038
INSERT INTO t1 VALUES ('a');
3021
 
SELECT * FROM t1 WHERE _utf8'a' = ANY (SELECT s1 FROM t1);
 
3039
SELECT * FROM t1 WHERE 'a' = ANY (SELECT s1 FROM t1);
3022
3040
DROP TABLE t1;
3023
3041
 
3024
3042
#
3025
3043
# Bug#33204: INTO is allowed in subselect, causing inconsistent results
3026
3044
#
3027
 
CREATE TABLE t1( a INT );
 
3045
CREATE TABLE t1( a INT ) ENGINE=MyISAM;
3028
3046
INSERT INTO t1 VALUES (1),(2);
3029
3047
 
3030
 
CREATE TABLE t2( a INT, b INT );
 
3048
CREATE TABLE t2( a INT, b INT ) ENGINE=MyISAM;
3031
3049
 
3032
3050
--error ER_PARSE_ERROR
3033
3051
SELECT *