~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysql-test/t/subselect.test

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

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) 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;
 
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);
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) ENGINE=MyISAM;
 
114
create table t5 (a int);
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)) ENGINE=MyISAM;
124
 
create table t7( uq int primary key, name char(25)) ENGINE=MyISAM;
 
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));
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') ENGINE=MyISAM;
 
137
CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0');
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') ENGINE=MyISAM;
 
139
CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0');
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') ENGINE=MyISAM;
 
141
CREATE TABLE t1 (a varchar(20),b date NOT NULL default '0000-00-00');
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) NOT NULL default '',
149
 
  `email` varchar(60) NOT NULL default '',
 
148
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
 
149
  `email` varchar(60) character set latin1 NOT NULL default '',
150
150
  PRIMARY KEY  (`pseudo`),
151
151
  UNIQUE KEY `email` (`email`)
152
 
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
 
152
) ENGINE=MyISAM CHARSET=latin1 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 NOT NULL default '0',
 
172
  `topic` mediumint(8) unsigned NOT NULL default '0',
173
173
  `date` date NOT NULL default '0000-00-00',
174
 
  `pseudo` varchar(35) NOT NULL default '',
 
174
  `pseudo` varchar(35) character set latin1 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 NOT NULL auto_increment,
193
 
  `maxnumrep` int NOT NULL default '0',
 
192
  `numeropost` mediumint(8) unsigned NOT NULL auto_increment,
 
193
  `maxnumrep` int(10) unsigned 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 NOT NULL default '0',
 
202
      `topic` mediumint(8) unsigned NOT NULL default '0',
203
203
      `date` date NOT NULL default '0000-00-00',
204
204
      `pseudo` varchar(35) NOT NULL default '',
205
205
       PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`)
232
232
 
233
233
#forumconthardwarefr7
234
234
CREATE TABLE `t1` (
235
 
  `numeropost` bigint NOT NULL auto_increment,
236
 
  `maxnumrep` int NOT NULL default '0',
 
235
  `numeropost` mediumint(8) unsigned NOT NULL auto_increment,
 
236
  `maxnumrep` int(10) unsigned 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) ENGINE=MyISAM;
 
248
create table t1 (a int);
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') ENGINE=MyISAM;
 
254
CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b');
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 NOT NULL default '0',
263
 
  `numreponse` int NOT NULL auto_increment,
 
262
  `numeropost` mediumint(8) unsigned NOT NULL default '0',
 
263
  `numreponse` int(10) unsigned 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) ENGINE=MyISAM;
 
281
CREATE TABLE t1 (a int(1));
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)) ENGINE=MyISAM;
288
 
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
 
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));
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)) ENGINE=MyISAM;
302
 
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
 
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));
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)) 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;
 
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));
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
325
324
select * from t12;
326
325
-- error 1093
327
326
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
329
328
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
330
329
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
331
330
select * from t11;
332
 
--sorted_result
333
331
select * from t12;
334
332
drop table t11, t12, t2;
335
333
 
336
334
#insert with subselects
337
 
CREATE TABLE t1 (x int) ENGINE=MyISAM;
338
 
create table t2 (a int) ENGINE=MyISAM;
339
 
create table t3 (b int) ENGINE=MyISAM;
 
335
CREATE TABLE t1 (x int);
 
336
create table t2 (a int);
 
337
create table t3 (b int);
340
338
insert into t2 values (1);
341
339
insert into t3 values (1),(2);
342
340
-- error 1093
366
364
drop table t1, t2, t3;
367
365
 
368
366
#replace with subselects
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;
 
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);
372
370
insert into t2 values (1);
373
371
insert into t3 values (1),(2);
374
372
select * from t1;
382
380
select * from t1;
383
381
replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a FROM t2));
384
382
-- sleep 1
385
 
--sorted_result
386
383
select * from t1;
387
384
replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a+1 FROM t2));
388
385
-- sleep 1
389
386
select * from t1;
390
387
replace LOW_PRIORITY into t1 (x, y) VALUES ((SELECT a+1 FROM t2), (SELECT a FROM t2));
391
 
--sorted_result
392
388
select * from t1;
393
389
drop table t1, t2, t3;
394
390
 
395
391
-- error 1096
396
392
SELECT * FROM (SELECT 1) b WHERE 1 IN (SELECT *);
397
393
 
398
 
CREATE TABLE t2 (id int default NULL, KEY id (id)) ENGINE=MyISAM;
 
394
CREATE TABLE t2 (id int(11) default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1;
399
395
INSERT INTO t2 VALUES (1),(2);
400
396
SELECT * FROM t2 WHERE id IN (SELECT 1);
401
397
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1);
410
406
-- error 1093
411
407
INSERT INTO t2 VALUES ((SELECT id FROM t2));
412
408
SELECT * FROM t2;
413
 
CREATE TABLE t1 (id int default NULL, KEY id (id)) ENGINE=MyISAM;
 
409
CREATE TABLE t1 (id int(11) default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1;
414
410
INSERT INTO t1 values (1),(1);
415
411
-- error 1242
416
412
UPDATE t2 SET id=(SELECT * FROM t1);
417
413
drop table t2, t1;
418
414
 
419
415
#NULL test
420
 
create table t1 (a int) ENGINE=MyISAM;
 
416
create table t1 (a int);
421
417
insert into t1 values (1),(2),(3);
422
418
select 1 IN (SELECT * from t1);
423
419
select 10 IN (SELECT * from t1);
431
427
select 1 > ANY (SELECT * from t1);
432
428
select 10 > ANY (SELECT * from t1);
433
429
drop table t1;
434
 
create table t1 (a varchar(20)) ENGINE=MyISAM;
 
430
create table t1 (a varchar(20));
435
431
insert into t1 values ('A'),('BC'),('DEF');
436
432
select 'A' IN (SELECT * from t1);
437
433
select 'XYZS' IN (SELECT * from t1);
445
441
select 'A' > ANY (SELECT * from t1);
446
442
select 'XYZS' > ANY (SELECT * from t1);
447
443
drop table t1;
448
 
create table t1 (a float) ENGINE=MyISAM;
 
444
create table t1 (a float);
449
445
insert into t1 values (1.5),(2.5),(3.5);
450
446
select 1.5 IN (SELECT * from t1);
451
447
select 10.5 IN (SELECT * from t1);
459
455
select 1.5 > ANY (SELECT * from t1);
460
456
select 10.5 > ANY (SELECT * from t1);
461
457
explain extended select (select a+1) from t1;
462
 
--sorted_result
463
458
select (select a+1) from t1;
464
459
drop table t1;
465
460
 
467
462
# Null with keys
468
463
#
469
464
 
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;
 
465
CREATE TABLE t1 (a int(11) NOT NULL default '0', PRIMARY KEY  (a));
 
466
CREATE TABLE t2 (a int(11) default '0', INDEX (a));
472
467
INSERT INTO t1 VALUES (1),(2),(3),(4);
473
468
INSERT INTO t2 VALUES (1),(2),(3);
474
469
SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
475
470
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
476
 
CREATE TABLE t3 (a int default '0') ENGINE=MyISAM;
 
471
CREATE TABLE t3 (a int(11) default '0');
477
472
INSERT INTO t3 VALUES (1),(2),(3);
478
473
SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
479
474
explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
480
475
drop table t1,t2,t3;
481
476
 
482
477
#LIMIT is not supported now
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;
 
478
create table t1 (a float);
 
479
-- error 1235
 
480
select 10.5 IN (SELECT * from t1 LIMIT 1);
 
481
-- error 1235
 
482
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
 
483
drop table t1;
 
484
 
 
485
create table t1 (a int, b int, c varchar(10));
 
486
create table t2 (a int);
 
487
insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c');
 
488
insert into t2 values (1),(2),(NULL);
 
489
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;
 
490
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;
 
491
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;
 
492
drop table t1,t2;
 
493
 
 
494
create table t1 (a int, b real, c varchar(10));
 
495
insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');
 
496
select ROW(1, 1, 'a') IN (select a,b,c from t1);
 
497
select ROW(1, 2, 'a') IN (select a,b,c from t1);
 
498
select ROW(1, 1, 'a') IN (select b,a,c from t1);
 
499
select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null);
 
500
select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null);
 
501
select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null);
 
502
select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a');
 
503
select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a');
 
504
select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
 
505
-- error 1235
 
506
select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
 
507
drop table t1;
513
508
 
514
509
#test of uncacheable subqueries
515
 
CREATE TABLE t1 (a int) ENGINE=MyISAM;
 
510
CREATE TABLE t1 (a int(1));
516
511
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
 
512
EXPLAIN EXTENDED SELECT (SELECT ENCRYPT('test') FROM t1) FROM t1;
517
513
EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1;
518
514
drop table t1;
519
515
 
520
516
 
521
517
CREATE TABLE `t1` (
522
 
  `mot` varchar(30) NOT NULL default '',
523
 
  `topic` bigint NOT NULL default '0',
 
518
  `mot` varchar(30) character set latin1 NOT NULL default '',
 
519
  `topic` mediumint(8) unsigned NOT NULL default '0',
524
520
  `date` date NOT NULL default '0000-00-00',
525
 
  `pseudo` varchar(35) NOT NULL default '',
 
521
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
526
522
  PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`),
527
523
  KEY `pseudo` (`pseudo`,`date`,`topic`),
528
524
  KEY `topic` (`topic`)
529
 
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
 
525
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
530
526
 
531
527
CREATE TABLE `t2` (
532
 
  `mot` varchar(30) NOT NULL default '',
533
 
  `topic` bigint NOT NULL default '0',
 
528
  `mot` varchar(30) character set latin1 NOT NULL default '',
 
529
  `topic` mediumint(8) unsigned NOT NULL default '0',
534
530
  `date` date NOT NULL default '0000-00-00',
535
 
  `pseudo` varchar(35) NOT NULL default '',
 
531
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
536
532
  PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`),
537
533
  KEY `pseudo` (`pseudo`,`date`,`topic`),
538
534
  KEY `topic` (`topic`)
539
 
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
 
535
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
540
536
 
541
537
CREATE TABLE `t3` (
542
 
  `numeropost` bigint NOT NULL auto_increment,
543
 
  `maxnumrep` int NOT NULL default '0',
 
538
  `numeropost` mediumint(8) unsigned NOT NULL auto_increment,
 
539
  `maxnumrep` int(10) unsigned NOT NULL default '0',
544
540
  PRIMARY KEY  (`numeropost`),
545
541
  UNIQUE KEY `maxnumrep` (`maxnumrep`)
546
 
) ENGINE=MyISAM;
 
542
) ENGINE=MyISAM CHARSET=latin1;
547
543
INSERT INTO t1 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
548
544
 
549
545
INSERT INTO t2 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
560
556
drop table t1, t2, t3;
561
557
 
562
558
SELECT * FROM (SELECT 1 as a,(SELECT a)) 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;
 
559
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT 1)) a;
 
560
SHOW CREATE TABLE t1;
 
561
drop table t1;
 
562
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
 
563
SHOW CREATE TABLE t1;
 
564
drop table t1;
 
565
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a;
 
566
SHOW CREATE TABLE t1;
 
567
drop table t1;
 
568
CREATE TABLE t1 SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a;
573
569
select * from t1;
574
570
SHOW CREATE TABLE t1;
575
571
drop table t1;
576
572
 
577
 
create table t1 (a int) ENGINE=MyISAM;
 
573
create table t1 (a int);
578
574
insert into t1 values (1), (2), (3);
579
575
explain extended select a,(select (select rand() from t1 limit 1)  from t1 limit 1)
580
576
from t1;
591
587
#
592
588
 
593
589
CREATE TABLE t1 (
594
 
  ID int NOT NULL auto_increment,
 
590
  ID int(11) NOT NULL auto_increment,
595
591
  name char(35) NOT NULL default '',
596
592
  t2 char(3) NOT NULL default '',
597
593
  District char(20) NOT NULL default '',
598
 
  Population int NOT NULL default '0',
 
594
  Population int(11) NOT NULL default '0',
599
595
  PRIMARY KEY  (ID)
600
596
) ENGINE=MyISAM;
601
597
 
609
605
  Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
610
606
  Region char(26) NOT NULL default '',
611
607
  SurfaceArea float(10,2) NOT NULL default '0.00',
612
 
  IndepYear int default NULL,
613
 
  Population int NOT NULL default '0',
 
608
  IndepYear smallint(6) default NULL,
 
609
  Population int(11) NOT NULL default '0',
614
610
  LifeExpectancy float(3,1) default NULL,
615
611
  GNP float(10,2) default NULL,
616
612
  GNPOld float(10,2) default NULL,
617
613
  LocalName char(45) NOT NULL default '',
618
614
  GovernmentForm char(45) NOT NULL default '',
619
615
  HeadOfState char(60) default NULL,
620
 
  Capital int default NULL,
 
616
  Capital int(11) default NULL,
621
617
  Code2 char(2) NOT NULL default '',
622
618
  PRIMARY KEY  (Code)
623
619
) ENGINE=MyISAM;
633
629
# constants in IN
634
630
#
635
631
CREATE TABLE `t1` (
636
 
  `id` bigint NOT NULL auto_increment,
637
 
  `pseudo` varchar(35) NOT NULL default '',
 
632
  `id` mediumint(8) unsigned NOT NULL auto_increment,
 
633
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
638
634
  PRIMARY KEY  (`id`),
639
635
  UNIQUE KEY `pseudo` (`pseudo`)
640
636
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
647
643
drop table t1;
648
644
 
649
645
CREATE TABLE `t1` (
650
 
  `i` int NOT NULL default '0',
 
646
  `i` int(11) NOT NULL default '0',
651
647
  PRIMARY KEY  (`i`)
652
 
) ENGINE=MyISAM;
 
648
) ENGINE=MyISAM CHARSET=latin1;
653
649
 
654
650
INSERT INTO t1 VALUES (1);
655
651
UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i));
663
659
# Multi update test
664
660
#
665
661
CREATE TABLE t1 (
666
 
  id int default NULL
667
 
) ENGINE=MyISAM;
 
662
  id int(11) default NULL
 
663
) ENGINE=MyISAM CHARSET=latin1;
668
664
INSERT INTO t1 VALUES (1),(1),(2),(2),(1),(3);
669
665
CREATE TABLE t2 (
670
 
  id int default NULL,
 
666
  id int(11) default NULL,
671
667
  name varchar(15) default NULL
672
 
) ENGINE=MyISAM;
 
668
) ENGINE=MyISAM CHARSET=latin1;
673
669
 
674
670
INSERT INTO t2 VALUES (4,'vita'), (1,'vita'), (2,'vita'), (1,'vita');
675
671
update t1, t2 set t2.name='lenka' where t2.id in (select id from t1);
679
675
#
680
676
# correct NULL in <CONSTANT> IN (SELECT ...)
681
677
#
682
 
create table t1 (a int, unique index indexa (a)) ENGINE=MyISAM; 
 
678
create table t1 (a int, unique index indexa (a)); 
683
679
insert into t1 values (-1), (-4), (-2), (NULL); 
684
680
select -10 IN (select a from t1 FORCE INDEX (indexa)); 
685
681
drop table t1;
687
683
#
688
684
# Test optimization for sub selects
689
685
#
690
 
create table t1 (id int not null auto_increment primary key, salary int, key(salary)) ENGINE=MyISAM;
 
686
create table t1 (id int not null auto_increment primary key, salary int, key(salary));
691
687
insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000);
692
688
explain extended SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1);
693
689
drop table t1;
694
690
 
695
691
CREATE TABLE t1 (
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',
 
692
  ID int(10) unsigned NOT NULL auto_increment,
 
693
  SUB_ID int(3) unsigned NOT NULL default '0',
 
694
  REF_ID int(10) unsigned default NULL,
 
695
  REF_SUB int(3) unsigned default '0',
700
696
  PRIMARY KEY (ID,SUB_ID),
701
697
  UNIQUE KEY t1_PK (ID,SUB_ID),
702
698
  KEY t1_FK (REF_ID,REF_SUB),
703
699
  KEY t1_REFID (REF_ID)
704
 
) ENGINE=MyISAM;
 
700
) ENGINE=MyISAM CHARSET=cp1251;
705
701
INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
706
702
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
707
703
DROP TABLE t1;
709
705
#
710
706
# uninterruptable update
711
707
#
712
 
create table t1 (a int, b int) ENGINE=MyISAM;
713
 
create table t2 (a int, b int) ENGINE=MyISAM;
 
708
create table t1 (a int, b int);
 
709
create table t2 (a int, b int);
714
710
 
715
711
insert into t1 values (1,0), (2,0), (3,0);
716
712
insert into t2 values (1,1), (2,1), (3,1), (2,2);
725
721
#
726
722
 
727
723
CREATE TABLE `t1` (
728
 
  `id` bigint NOT NULL auto_increment,
 
724
  `id` mediumint(8) unsigned NOT NULL auto_increment,
729
725
  `pseudo` varchar(35) NOT NULL default '',
730
726
  `email` varchar(60) NOT NULL default '',
731
727
  PRIMARY KEY  (`id`),
732
728
  UNIQUE KEY `email` (`email`),
733
729
  UNIQUE KEY `pseudo` (`pseudo`)
734
 
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
 
730
) ENGINE=MyISAM CHARSET=latin1 PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
735
731
INSERT INTO t1 (id,pseudo,email) VALUES (1,'test','test'),(2,'test1','test1');
736
732
SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT id*1);
737
733
drop table if exists t1;
741
737
#
742
738
# IN subselect optimization test
743
739
#
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;
 
740
create table t1 (a int not null, b int, primary key (a));
 
741
create table t2 (a int not null, primary key (a));
 
742
create table t3 (a int not null, b int, primary key (a));
747
743
insert into t1 values (1,10), (2,20), (3,30),  (4,40);
748
744
insert into t2 values (2), (3), (4), (5);
749
745
insert into t3 values (10,3), (20,4), (30,5);
754
750
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
755
751
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
756
752
drop table t1, t2, t3;
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;
 
753
create table t1 (a int, b int, index a (a,b));
 
754
create table t2 (a int, index a (a));
 
755
create table t3 (a int, b int, index a (a));
760
756
insert into t1 values (1,10), (2,20), (3,30), (4,40);
761
757
disable_query_log;
762
758
# making table large enough
763
 
set autocommit=0;
764
 
begin;
765
759
let $1 = 10000;
766
760
while ($1)
767
761
 {
768
762
  eval insert into t1 values (rand()*100000+200,rand()*100000); 
769
763
  dec $1;
770
764
 }
771
 
commit;
772
 
set autocommit=1;
773
765
enable_query_log;
774
766
insert into t2 values (2), (3), (4), (5);
775
767
insert into t3 values (10,3), (20,4), (30,5);
788
780
#
789
781
# alloc_group_fields() working
790
782
#
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;
 
783
create table t1 (a int, b int);
 
784
create table t2 (a int, b int);
 
785
create table t3 (a int, b int);
794
786
insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10);
795
787
insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1);
796
788
insert into t3 values (3,3), (2,2), (1,1); 
800
792
#
801
793
# aggregate functions in HAVING test
802
794
#
803
 
create table t1 (s1 int) ENGINE=MyISAM;
804
 
create table t2 (s1 int) ENGINE=MyISAM;
 
795
create table t1 (s1 int);
 
796
create table t2 (s1 int);
805
797
insert into t1 values (1);
806
798
insert into t2 values (1);
807
799
select * from t1 where exists (select s1 from t2 having max(t2.s1)=t1.s1);
811
803
# update subquery with wrong field (to force name resolving
812
804
# in UPDATE name space)
813
805
#
814
 
create table t1 (s1 int) ENGINE=MyISAM;
815
 
create table t2 (s1 int) ENGINE=MyISAM;
 
806
create table t1 (s1 int);
 
807
create table t2 (s1 int);
816
808
insert into t1 values (1);
817
809
insert into t2 values (1);
818
810
-- error 1054
822
814
#
823
815
# collation test
824
816
#
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;
 
817
CREATE TABLE t1 (s1 CHAR(5) COLLATE latin1_german1_ci,
 
818
                 s2 CHAR(5) COLLATE latin1_swedish_ci);
 
819
INSERT INTO t1 VALUES ('z','?');
 
820
-- error 1267
 
821
select * from t1 where s1 > (select max(s2) from t1);
 
822
-- error 1267
 
823
select * from t1 where s1 > any (select max(s2) from t1);
 
824
drop table t1;
833
825
 
834
826
#
835
827
# aggregate functions reinitialization
836
828
#
837
 
create table t1(toid int,rd int) ENGINE=MyISAM;
838
 
create table t2(userid int,pmnew int,pmtotal int) ENGINE=MyISAM;
 
829
create table t1(toid int,rd int);
 
830
create table t2(userid int,pmnew int,pmtotal int);
839
831
insert into t2 values(1,0,0),(2,0,0);
840
832
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);
841
833
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);
844
836
#
845
837
# row union
846
838
#
847
 
create table t1 (s1 char(5)) ENGINE=MyISAM;
 
839
create table t1 (s1 char(5));
848
840
-- error 1241
849
841
select (select 'a','b' from t1 union select 'a','b' from t1) from t1;
850
842
insert into t1 values ('tttt');
856
848
#
857
849
# IN optimisation test results
858
850
#
859
 
create table t1 (s1 char(5), index s1(s1)) ENGINE=MyISAM;
860
 
create table t2 (s1 char(5), index s1(s1)) ENGINE=MyISAM;
 
851
create table t1 (s1 char(5), index s1(s1));
 
852
create table t2 (s1 char(5), index s1(s1));
861
853
insert into t1 values ('a1'),('a2'),('a3');
862
854
insert into t2 values ('a1'),('a2');
863
855
select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
873
865
#
874
866
# correct ALL optimisation
875
867
#
876
 
create table t2 (a int, b int) ENGINE=MyISAM;
877
 
create table t3 (a int) ENGINE=MyISAM;
 
868
create table t2 (a int, b int);
 
869
create table t3 (a int);
878
870
insert into t3 values (6),(7),(3);
879
871
select * from t3 where a >= all (select b from t2);
880
872
explain extended select * from t3 where a >= all (select b from t2);
904
896
# correct used_tables()
905
897
#
906
898
 
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 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 AUTO_INCREMENT=3 ;
 
899
CREATE TABLE `t1` ( `id` mediumint(9) NOT NULL auto_increment, `taskid` bigint(20) NOT NULL default '0', `dbid` int(11) 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 ;
908
900
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());
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;
 
901
CREATE TABLE `t2` (`db_id` int(11) NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` smallint(6) NOT NULL default '0',`secondary_uid` smallint(6) NOT NULL default '0',PRIMARY KEY  (`db_id`),UNIQUE KEY `name_2` (`name`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2147483647;
910
902
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);
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 ;
 
903
CREATE TABLE `t3` (`taskgenid` mediumint(9) NOT NULL auto_increment,`dbid` int(11) NOT NULL default '0',`taskid` int(11) NOT NULL default '0',`mon` tinyint(4) NOT NULL default '1',`tues` tinyint(4) NOT NULL default '1',`wed` tinyint(4) NOT NULL default '1',`thur` tinyint(4) NOT NULL default '1',`fri` tinyint(4) NOT NULL default '1',`sat` tinyint(4) NOT NULL default '0',`sun` tinyint(4) NOT NULL default '0',`how_often` smallint(6) NOT NULL default '1',`userid` smallint(6) NOT NULL default '0',`active` tinyint(4) NOT NULL default '1',PRIMARY KEY  (`taskgenid`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2 ;
912
904
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);
913
 
CREATE TABLE `t4` (`task_id` int NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM;
 
905
CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
914
906
INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
915
907
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;
916
908
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;
919
911
#
920
912
# cardinality check
921
913
#
922
 
CREATE TABLE t1 (id int default NULL) ENGINE=MyISAM;
 
914
CREATE TABLE t1 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1;
923
915
INSERT INTO t1 VALUES (1),(5);
924
 
CREATE TABLE t2 (id int default NULL) ENGINE=MyISAM;
 
916
CREATE TABLE t2 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1;
925
917
INSERT INTO t2 VALUES (2),(6);
926
918
-- error 1241
927
919
select * from t1 where (1,2,6) in (select * from t2);
930
922
#
931
923
# optimized ALL/ANY with union
932
924
#
933
 
create table t1 (s1 char) ENGINE=MyISAM;
 
925
create table t1 (s1 char);
934
926
insert into t1 values ('e');
935
927
select * from t1 where 'f' > any (select s1 from t1);
936
928
select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
940
932
#
941
933
# filesort in subquery (restoring join_tab)
942
934
#
943
 
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM;
 
935
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
944
936
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
945
 
CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM;
 
937
CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM CHARSET=latin1;
946
938
INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6');
947
939
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;
948
940
drop table t1, t2;
950
942
#
951
943
# unresolved field error
952
944
#
953
 
create table t1 (s1 int) ENGINE=MyISAM; 
954
 
create table t2 (s1 int) ENGINE=MyISAM;
 
945
create table t1 (s1 int); 
 
946
create table t2 (s1 int);
955
947
-- error 1054
956
948
select * from t1 where (select count(*) from t2 where t1.s2) = 1;
957
949
-- error 1054
963
955
#
964
956
# fix_fields() in add_ref_to_table_cond()
965
957
#
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;
 
958
CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB));
 
959
CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA));
968
960
INSERT INTO t1 VALUES (1,1,'1A3240'), (1,2,'4W2365');
969
961
INSERT INTO t2 VALUES (100, 200, 'C');
970
962
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
971
963
DROP TABLE t1, t2;
972
964
 
973
 
CREATE TABLE t1 (a int) ENGINE=MyISAM;
 
965
CREATE TABLE t1 (a int(1));
974
966
INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5);
975
967
SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100;
976
968
DROP TABLE t1;
980
972
#
981
973
 
982
974
CREATE TABLE `t1` (
983
 
  `id` int NOT NULL auto_increment,
984
 
  `id_cns` int NOT NULL default '0',
 
975
  `id` int(11) NOT NULL auto_increment,
 
976
  `id_cns` tinyint(3) unsigned NOT NULL default '0',
985
977
  `tipo` enum('','UNO','DUE') NOT NULL default '',
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',
 
978
  `anno_dep` smallint(4) unsigned zerofill NOT NULL default '0000',
 
979
  `particolare` mediumint(8) unsigned NOT NULL default '0',
 
980
  `generale` mediumint(8) unsigned NOT NULL default '0',
 
981
  `bis` tinyint(3) unsigned NOT NULL default '0',
990
982
  PRIMARY KEY  (`id`),
991
983
  UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`),
992
 
  UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`))
993
 
 ENGINE=MyISAM;
 
984
  UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`)
 
985
);
994
986
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);
995
987
CREATE TABLE `t2` (
996
 
  `id` int NOT NULL auto_increment,
997
 
  `max_anno_dep` int NOT NULL default '0',
998
 
  PRIMARY KEY  (`id`)) ENGINE=MyISAM;
 
988
  `id` tinyint(3) unsigned NOT NULL auto_increment,
 
989
  `max_anno_dep` smallint(6) unsigned NOT NULL default '0',
 
990
  PRIMARY KEY  (`id`)
 
991
);
999
992
INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990);
1000
993
 
1001
994
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;
1005
998
#
1006
999
# GLOBAL LIMIT
1007
1000
#
1008
 
create table t1 (a int) ENGINE=MyISAM;
 
1001
create table t1 (a int);
1009
1002
insert into t1 values (1), (2), (3);
1010
1003
SET SQL_SELECT_LIMIT=1;
1011
1004
select sum(a) from (select * from t1) as a;
1017
1010
# Bug #3118: subselect + order by
1018
1011
#
1019
1012
 
1020
 
CREATE TABLE t1 (a int, b int, INDEX (a)) ENGINE=MyISAM;
 
1013
CREATE TABLE t1 (a int, b int, INDEX (a));
1021
1014
INSERT INTO t1 VALUES (1, 1), (1, 2), (1, 3);
1022
1015
SELECT * FROM t1 WHERE a = (SELECT MAX(a) FROM t1 WHERE a = 1) ORDER BY b;
1023
1016
DROP TABLE t1;
1024
1017
 
1025
1018
# Item_cond fix field
1026
1019
#
1027
 
create table t1(val varchar(10)) ENGINE=MyISAM;
 
1020
create table t1(val varchar(10));
1028
1021
insert into t1 values ('aaa'), ('bbb'),('eee'),('mmm'),('ppp');
1029
1022
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%');
1030
1023
drop table t1;
1032
1025
#
1033
1026
# ref_or_null replacing with ref
1034
1027
#
1035
 
create table t1 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM;
 
1028
create table t1 (id int not null, text varchar(20) not null default '', primary key (id));
1036
1029
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');
1037
1030
select * from t1 where id not in (select id from t1 where id < 8);
1038
1031
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);
1039
1032
explain extended select * from t1 where id not in (select id from t1 where id < 8);
1040
1033
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);
1041
1034
insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
1042
 
create table t2 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM;
 
1035
create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
1043
1036
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');
1044
1037
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);
1045
1038
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);
1048
1041
#
1049
1042
# Static tables & rund() in subqueries
1050
1043
#
1051
 
create table t1 (a int) ENGINE=MyISAM;
 
1044
create table t1 (a int);
1052
1045
insert into t1 values (1);
1053
1046
explain select benchmark(1000, (select a from t1 where a=rand()));
1054
1047
drop table t1;
1056
1049
#
1057
1050
# bug 3188
1058
1051
#
1059
 
create table t1(id int) ENGINE=MyISAM;
1060
 
create table t2(id int) ENGINE=MyISAM;
1061
 
create table t3(flag int) ENGINE=MyISAM;
 
1052
create table t1(id int);
 
1053
create table t2(id int);
 
1054
create table t3(flag int);
1062
1055
-- error 1064
1063
1056
select (select * from t3 where id not null) from t1, t2;
1064
1057
drop table t1,t2,t3;
1066
1059
#
1067
1060
# aggregate functions (Bug #3505)
1068
1061
#
1069
 
CREATE TABLE t1 (id INT) ENGINE=MyISAM;
1070
 
CREATE TABLE t2 (id INT) ENGINE=MyISAM;
 
1062
CREATE TABLE t1 (id INT);
 
1063
CREATE TABLE t2 (id INT);
1071
1064
INSERT INTO t1 VALUES (1), (2);
1072
1065
INSERT INTO t2 VALUES (1);
1073
1066
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);
1079
1072
#
1080
1073
# ALL/ANY test
1081
1074
#
1082
 
CREATE TABLE t1 ( a int, b int ) ENGINE=MyISAM;
 
1075
CREATE TABLE t1 ( a int, b int );
1083
1076
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
1084
1077
SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 );
1085
1078
SELECT a FROM t1 WHERE a < ANY ( SELECT a FROM t1 WHERE b = 2 );
1214
1207
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a < t1.a), '-') from t1 a;
1215
1208
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a = t1.a), '-') from t1 a;
1216
1209
DROP TABLE t1;
1217
 
CREATE TABLE t1 ( a double, b double ) ENGINE=MyISAM;
 
1210
CREATE TABLE t1 ( a double, b double );
1218
1211
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
1219
1212
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2e0);
1220
1213
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2e0);
1229
1222
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2e0);
1230
1223
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2e0);
1231
1224
DROP TABLE t1;
1232
 
CREATE TABLE t1 ( a char(1), b char(1)) ENGINE=MyISAM;
 
1225
CREATE TABLE t1 ( a char(1), b char(1));
1233
1226
INSERT INTO t1 VALUES ('1','1'),('2','2'),('3','3');
1234
1227
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = '2');
1235
1228
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = '2');
1249
1242
#
1250
1243
# SELECT(EXISTS * ...)optimisation
1251
1244
#
1252
 
create table t1 (a int, b int) ENGINE=MyISAM;
 
1245
create table t1 (a int, b int);
1253
1246
insert into t1 values (1,2),(3,4);
1254
1247
select * from t1 up where exists (select * from t1 where t1.a=up.a);
1255
1248
explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
1259
1252
# Bug #4102: subselect in HAVING
1260
1253
#
1261
1254
 
1262
 
CREATE TABLE t1 (t1_a int) ENGINE=MyISAM;
 
1255
CREATE TABLE t1 (t1_a int);
1263
1256
INSERT INTO t1 VALUES (1);
1264
 
CREATE TABLE t2 (t2_a int, t2_b int, PRIMARY KEY (t2_a, t2_b)) ENGINE=MyISAM;
 
1257
CREATE TABLE t2 (t2_a int, t2_b int, PRIMARY KEY (t2_a, t2_b));
1265
1258
INSERT INTO t2 VALUES (1, 1), (1, 2);
1266
1259
SELECT * FROM t1, t2 table2 WHERE t1_a = 1 AND table2.t2_a = 1
1267
1260
  HAVING table2.t2_b = (SELECT MAX(t2_b) FROM t2 WHERE t2_a = table2.t2_a);
1271
1264
# Test problem with NULL and derived tables (Bug #4097)
1272
1265
#
1273
1266
 
1274
 
CREATE TABLE t1 (id int default NULL,name varchar(10) default NULL) ENGINE=MyISAM;
 
1267
CREATE TABLE t1 (id int(11) default NULL,name varchar(10) default NULL);
1275
1268
INSERT INTO t1 VALUES (1,'Tim'),(2,'Rebecca'),(3,NULL);
1276
 
CREATE TABLE t2 (id int default NULL, pet varchar(10) default NULL) ENGINE=MyISAM;
 
1269
CREATE TABLE t2 (id int(11) default NULL, pet varchar(10) default NULL);
1277
1270
INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix');
1278
1271
SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id;
1279
1272
drop table t1,t2;
1281
1274
#
1282
1275
# Aggregate function comparation with ALL/ANY/SOME subselect
1283
1276
#
1284
 
CREATE TABLE `t1` ( `a` int default NULL) ENGINE=MyISAM;
 
1277
CREATE TABLE `t1` ( `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1285
1278
insert into t1 values (1);
1286
 
CREATE TABLE `t2` ( `b` int default NULL, `a` int default NULL) ENGINE=MyISAM;
 
1279
CREATE TABLE `t2` ( `b` int(11) default NULL, `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1287
1280
insert into t2 values (1,2);
1288
1281
select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1);
1289
1282
drop table t1,t2;
1291
1284
#
1292
1285
# BUG#5003 - like in subselect
1293
1286
#
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;
 
1287
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);
1295
1288
CREATE INDEX AK01IZAVORGANG ON t1(izaAnalyseart_id,Kuerzel);
1296
1289
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000001','601','D0000000001','I0000000001');
1297
1290
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000002','602','D0000000001','I0000000001');
1303
1296
#
1304
1297
# Optimized IN with compound index
1305
1298
#
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;
 
1299
CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
 
1300
CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
1308
1301
insert into t1 values (1,1),(1,2),(2,1),(2,2);
1309
1302
insert into t2 values (1,2),(2,2);
1310
1303
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
1319
1312
#
1320
1313
# resolving fields of grouped outer SELECT
1321
1314
#
1322
 
CREATE TABLE t1 (howmanyvalues bigint, avalue int) ENGINE=MyISAM;
 
1315
CREATE TABLE t1 (howmanyvalues bigint, avalue int);
1323
1316
INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4);
1324
1317
SELECT howmanyvalues, count(*) from t1 group by howmanyvalues;
1325
1318
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
1329
1322
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues;
1330
1323
drop table t1;
1331
1324
 
1332
 
create table t1 (x int) ENGINE=MyISAM;
 
1325
create table t1 (x int);
1333
1326
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;
1334
1327
drop table t1;
1335
1328
 
1337
1330
# Test of correct maybe_null flag returning by subquwery for temporary table
1338
1331
# creation
1339
1332
#
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;
 
1333
CREATE TABLE `t1` ( `master` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `slave` int(10) unsigned NOT NULL default '0', `access` int(10) unsigned NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`));
1341
1334
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);
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 ;
 
1335
CREATE TABLE `t2` ( `id` int(10) unsigned NOT NULL default '0', `pid` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `level` tinyint(4) unsigned NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY  (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ;
1343
1336
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');
1344
1337
-- error 1054
1345
1338
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;
1356
1349
#
1357
1350
# primary query with temporary table and subquery with groupping
1358
1351
#
1359
 
create table t1 (a int, b int) ENGINE=MyISAM;
1360
 
create table t2 (a int, b int) ENGINE=MyISAM;
 
1352
create table t1 (a int, b int);
 
1353
create table t2 (a int, b int);
1361
1354
insert into t1 values (1,1),(1,2),(1,3),(2,4),(2,5);
1362
1355
insert into t2 values (1,3),(2,1);
1363
1356
select distinct a,b, (select max(b) from t2 where t1.b=t2.a) from t1 order by t1.b;
1366
1359
#
1367
1360
# Equal operation under row and empty subquery
1368
1361
#
1369
 
create table t1 (s1 int,s2 int) ENGINE=MyISAM;
 
1362
create table t1 (s1 int,s2 int);
1370
1363
insert into t1 values (20,15);
1371
1364
select * from t1 where  (('a',null) <=> (select 'a',s2 from t1 where s1 = 0));
1372
1365
drop table t1;
1374
1367
#
1375
1368
# ALL/ANY with NULL
1376
1369
#
1377
 
create table t1 (s1 int) ENGINE=MyISAM;
 
1370
create table t1 (s1 int);
1378
1371
insert into t1 values (1),(null);
1379
1372
select * from t1 where s1 < all (select s1 from t1);
1380
1373
select s1, s1 < all (select s1 from t1) from t1;
1389
1382
  Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
1390
1383
  Region char(26) NOT NULL default '',
1391
1384
  SurfaceArea float(10,2) NOT NULL default '0.00',
1392
 
  IndepYear int default NULL,
1393
 
  Population int NOT NULL default '0',
 
1385
  IndepYear smallint(6) default NULL,
 
1386
  Population int(11) NOT NULL default '0',
1394
1387
  LifeExpectancy float(3,1) default NULL,
1395
1388
  GNP float(10,2) default NULL,
1396
1389
  GNPOld float(10,2) default NULL,
1397
1390
  LocalName char(45) NOT NULL default '',
1398
1391
  GovernmentForm char(45) NOT NULL default '',
1399
1392
  HeadOfState char(60) default NULL,
1400
 
  Capital int default NULL,
 
1393
  Capital int(11) default NULL,
1401
1394
  Code2 char(2) NOT NULL default ''
1402
1395
) ENGINE=MyISAM;
1403
1396
INSERT INTO t1 VALUES ('XXX','Xxxxx','Oceania','Xxxxxx',26.00,0,0,0,0,0,'Xxxxx','Xxxxx','Xxxxx',NULL,'XX');
1414
1407
# Test for BUG#7885: Server crash when 'any' subselect compared to
1415
1408
# non-existant field.
1416
1409
#
1417
 
create table t1 (a1 int) ENGINE=MyISAM;
1418
 
create table t2 (b1 int) ENGINE=MyISAM;
 
1410
create table t1 (a1 int);
 
1411
create table t2 (b1 int);
1419
1412
--error 1054
1420
1413
select * from t1 where a2 > any(select b1 from t2);
1421
1414
select * from t1 where a1 > any(select b1 from t2);
1425
1418
#
1426
1419
# Comparison subquery with * and row
1427
1420
#
1428
 
create table t1 (a integer, b integer) ENGINE=MyISAM;
 
1421
create table t1 (a integer, b integer);
1429
1422
select (select * from t1) = (select 1,2);
1430
1423
select (select 1,2) = (select * from t1);
1431
1424
# queries whih can be converted to IN
1436
1429
#
1437
1430
# Comparison subquery and row with nested rows
1438
1431
#
1439
 
create table t1 (a integer, b integer) ENGINE=MyISAM;
 
1432
create table t1 (a integer, b integer);
1440
1433
-- error 1241
1441
1434
select row(1,(2,2)) in (select * from t1 );
1442
1435
-- error 1241
1463
1456
# Test for BUG#8218
1464
1457
#
1465
1458
CREATE TABLE t1 (
1466
 
  categoryId int NOT NULL,
1467
 
  courseId int NOT NULL,
 
1459
  categoryId int(11) NOT NULL,
 
1460
  courseId int(11) NOT NULL,
1468
1461
  startDate datetime NOT NULL,
1469
1462
  endDate datetime NOT NULL,
1470
1463
  createDate datetime NOT NULL,
1471
1464
  modifyDate timestamp NOT NULL,
1472
 
  attributes text NOT NULL)
1473
 
  engine=myisam;
1474
 
 
 
1465
  attributes text NOT NULL
 
1466
);
1475
1467
INSERT INTO t1 VALUES (1,41,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''),
1476
1468
(1,86,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
1477
1469
(1,87,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
1483
1475
(5,12,'2004-02-18','2010-01-01','2004-02-18','2004-02-18','');
1484
1476
 
1485
1477
CREATE TABLE t2 (
1486
 
  userId int NOT NULL,
1487
 
  courseId int NOT NULL,
1488
 
  date datetime NOT NULL)
1489
 
  engine=myisam;
1490
 
 
 
1478
  userId int(11) NOT NULL,
 
1479
  courseId int(11) NOT NULL,
 
1480
  date datetime NOT NULL
 
1481
);
1491
1482
INSERT INTO t2 VALUES (5141,71,'2003-11-18'),
1492
1483
(5141,72,'2003-11-25'),(5141,41,'2004-08-06'),
1493
1484
(5141,52,'2004-08-06'),(5141,53,'2004-08-06'),
1497
1488
 
1498
1489
 
1499
1490
CREATE TABLE t3 (
1500
 
  groupId int NOT NULL,
1501
 
  parentId int NOT NULL,
 
1491
  groupId int(11) NOT NULL,
 
1492
  parentId int(11) NOT NULL,
1502
1493
  startDate datetime NOT NULL,
1503
1494
  endDate datetime NOT NULL,
1504
1495
  createDate datetime NOT NULL,
1505
1496
  modifyDate timestamp NOT NULL,
1506
 
  ordering int)
1507
 
  engine=myisam;
1508
 
 
 
1497
  ordering int(11)
 
1498
);
1509
1499
INSERT INTO t3 VALUES (12,9,'1000-01-01','3999-12-31','2004-01-29','2004-01-29',NULL);
1510
1500
 
1511
1501
CREATE TABLE t4 (
1512
 
  id int NOT NULL,
1513
 
  groupTypeId int NOT NULL,
 
1502
  id int(11) NOT NULL,
 
1503
  groupTypeId int(11) NOT NULL,
1514
1504
  groupKey varchar(50) NOT NULL,
1515
1505
  name text,
1516
 
  ordering int,
 
1506
  ordering int(11),
1517
1507
  description text,
1518
1508
  createDate datetime NOT NULL,
1519
 
  modifyDate timestamp NOT NULL)
1520
 
  engine=myisam;
1521
 
 
 
1509
  modifyDate timestamp NOT NULL
 
1510
);
1522
1511
INSERT INTO t4 VALUES (9,5,'stationer','stationer',0,'Stationer','2004-01-29','2004-01-29'),
1523
1512
(12,5,'group2','group2',0,'group2','2004-01-29','2004-01-29');
1524
1513
 
1525
1514
CREATE TABLE t5 (
1526
 
  userId int NOT NULL,
1527
 
  groupId int NOT NULL,
 
1515
  userId int(11) NOT NULL,
 
1516
  groupId int(11) NOT NULL,
1528
1517
  createDate datetime NOT NULL,
1529
 
  modifyDate timestamp NOT NULL) ENGINE=MyISAM;
1530
 
 
 
1518
  modifyDate timestamp NOT NULL
 
1519
);
1531
1520
INSERT INTO t5 VALUES (5141,12,'2004-08-06','2004-08-06');
1532
1521
 
1533
1522
select
1567
1556
#
1568
1557
# Transformation in left expression of subquery (BUG#8888)
1569
1558
#
1570
 
create table t1 (a int) ENGINE=MyISAM;
 
1559
create table t1 (a int);
1571
1560
insert into t1 values (1), (2), (3);
1572
1561
SELECT 1 FROM t1 WHERE (SELECT 1) in (SELECT 1);
1573
1562
drop table t1;
1575
1564
#
1576
1565
# single row subqueries and row operations (code covarage improvement)
1577
1566
#
1578
 
create table t1 (a int, b int) ENGINE=MyISAM;
 
1567
create table t1 (a int, b int);
1579
1568
insert into t1 values (1,2);
1580
1569
-- error 1241
1581
1570
select 1 = (select * from t1);
1594
1583
#
1595
1584
# Item_int_with_ref check (BUG#10020)
1596
1585
#
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;
 
1586
CREATE TABLE `t1` (
 
1587
  `itemid` bigint(20) unsigned NOT NULL auto_increment,
 
1588
  `sessionid` bigint(20) unsigned default NULL,
 
1589
  `time` int(10) unsigned NOT NULL default '0',
 
1590
  `type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT
 
1591
NULL default '',
 
1592
  `data` text collate latin1_general_ci NOT NULL,
 
1593
  PRIMARY KEY  (`itemid`)
 
1594
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
1595
INSERT INTO `t1` VALUES (1, 1, 1, 'D', '');
 
1596
CREATE TABLE `t2` (
 
1597
  `sessionid` bigint(20) unsigned NOT NULL auto_increment,
 
1598
  `pid` int(10) unsigned NOT NULL default '0',
 
1599
  `date` int(10) unsigned NOT NULL default '0',
 
1600
  `ip` varchar(15) collate latin1_general_ci NOT NULL default '',
 
1601
  PRIMARY KEY  (`sessionid`)
 
1602
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
1603
INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
 
1604
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;
 
1605
drop tables t1,t2;
1615
1606
 
1616
1607
# BUG#11821 : Select from subselect using aggregate function on an enum
1617
1608
# segfaults:
1618
 
create table t1 (fld enum('0','1')) ENGINE=MyISAM;
 
1609
create table t1 (fld enum('0','1'));
1619
1610
insert into t1 values ('1');
1620
1611
select * from (select max(fld) from t1) as foo;
1621
1612
drop table t1;
1624
1615
# Bug #11867: queries with ROW(,elems>) IN (SELECT DISTINCT <cols> FROM ...)
1625
1616
#
1626
1617
 
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;
 
1618
CREATE TABLE t1 (one int, two int, flag char(1));
 
1619
CREATE TABLE t2 (one int, two int, flag char(1));
1629
1620
INSERT INTO t1 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
1630
1621
INSERT INTO t2 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
1631
1622
 
1655
1646
# Bug #12392: where cond with IN predicate for rows and NULL values in table 
1656
1647
#
1657
1648
 
1658
 
CREATE TABLE t1 (a char(5), b char(5)) ENGINE=MyISAM;
 
1649
CREATE TABLE t1 (a char(5), b char(5));
1659
1650
INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
1660
1651
 
1661
1652
SELECT * FROM t1 WHERE (a,b) IN (('aaa','aaa'), ('aaa','bbb'));
1666
1657
# Bug #11479: subquery over left join with an empty inner table 
1667
1658
#
1668
1659
 
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;
 
1660
CREATE TABLE t1 (a int);
 
1661
CREATE TABLE t2 (a int, b int);
 
1662
CREATE TABLE t3 (b int NOT NULL);
1672
1663
INSERT INTO t1 VALUES (1), (2), (3), (4);
1673
1664
INSERT INTO t2 VALUES (1,10), (3,30);
1674
1665
 
1684
1675
# Bug#18503: Queries with a quantified subquery returning empty set may
1685
1676
# return a wrong result. 
1686
1677
#
1687
 
CREATE TABLE t1 (f1 INT) ENGINE=MyISAM;
1688
 
CREATE TABLE t2 (f2 INT) ENGINE=MyISAM;
 
1678
CREATE TABLE t1 (f1 INT);
 
1679
CREATE TABLE t2 (f2 INT);
1689
1680
INSERT INTO t1 VALUES (1);
1690
1681
SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2);
1691
1682
SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE 1=0);
1695
1686
DROP TABLE t1, t2;
1696
1687
 
1697
1688
# BUG#20975 Wrong query results for subqueries within NOT
1698
 
create table t1 (s1 char) ENGINE=MyISAM;
 
1689
create table t1 (s1 char);
1699
1690
insert into t1 values (1),(2);
1700
1691
 
1701
1692
select * from t1 where (s1 < any (select s1 from t1));
1716
1707
#
1717
1708
create table t1 (
1718
1709
  retailerID varchar(8) NOT NULL,
1719
 
  statusID   int NOT NULL,
 
1710
  statusID   int(10) unsigned NOT NULL,
1720
1711
  changed    datetime NOT NULL,
1721
 
  UNIQUE KEY retailerID (retailerID, statusID, changed))
1722
 
  ENGINE=MyISAM;
 
1712
  UNIQUE KEY retailerID (retailerID, statusID, changed)
 
1713
);
1723
1714
 
1724
1715
INSERT INTO t1 VALUES("0026", "1", "2005-12-06 12:18:56");
1725
1716
INSERT INTO t1 VALUES("0026", "2", "2006-01-06 12:25:53");
1738
1729
# Bug #21180: Subselect with index for both WHERE and ORDER BY 
1739
1730
#             produces empty result
1740
1731
#
1741
 
create table t1(a int, primary key (a)) ENGINE=MyISAM;
 
1732
create table t1(a int, primary key (a));
1742
1733
insert into t1 values (10);
1743
1734
 
1744
 
create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)) ENGINE=MyISAM;
 
1735
create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
1745
1736
insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
1746
1737
 
1747
1738
explain SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r 
1769
1760
  field1 int NOT NULL,                 
1770
1761
  field2 int NOT NULL,                 
1771
1762
  field3 int NOT NULL,                 
1772
 
  PRIMARY KEY  (field1,field2,field3))
1773
 
  ENGINE=MyISAM;
1774
 
 
 
1763
  PRIMARY KEY  (field1,field2,field3)  
 
1764
);
1775
1765
CREATE TABLE t2 (             
1776
1766
  fieldA int NOT NULL,            
1777
1767
  fieldB int NOT NULL,            
1778
 
  PRIMARY KEY  (fieldA,fieldB))
1779
 
  ENGINE=MyISAM;
 
1768
  PRIMARY KEY  (fieldA,fieldB)     
 
1769
); 
1780
1770
 
1781
1771
INSERT INTO t1 VALUES
1782
1772
  (1,1,1), (1,1,2), (1,2,1), (1,2,2), (1,2,3), (1,3,1);
1803
1793
#             with possible NULL values by index access from the outer query
1804
1794
#
1805
1795
 
1806
 
CREATE TABLE t1(a int, INDEX (a)) ENGINE=MyISAM;
 
1796
CREATE TABLE t1(a int, INDEX (a));
1807
1797
INSERT INTO t1 VALUES (1), (3), (5), (7);
1808
1798
INSERT INTO t1 VALUES (NULL);
1809
1799
 
1810
 
CREATE TABLE t2(a int) ENGINE=MyISAM;
 
1800
CREATE TABLE t2(a int);
1811
1801
INSERT INTO t2 VALUES (1),(2),(3);
1812
1802
 
1813
1803
EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2;
1818
1808
#
1819
1809
# Bug #11302: getObject() returns a String for a sub-query of type datetime
1820
1810
#
1821
 
CREATE TABLE t1 (a DATETIME) ENGINE=MyISAM;
 
1811
CREATE TABLE t1 (a DATETIME);
1822
1812
INSERT INTO t1 VALUES ('1998-09-23'), ('2003-03-25');
1823
1813
 
1824
 
CREATE TABLE t2 ENGINE=MyISAM AS SELECT 
 
1814
CREATE TABLE t2 AS SELECT 
1825
1815
  (SELECT a FROM t1 WHERE a < '2000-01-01') AS sub_a 
1826
1816
   FROM t1 WHERE a > '2000-01-01';
1827
1817
SHOW CREATE TABLE t2;
1828
1818
 
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'); 
 
1819
CREATE TABLE t3 AS (SELECT a FROM t1 WHERE a < '2000-01-01') UNION (SELECT a FROM t1 WHERE a > '2000-01-01'); 
1830
1820
SHOW CREATE TABLE t3;
1831
1821
 
1832
1822
DROP TABLE t1,t2,t3;
1836
1826
#            that return more than one row
1837
1827
#
1838
1828
 
1839
 
CREATE TABLE t1 (a int) ENGINE=MyISAM;
 
1829
CREATE TABLE t1 (a int);
1840
1830
INSERT INTO t1 VALUES (2), (4), (1), (3);
1841
1831
 
1842
 
CREATE TABLE t2 (b int, c int) ENGINE=MyISAM;
 
1832
CREATE TABLE t2 (b int, c int);
1843
1833
INSERT INTO t2 VALUES
1844
1834
  (2,1), (1,3), (2,1), (4,4), (2,2), (1,4);
1845
1835
 
1894
1884
#
1895
1885
#decimal-related tests
1896
1886
#
1897
 
create table t1 (df decimal(5,1)) ENGINE=MyISAM;
 
1887
create table t1 (df decimal(5,1));
1898
1888
insert into t1 values(1.1);
1899
1889
insert into t1 values(2.2);
1900
1890
 
1902
1892
select * from t1 where df >= all (select avg(df) from t1 group by df);
1903
1893
drop table t1;
1904
1894
 
1905
 
create table t1 (df decimal(5,1)) ENGINE=MyISAM;
 
1895
create table t1 (df decimal(5,1));
1906
1896
insert into t1 values(1.1);
1907
1897
select 1.1 * exists(select * from t1);
1908
1898
drop table t1;
1909
1899
 
1910
1900
CREATE TABLE t1 (
1911
 
  grp int default NULL,
1912
 
  a decimal(10,2) default NULL) ENGINE=MyISAM;
 
1901
  grp int(11) default NULL,
 
1902
  a decimal(10,2) default NULL);
1913
1903
 
1914
1904
insert into t1 values (1, 1), (2, 2), (2, 3), (3, 4), (3, 5), (3, 6), (NULL, NULL);
1915
1905
select * from t1;
1920
1910
# Test for bug #9338: lame substitution of c1 instead of c2 
1921
1911
#
1922
1912
 
1923
 
CREATE table t1 ( c1 integer ) ENGINE=MyISAM;
 
1913
CREATE table t1 ( c1 integer );
1924
1914
INSERT INTO t1 VALUES ( 1 );
1925
1915
INSERT INTO t1 VALUES ( 2 );
1926
1916
INSERT INTO t1 VALUES ( 3 );
1927
1917
 
1928
 
CREATE TABLE t2 ( c2 integer ) ENGINE=MyISAM;
 
1918
CREATE TABLE t2 ( c2 integer );
1929
1919
INSERT INTO t2 VALUES ( 1 );
1930
1920
INSERT INTO t2 VALUES ( 4 );
1931
1921
INSERT INTO t2 VALUES ( 5 );
1940
1930
#
1941
1931
# Test for bug #9516: wrong evaluation of not_null_tables attribute in SQ 
1942
1932
#
1943
 
CREATE TABLE t1 ( c1 integer ) ENGINE=MyISAM;
 
1933
CREATE TABLE t1 ( c1 integer );
1944
1934
INSERT INTO t1 VALUES ( 1 );
1945
1935
INSERT INTO t1 VALUES ( 2 );
1946
1936
INSERT INTO t1 VALUES ( 3 );
1947
1937
INSERT INTO t1 VALUES ( 6 ); 
1948
1938
 
1949
 
CREATE TABLE t2 ( c2 integer ) ENGINE=MyISAM;
 
1939
CREATE TABLE t2 ( c2 integer );
1950
1940
INSERT INTO t2 VALUES ( 1 );
1951
1941
INSERT INTO t2 VALUES ( 4 );
1952
1942
INSERT INTO t2 VALUES ( 5 );
1953
1943
INSERT INTO t2 VALUES ( 6 );
1954
1944
 
1955
 
CREATE TABLE t3 ( c3 integer ) ENGINE=MyISAM;
 
1945
CREATE TABLE t3 ( c3 integer );
1956
1946
INSERT INTO t3 VALUES ( 7 );
1957
1947
INSERT INTO t3 VALUES ( 8 );
1958
1948
 
1962
1952
DROP TABLE t1,t2,t3;
1963
1953
 
1964
1954
#
 
1955
# Item_int_with_ref check (BUG#10020)
 
1956
#
 
1957
CREATE TABLE `t1` (
 
1958
  `itemid` bigint(20) unsigned NOT NULL auto_increment,
 
1959
  `sessionid` bigint(20) unsigned default NULL,
 
1960
  `time` int(10) unsigned NOT NULL default '0',
 
1961
  `type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT
 
1962
NULL default '',
 
1963
  `data` text collate latin1_general_ci NOT NULL,
 
1964
  PRIMARY KEY  (`itemid`)
 
1965
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
1966
INSERT INTO `t1` VALUES (1, 1, 1, 'D', '');
 
1967
CREATE TABLE `t2` (
 
1968
  `sessionid` bigint(20) unsigned NOT NULL auto_increment,
 
1969
  `pid` int(10) unsigned NOT NULL default '0',
 
1970
  `date` int(10) unsigned NOT NULL default '0',
 
1971
  `ip` varchar(15) collate latin1_general_ci NOT NULL default '',
 
1972
  PRIMARY KEY  (`sessionid`)
 
1973
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
1974
INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
 
1975
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;
 
1976
drop tables t1,t2;
 
1977
 
 
1978
#
1965
1979
# Correct building of equal fields list (do not include outer
1966
1980
# fields) (BUG#6384)
1967
1981
#
1968
 
CREATE TABLE t1 (EMPNUM   CHAR(3)) ENGINE=MyISAM;
1969
 
CREATE TABLE t2 (EMPNUM   CHAR(3) ) ENGINE=MyISAM;
 
1982
CREATE TABLE t1 (EMPNUM   CHAR(3));
 
1983
CREATE TABLE t2 (EMPNUM   CHAR(3) );
1970
1984
INSERT INTO t1 VALUES ('E1'),('E2');
1971
1985
INSERT INTO t2 VALUES ('E1');
1972
1986
DELETE FROM t1
1981
1995
# Test for bug #11487: range access in a subquery
1982
1996
#
1983
1997
 
1984
 
CREATE TABLE t1(select_id BIGINT, values_id BIGINT) ENGINE=MyISAM;
 
1998
CREATE TABLE t1(select_id BIGINT, values_id BIGINT);
1985
1999
INSERT INTO t1 VALUES (1, 1);
1986
2000
CREATE TABLE t2 (select_id BIGINT, values_id BIGINT, 
1987
 
                 PRIMARY KEY(select_id,values_id)) ENGINE=MyISAM;
 
2001
                 PRIMARY KEY(select_id,values_id));
1988
2002
INSERT INTO t2 VALUES (0, 1), (0, 2), (0, 3), (1, 5);
1989
2003
 
1990
2004
SELECT values_id FROM t1 
2001
2015
 
2002
2016
# BUG#11821 : Select from subselect using aggregate function on an enum
2003
2017
# segfaults:
2004
 
create table t1 (fld enum('0','1')) ENGINE=MyISAM;
 
2018
create table t1 (fld enum('0','1'));
2005
2019
insert into t1 values ('1');
2006
2020
select * from (select max(fld) from t1) as foo;
2007
2021
drop table t1;
2010
2024
# Test for bug #11762: subquery with an aggregate function in HAVING
2011
2025
#
2012
2026
 
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;
 
2027
CREATE TABLE t1 (a int, b int);
 
2028
CREATE TABLE t2 (c int, d int);
 
2029
CREATE TABLE t3 (e int);
2016
2030
 
2017
2031
INSERT INTO t1 VALUES 
2018
2032
  (1,10), (2,10), (1,20), (2,20), (3,20), (2,30), (4,40);
2094
2108
# Test for bug #16603: GROUP BY in a row subquery with a quantifier 
2095
2109
#                      when an index is defined on the grouping field
2096
2110
 
2097
 
CREATE TABLE t1 (a varchar(5), b varchar(10)) ENGINE=MyISAM;
 
2111
CREATE TABLE t1 (a varchar(5), b varchar(10));
2098
2112
INSERT INTO t1 VALUES
2099
2113
  ('AAA', 5), ('BBB', 4), ('BBB', 1), ('CCC', 2),
2100
2114
  ('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8);
2114
2128
#
2115
2129
# Bug#17366: Unchecked Item_int results in server crash
2116
2130
#
2117
 
create table t1( f1 int,f2 int) ENGINE=MyISAM;
 
2131
create table t1( f1 int,f2 int);
2118
2132
insert into t1 values (1,1),(2,2);
2119
2133
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';
2120
2134
drop table t1;
2123
2137
# Bug #18306: server crash on delete using subquery.
2124
2138
#
2125
2139
 
2126
 
create table t1 (c int, key(c)) ENGINE=MyISAM;                              
 
2140
create table t1 (c int, key(c));                              
2127
2141
insert into t1 values (1142477582), (1142455969);
2128
 
create table t2 (a int, b int) ENGINE=MyISAM;
 
2142
create table t2 (a int, b int);
2129
2143
insert into t2 values (2, 1), (1, 0);
2130
2144
delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1;
2131
2145
drop table t1, t2;
2133
2147
#
2134
2148
# Bug#19077: A nested materialized derived table is used before being populated.
2135
2149
#
2136
 
create table t1 (i int, j bigint) ENGINE=MyISAM;
 
2150
create table t1 (i int, j bigint);
2137
2151
insert into t1 values (1, 2), (2, 2), (3, 2);
2138
2152
select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3;
2139
2153
drop table t1;
2141
2155
2142
2156
# Bug#19700: subselect returning BIGINT always returned it as SIGNED
2143
2157
#
2144
 
CREATE TABLE t1 (i BIGINT) ENGINE=MyISAM;
2145
 
INSERT INTO t1 VALUES (10000000000000000); # > MAX SIGNED BIGINT 9323372036854775807
 
2158
CREATE TABLE t1 (i BIGINT UNSIGNED);
 
2159
INSERT INTO t1 VALUES (10000000000000000000); # > MAX SIGNED BIGINT 9323372036854775807
2146
2160
INSERT INTO t1 VALUES (1);
2147
2161
 
2148
 
CREATE TABLE t2 (i BIGINT) ENGINE=MyISAM;
2149
 
INSERT INTO t2 VALUES (10000000000000000); # same as first table
 
2162
CREATE TABLE t2 (i BIGINT UNSIGNED);
 
2163
INSERT INTO t2 VALUES (10000000000000000000); # same as first table
2150
2164
INSERT INTO t2 VALUES (1);
2151
2165
 
2152
2166
/* simple test */
2156
2170
SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2);
2157
2171
 
2158
2172
/* subquery test with cast*/
2159
 
SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2);
 
2173
SELECT t1.i FROM t1 WHERE t1.i = CAST((SELECT MAX(i) FROM t2) AS UNSIGNED);
2160
2174
 
2161
2175
DROP TABLE t1;
2162
2176
DROP TABLE t2;
2166
2180
#
2167
2181
 
2168
2182
CREATE TABLE t1 (
2169
 
  id bigint NOT NULL auto_increment,
 
2183
  id bigint(20) unsigned NOT NULL auto_increment,
2170
2184
  name varchar(255) NOT NULL,
2171
 
  PRIMARY KEY  (id))
2172
 
  ENGINE=MyISAM;
2173
 
 
 
2185
  PRIMARY KEY  (id)
 
2186
);
2174
2187
INSERT INTO t1 VALUES
2175
2188
  (1, 'Balazs'), (2, 'Joe'), (3, 'Frank');
2176
2189
 
2177
2190
CREATE TABLE t2 (
2178
 
  id bigint NOT NULL auto_increment,
2179
 
  mid bigint NOT NULL,
 
2191
  id bigint(20) unsigned NOT NULL auto_increment,
 
2192
  mid bigint(20) unsigned NOT NULL,
2180
2193
  date date NOT NULL,
2181
 
  PRIMARY KEY  (id))
2182
 
  ENGINE=MyISAM;
2183
 
 
 
2194
  PRIMARY KEY  (id)
 
2195
);
2184
2196
INSERT INTO t2 VALUES 
2185
2197
  (1, 1, '2006-03-30'), (2, 2, '2006-04-06'), (3, 3, '2006-04-13'),
2186
2198
  (4, 2, '2006-04-20'), (5, 1, '2006-05-01');
2208
2220
#
2209
2221
 
2210
2222
CREATE TABLE t1 (
2211
 
  i1 int NOT NULL default '0',
2212
 
  i2 int NOT NULL default '0',
 
2223
  i1 int(11) NOT NULL default '0',
 
2224
  i2 int(11) NOT NULL default '0',
2213
2225
  t datetime NOT NULL default '0000-00-00 00:00:00',
2214
 
  PRIMARY KEY  (i1,i2,t))
2215
 
  ENGINE=MyISAM;
2216
 
 
 
2226
  PRIMARY KEY  (i1,i2,t)
 
2227
);
2217
2228
INSERT INTO t1 VALUES 
2218
2229
(24,1,'2005-03-03 16:31:31'),(24,1,'2005-05-27 12:40:07'),
2219
2230
(24,1,'2005-05-27 12:40:08'),(24,1,'2005-05-27 12:40:10'),
2223
2234
(24,2,'2005-05-27 12:40:06');
2224
2235
 
2225
2236
CREATE TABLE t2 (
2226
 
  i1 int NOT NULL default '0',
2227
 
  i2 int NOT NULL default '0',
 
2237
  i1 int(11) NOT NULL default '0',
 
2238
  i2 int(11) NOT NULL default '0',
2228
2239
  t datetime default NULL,
2229
 
  PRIMARY KEY  (i1))
2230
 
  ENGINE=MyISAM;
2231
 
 
 
2240
  PRIMARY KEY  (i1)
 
2241
);
2232
2242
INSERT INTO t2 VALUES (24,1,'2006-06-20 12:29:40');
2233
2243
 
2234
2244
EXPLAIN
2247
2257
# Bug#14654 : Cannot select from the same table twice within a UNION
2248
2258
# statement 
2249
2259
#
2250
 
CREATE TABLE t1 (i INT) ENGINE=MyISAM;
 
2260
CREATE TABLE t1 (i INT);
2251
2261
 
2252
2262
(SELECT i FROM t1) UNION (SELECT i FROM t1);
2253
2263
SELECT * FROM t1 WHERE NOT EXISTS 
2272
2282
DROP TABLE t1;
2273
2283
 
2274
2284
#
 
2285
# Bug#21798: memory leak during query execution with subquery in column 
 
2286
#             list using a function
 
2287
#
 
2288
CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
 
2289
insert into t1 (a) values (FLOOR(rand() * 100));
 
2290
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2291
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2292
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2293
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2294
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2295
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2296
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2297
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2298
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2299
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2300
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2301
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2302
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2303
 
 
2304
SELECT a, 
 
2305
       (SELECT REPEAT(' ',250) FROM t1 i1 
 
2306
        WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a 
 
2307
FROM t1 ORDER BY a LIMIT 5;
 
2308
DROP TABLE t1;
 
2309
 
 
2310
#
2275
2311
# Bug #21540: Subqueries with no from and aggregate functions return 
2276
2312
#              wrong results
2277
 
CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM;
2278
 
CREATE TABLE t2 (a INT) ENGINE=MyISAM;
 
2313
CREATE TABLE t1 (a INT, b INT);
 
2314
CREATE TABLE t2 (a INT);
2279
2315
INSERT INTO t2 values (1);
2280
2316
INSERT INTO t1 VALUES (1,1),(1,2),(2,3),(3,4);
2281
2317
SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a;
2298
2334
#             slow with big sort_buffer_size 
2299
2335
#
2300
2336
 
2301
 
CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b)) ENGINE=MyISAM;
 
2337
CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b));
2302
2338
CREATE TABLE t2 (x int auto_increment, y int, z int,
2303
 
                 PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b)) ENGINE=MyISAM;
 
2339
                 PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b));
 
2340
 
2304
2341
disable_query_log;
2305
 
set autocommit=0;
2306
 
begin;
2307
2342
let $1=3000;
2308
2343
while ($1)
2309
2344
{
2317
2352
  } 
2318
2353
  dec $1;
2319
2354
}
2320
 
commit;
2321
 
set autocommit=1;
2322
2355
enable_query_log;
2323
2356
 
2324
2357
SET SESSION sort_buffer_size = 32 * 1024;
2331
2364
  FROM (SELECT  a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
2332
2365
          FROM t1) t;
2333
2366
 
2334
 
DROP TABLE t2,t1;
 
2367
DROP TABLE t1,t2;
2335
2368
 
2336
2369
#
2337
2370
# Bug #25219: EXIST subquery with UNION over a mix of
2338
2371
#             correlated and uncorrelated selects
2339
2372
#
2340
2373
 
2341
 
CREATE TABLE t1 (id char(4) PRIMARY KEY, c int) ENGINE=MyISAM;
2342
 
CREATE TABLE t2 (c int) ENGINE=MyISAM;
 
2374
CREATE TABLE t1 (id char(4) PRIMARY KEY, c int);
 
2375
CREATE TABLE t2 (c int);
2343
2376
 
2344
2377
INSERT INTO t1 VALUES ('aa', 1);
2345
2378
INSERT INTO t2 VALUES (1);
2357
2390
                SELECT c from t2 WHERE c=t1.c);
2358
2391
 
2359
2392
INSERT INTO t2 VALUES (2);
2360
 
CREATE TABLE t3 (c int) ENGINE=MyISAM;
 
2393
CREATE TABLE t3 (c int);
2361
2394
INSERT INTO t3 VALUES (1);
2362
2395
 
2363
2396
SELECT * FROM t1
2378
2411
--enable_warnings
2379
2412
 
2380
2413
CREATE TABLE t1 (
2381
 
  id_1 int NOT NULL,
2382
 
  t varchar(4) DEFAULT NULL)
2383
 
  ENGINE=MyISAM;
 
2414
  id_1 int(5) NOT NULL,
 
2415
  t varchar(4) DEFAULT NULL
 
2416
);
2384
2417
 
2385
2418
CREATE TABLE t2 (
2386
 
  id_2 int NOT NULL,
2387
 
  t varchar(4) DEFAULT NULL)
2388
 
  ENGINE=MyISAM;
 
2419
  id_2 int(5) NOT NULL,
 
2420
  t varchar(4) DEFAULT NULL
 
2421
);
2389
2422
 
2390
2423
CREATE TABLE t1xt2 (
2391
 
  id_1 int NOT NULL,
2392
 
  id_2 int NOT NULL)
2393
 
  ENGINE=MyISAM;
 
2424
  id_1 int(5) NOT NULL,
 
2425
  id_2 int(5) NOT NULL
 
2426
);
2394
2427
 
2395
2428
INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd');
2396
2429
 
2470
2503
# Bug #26728: derived table with concatanation of literals in select list
2471
2504
#  
2472
2505
 
2473
 
CREATE TABLE t1 (a int) ENGINE=MyISAM;
 
2506
CREATE TABLE t1 (a int);
2474
2507
INSERT INTO t1 VALUES (3), (1), (2);           
2475
2508
 
2476
2509
SELECT 'this is ' 'a test.' AS col1, a AS col2 FROM t1;
2482
2515
# Bug #27257: COUNT(*) aggregated in outer query
2483
2516
#  
2484
2517
 
2485
 
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
2486
 
CREATE TABLE t2 (m int, n int) ENGINE=MyISAM;
 
2518
CREATE TABLE t1 (a int, b int);
 
2519
CREATE TABLE t2 (m int, n int);
2487
2520
INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
2488
2521
INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
2489
2522
 
2505
2538
# Bug #27229: GROUP_CONCAT in subselect with COUNT() as an argument 
2506
2539
#  
2507
2540
 
2508
 
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
2509
 
CREATE TABLE t2 (m int, n int) ENGINE=MyISAM;
 
2541
CREATE TABLE t1 (a int, b int);
 
2542
CREATE TABLE t2 (m int, n int);
2510
2543
INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
2511
2544
INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
2512
2545
 
2523
2556
#
2524
2557
# Bug#27321: Wrong subquery result in a grouping select
2525
2558
#
2526
 
CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b)) ENGINE=MyISAM;
 
2559
CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b));
2527
2560
INSERT INTO t1 VALUES (1,1,0,'a'), (1,2,0,'b'), (1,3,0,'c'), (1,4,0,'d'),
2528
2561
(1,5,0,'e'), (2,1,0,'f'), (2,2,0,'g'), (2,3,0,'h'), (3,4,0,'i'), (3,3,0,'j'),
2529
2562
(3,2,0,'k'), (3,1,0,'l'), (1,9,0,'m'), (1,0,10,'n'), (2,0,5,'o'), (3,0,7,'p');
2561
2594
# Bug #27363: nested aggregates in outer, subquery / sum(select
2562
2595
# count(outer))
2563
2596
#
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);
 
2597
CREATE TABLE t1 (a INT); INSERT INTO t1 values (1),(1),(1),(1);
 
2598
CREATE TABLE t2 (x INT); INSERT INTO t1 values (1000),(1001),(1002);
2566
2599
 
2567
2600
--error ER_INVALID_GROUP_FUNC_USE
2568
2601
SELECT SUM( (SELECT COUNT(a) FROM t2) ) FROM t1;
2584
2617
#
2585
2618
# Bug #27807: Server crash when executing subquery with EXPLAIN
2586
2619
#  
2587
 
CREATE TABLE t1 (a int, b int, KEY (a)) ENGINE=MyISAM; 
 
2620
CREATE TABLE t1 (a int, b int, KEY (a)); 
2588
2621
INSERT INTO t1 VALUES (1,1),(2,1);
2589
2622
EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b);
2590
2623
DROP TABLE t1;
2593
2626
# Bug #28377: grouping query with a correlated subquery in WHERE condition
2594
2627
#  
2595
2628
 
2596
 
CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)) ENGINE=MyISAM;
 
2629
CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id));
2597
2630
INSERT INTO t1 VALUES
2598
2631
  (3,'FL'), (2,'GA'), (4,'FL'), (1,'GA'), (5,'NY'), (7,'FL'), (6,'NY');
2599
 
CREATE TABLE t2 (id int NOT NULL, INDEX idx(id)) ENGINE=MyISAM;
 
2632
CREATE TABLE t2 (id int NOT NULL, INDEX idx(id));
2600
2633
INSERT INTO t2 VALUES (7), (5), (1), (3);
2601
2634
 
2602
2635
SELECT id, st FROM t1 
2618
2651
#             over a grouping subselect
2619
2652
2620
2653
 
2621
 
CREATE TABLE t1 (a int) ENGINE=MyISAM;
 
2654
CREATE TABLE t1 (a int);
2622
2655
 
2623
2656
INSERT INTO t1 VALUES (1), (2);
2624
2657
 
2634
2667
CREATE TABLE t1 (
2635
2668
  a varchar(255) default NULL,
2636
2669
  b timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2637
 
  INDEX idx(a,b))
2638
 
  ENGINE=MyISAM;
2639
 
 
 
2670
  INDEX idx(a,b)
 
2671
);
2640
2672
CREATE TABLE t2 (
2641
 
  a varchar(255) default NULL)
2642
 
  ENGINE=MyISAM;
 
2673
  a varchar(255) default NULL
 
2674
);
2643
2675
 
2644
2676
INSERT INTO t1 VALUES ('abcdefghijk','2007-05-07 06:00:24');
2645
2677
INSERT INTO t1 SELECT * FROM t1;
2665
2697
# Bug #27333: subquery grouped for aggregate of outer query / no aggregate
2666
2698
# of subquery
2667
2699
#
2668
 
CREATE TABLE t1 (a INTEGER, b INTEGER) ENGINE=MyISAM;
2669
 
CREATE TABLE t2 (x INTEGER) ENGINE=MyISAM;
 
2700
CREATE TABLE t1 (a INTEGER, b INTEGER);
 
2701
CREATE TABLE t2 (x INTEGER);
2670
2702
INSERT INTO t1 VALUES (1,11), (2,22), (2,22);
2671
2703
INSERT INTO t2 VALUES (1), (2);
2672
2704
 
2682
2714
DROP TABLE t1,t2;
2683
2715
 
2684
2716
# second test case from 27333
2685
 
CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM;
 
2717
CREATE TABLE t1 (a INT, b INT);
2686
2718
INSERT INTO t1 VALUES (1, 2), (1,3), (1,4), (2,1), (2,2);
2687
2719
 
2688
2720
# returns no rows, when it should
2692
2724
DROP TABLE t1;
2693
2725
 
2694
2726
#test cases from 29297
2695
 
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
2696
 
CREATE TABLE t2 (a INT) ENGINE=MyISAM;
 
2727
CREATE TABLE t1 (a INT);
 
2728
CREATE TABLE t2 (a INT);
2697
2729
INSERT INTO t1 VALUES (1),(2);
2698
2730
INSERT INTO t2 VALUES (1),(2);
2699
2731
SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=0) FROM t1;
2706
2738
# Bug #31884: Assertion + crash in subquery in the SELECT clause.
2707
2739
#
2708
2740
 
2709
 
CREATE TABLE t1 (a1 INT, a2 INT) ENGINE=MyISAM;
2710
 
CREATE TABLE t2 (b1 INT, b2 INT) ENGINE=MyISAM;
 
2741
CREATE TABLE t1 (a1 INT, a2 INT);
 
2742
CREATE TABLE t2 (b1 INT, b2 INT);
2711
2743
 
2712
2744
INSERT INTO t1 VALUES (100, 200);
2713
2745
INSERT INTO t1 VALUES (101, 201);
2718
2750
DROP TABLE t1, t2;
2719
2751
 
2720
2752
#
 
2753
# Bug #28076: inconsistent binary/varbinary comparison
 
2754
#
 
2755
 
 
2756
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
 
2757
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
 
2758
 
 
2759
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
 
2760
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
 
2761
 
 
2762
CREATE INDEX I1 ON t1 (s1);
 
2763
CREATE INDEX I2 ON t1 (s2);
 
2764
 
 
2765
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
 
2766
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
 
2767
 
 
2768
TRUNCATE t1;
 
2769
INSERT INTO t1 VALUES (0x41,0x41);
 
2770
SELECT * FROM t1 WHERE s1 = (SELECT s2 FROM t1);
 
2771
 
 
2772
DROP TABLE t1;
 
2773
 
 
2774
CREATE TABLE t1 (a1 VARBINARY(2) NOT NULL DEFAULT '0', PRIMARY KEY (a1));
 
2775
CREATE TABLE t2 (a2 BINARY(2) default '0', INDEX (a2));
 
2776
CREATE TABLE t3 (a3 BINARY(2) default '0');
 
2777
INSERT INTO t1 VALUES (1),(2),(3),(4);
 
2778
INSERT INTO t2 VALUES (1),(2),(3);
 
2779
INSERT INTO t3 VALUES (1),(2),(3);
 
2780
SELECT LEFT(t2.a2, 1) FROM t2,t3 WHERE t3.a3=t2.a2;
 
2781
SELECT t1.a1, t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2) FROM t1;
 
2782
DROP TABLE t1,t2,t3;
 
2783
 
 
2784
CREATE TABLE t1 (a1 BINARY(3) PRIMARY KEY, b1 VARBINARY(3));
 
2785
CREATE TABLE t2 (a2 VARBINARY(3) PRIMARY KEY);
 
2786
CREATE TABLE t3 (a3 VARBINARY(3) PRIMARY KEY);
 
2787
INSERT INTO t1 VALUES (1,10), (2,20), (3,30), (4,40);
 
2788
INSERT INTO t2 VALUES (2), (3), (4), (5);
 
2789
INSERT INTO t3 VALUES (10), (20), (30);
 
2790
SELECT LEFT(t1.a1,1) FROM t1,t3 WHERE t1.b1=t3.a3;
 
2791
SELECT a2 FROM t2 WHERE t2.a2 IN (SELECT t1.a1 FROM t1,t3 WHERE t1.b1=t3.a3);
 
2792
DROP TABLE t1, t2, t3;
 
2793
 
 
2794
#
2721
2795
# Bug #30788: Inconsistent retrieval of char/varchar
2722
2796
#
2723
2797
 
2724
 
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10)) ENGINE=MyISAM;
 
2798
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10));
2725
2799
INSERT INTO t1 VALUES ('a', 'aa');
2726
2800
INSERT INTO t1 VALUES ('a', 'aaa');
2727
2801
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
2730
2804
EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
2731
2805
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
2732
2806
 
2733
 
CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10)) ENGINE=MyISAM;
 
2807
CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10));
2734
2808
INSERT INTO t2 SELECT * FROM t1;
2735
2809
CREATE INDEX I1 ON t2 (a);
2736
2810
CREATE INDEX I2 ON t2 (b);
2747
2821
# occasions
2748
2822
#
2749
2823
 
2750
 
CREATE TABLE t1(a INT, b INT) ENGINE=MyISAM;
 
2824
CREATE TABLE t1(a INT, b INT);
2751
2825
INSERT INTO t1 VALUES (1,1), (1,2), (2,3), (2,4);
2752
2826
 
2753
2827
--error ER_BAD_FIELD_ERROR
2777
2851
# Bug #32036: EXISTS within a WHERE clause with a UNION crashes MySQL 5.122
2778
2852
#
2779
2853
 
2780
 
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
2781
 
CREATE TABLE t2 (a INT) ENGINE=MyISAM;
 
2854
CREATE TABLE t1 (a INT);
 
2855
CREATE TABLE t2 (a INT);
2782
2856
 
2783
2857
INSERT INTO t1 VALUES (1),(2);
2784
2858
INSERT INTO t2 VALUES (1),(2);
2800
2874
CREATE TABLE t4 (
2801
2875
  f7 varchar(32) collate utf8_bin NOT NULL default '',
2802
2876
  f10 varchar(32) collate utf8_bin default NULL,
2803
 
  PRIMARY KEY  (f7))
2804
 
  ENGINE=MyISAM;
2805
 
 
 
2877
  PRIMARY KEY  (f7)
 
2878
);
2806
2879
INSERT INTO t4 VALUES(1,1), (2,null);
2807
2880
 
2808
2881
CREATE TABLE t2 (
2810
2883
  f2 varchar(50) collate utf8_bin default NULL,
2811
2884
  f3 varchar(10) collate utf8_bin default NULL,
2812
2885
  PRIMARY KEY  (f4),
2813
 
  UNIQUE KEY uk1 (f2))
2814
 
  ENGINE=MyISAM;
2815
 
 
 
2886
  UNIQUE KEY uk1 (f2)
 
2887
);
2816
2888
INSERT INTO t2 VALUES(1,1,null), (2,2,null);
2817
2889
 
2818
 
CREATE TABLE t1  (
 
2890
CREATE TABLE t1 (
2819
2891
  f8 varchar(32) collate utf8_bin NOT NULL default '',
2820
2892
  f1 varchar(10) collate utf8_bin default NULL,
2821
2893
  f9 varchar(32) collate utf8_bin default NULL,
2822
 
  PRIMARY KEY  (f8))
2823
 
  ENGINE=MyISAM;
2824
 
 
 
2894
  PRIMARY KEY  (f8)
 
2895
);
2825
2896
INSERT INTO t1 VALUES (1,'P',1), (2,'P',1), (3,'R',2);
2826
2897
 
2827
2898
CREATE TABLE t3 (
2828
2899
  f6 varchar(32) collate utf8_bin NOT NULL default '',
2829
2900
  f5 varchar(50) collate utf8_bin default NULL,
2830
 
  PRIMARY KEY (f6))
2831
 
  ENGINE=MyISAM;
2832
 
 
 
2901
  PRIMARY KEY (f6)
 
2902
);
2833
2903
INSERT INTO t3 VALUES (1,null), (2,null);
2834
2904
 
2835
2905
SELECT
2859
2929
#
2860
2930
 
2861
2931
create table t_out (subcase char(3),
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;
 
2932
                    a1 char(2), b1 char(2), c1 char(2));
 
2933
create table t_in  (a2 char(2), b2 char(2), c2 char(2));
2864
2934
 
2865
2935
insert into t_out values ('A.1','2a', NULL, '2a');
2866
2936
#------------------------- A.2 - impossible
3034
3104
#
3035
3105
# Bug#20835 (literal string with =any values)
3036
3106
#
3037
 
CREATE TABLE t1 (s1 char(1)) ENGINE=MyISAM;
 
3107
CREATE TABLE t1 (s1 char(1));
3038
3108
INSERT INTO t1 VALUES ('a');
3039
 
SELECT * FROM t1 WHERE 'a' = ANY (SELECT s1 FROM t1);
 
3109
SELECT * FROM t1 WHERE _utf8'a' = ANY (SELECT s1 FROM t1);
3040
3110
DROP TABLE t1;
3041
3111
 
3042
3112
#
3043
3113
# Bug#33204: INTO is allowed in subselect, causing inconsistent results
3044
3114
#
3045
 
CREATE TABLE t1( a INT ) ENGINE=MyISAM;
 
3115
CREATE TABLE t1( a INT );
3046
3116
INSERT INTO t1 VALUES (1),(2);
3047
3117
 
3048
 
CREATE TABLE t2( a INT, b INT ) ENGINE=MyISAM;
 
3118
CREATE TABLE t2( a INT, b INT );
3049
3119
 
3050
3120
--error ER_PARSE_ERROR
3051
3121
SELECT *