~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/subselect.result

  • Committer: Brian Aker
  • Date: 2009-06-16 00:53:22 UTC
  • mto: This revision was merged to the branch mainline in revision 1094.
  • Revision ID: brian@gaz-20090616005322-w0ode4jul9z8s2y9
Partial fix for tests for tmp

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Initialise
2
1
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
3
2
select (select 2);
4
3
(select 2)
132
131
SELECT 1 as a,(SELECT a+a) b,(SELECT b);
133
132
a       b       (SELECT b)
134
133
1       2       2
135
 
create table t1 (a int);
136
 
create table t2 (a int, b int);
137
 
create table t3 (a int);
138
 
create table t4 (a int not null, b int not null);
 
134
create table t1 (a int) ENGINE=MyISAM;
 
135
create table t2 (a int, b int) ENGINE=MyISAM;
 
136
create table t3 (a int) ENGINE=MyISAM;
 
137
create table t4 (a int not null, b int not null) ENGINE=MyISAM;
139
138
insert into t1 values (2);
140
139
insert into t2 values (1,7),(2,7);
141
140
insert into t4 values (4,8),(3,8),(5,9);
178
177
3       8
179
178
explain extended (select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a);
180
179
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
181
 
1       PRIMARY t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
182
 
2       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using filesort
183
 
3       UNION   t4      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
184
 
4       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    #       100.00  
185
 
NULL    UNION RESULT    <union1,3>      ALL     NULL    NULL    NULL    NULL    #       NULL    
 
180
1       PRIMARY t2      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
 
181
2       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using filesort
 
182
3       UNION   t4      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
183
4       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    2       100.00  
 
184
NULL    UNION RESULT    <union1,3>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
186
185
Warnings:
187
186
Note    1003    (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` AS `a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) AS `max(t2.a)*4` from `test`.`t2`)) order by `a`)
188
187
select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2;
196
195
explain extended select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from 
197
196
(select * from t2 where a>1) as tt;
198
197
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
199
 
1       PRIMARY <derived3>      system  NULL    NULL    NULL    NULL    #       100.00  
200
 
3       DERIVED t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
201
 
2       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where; Using filesort
 
198
1       PRIMARY <derived3>      system  NULL    NULL    NULL    NULL    1       100.00  
 
199
3       DERIVED t2      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
 
200
2       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where; Using filesort
202
201
Warnings:
203
202
Note    1003    select (select `test`.`t3`.`a` AS `a` from `test`.`t3` where (`test`.`t3`.`a` < 8) order by 1 desc limit 1) AS `(select t3.a from t3 where a<8 order by 1 desc limit 1)`,'2' AS `a` from (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`a` > 1)) `tt`
204
203
select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3) order by 1 desc limit 1);
216
215
9       7.5000
217
216
explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4;
218
217
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
219
 
1       PRIMARY t4      ALL     NULL    NULL    NULL    NULL    #       100.00  
220
 
2       DEPENDENT SUBQUERY      t2      ALL     NULL    NULL    NULL    NULL    #       100.00  
221
 
3       DEPENDENT SUBQUERY      t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
 
218
1       PRIMARY t4      ALL     NULL    NULL    NULL    NULL    3       100.00  
 
219
2       DEPENDENT SUBQUERY      t2      ALL     NULL    NULL    NULL    NULL    2       100.00  
 
220
3       DEPENDENT SUBQUERY      t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
222
221
Warnings:
223
222
Note    1276    Field or reference 'test.t4.a' of SELECT #3 was resolved in SELECT #1
224
223
Note    1003    select `test`.`t4`.`b` AS `b`,(select avg((`test`.`t2`.`a` + (select min(`test`.`t3`.`a`) AS `min(t3.a)` from `test`.`t3` where (`test`.`t3`.`a` >= `test`.`t4`.`a`)))) AS `avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a))` from `test`.`t2`) AS `(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)` from `test`.`t4`
243
242
a
244
243
6
245
244
3
246
 
# Rewrite: select * from t3 where not exists (select b from t2 where a <> b);
247
245
select * from t3 where a = all (select b from t2);
248
246
a
249
247
7
265
263
7
266
264
explain extended select * from t3 where a >= any (select b from t2);
267
265
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
268
 
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
269
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    #       100.00  
 
266
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
267
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    3       100.00  
270
268
Warnings:
271
269
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>((`test`.`t3`.`a` >= (select min(`test`.`t2`.`b`) from `test`.`t2`)))
272
270
select * from t3 where a >= all (select b from t2);
278
276
select * from t3 where a in (select * from t2);
279
277
ERROR 21000: Operand should contain 1 column(s)
280
278
insert into t4 values (12,7),(1,7),(10,9),(9,6),(7,6),(3,9),(1,10);
281
 
# empty set
282
279
select b,max(a) as ma from t4 group by b having b < (select max(t2.a) from t2 where t2.b=t4.b);
283
280
b       ma
284
281
insert into t2 values (2,10);
289
286
select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 where t2.b=t4.b);
290
287
b       ma
291
288
7       12
292
 
create temporary table t5 (a int) ENGINE=MyISAM;
 
289
create table t5 (a int) ENGINE=MyISAM;
293
290
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
294
291
(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)       a
295
292
NULL    1
306
303
2       2
307
304
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;
308
305
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
309
 
1       PRIMARY t2      ALL     NULL    NULL    NULL    NULL    #       100.00  
310
 
2       DEPENDENT SUBQUERY      t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
311
 
3       DEPENDENT UNION t5      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
312
 
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    #       NULL    
 
306
1       PRIMARY t2      ALL     NULL    NULL    NULL    NULL    2       100.00  
 
307
2       DEPENDENT SUBQUERY      t1      system  NULL    NULL    NULL    NULL    1       100.00  
 
308
3       DEPENDENT UNION t5      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
 
309
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
313
310
Warnings:
314
311
Note    1276    Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
315
312
Note    1276    Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1
316
 
Note    1003    select (select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`a`) union select `test`.`t5`.`a` AS `a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`)) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
 
313
Note    1003    select (select '2' AS `a` from `test`.`t1` where ('2' = `test`.`t2`.`a`) union select `test`.`t5`.`a` AS `a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`)) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
317
314
select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
318
315
ERROR 21000: Subquery returns more than 1 row
319
 
create temporary table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq)) ENGINE=MyISAM;
320
 
create temporary table t7( uq int primary key, name char(25)) ENGINE=MyISAM;
 
316
create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq)) ENGINE=MyISAM;
 
317
create table t7( uq int primary key, name char(25)) ENGINE=MyISAM;
321
318
insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta");
322
319
insert into t6 values (1,1),(1,2),(2,2),(1,3);
323
320
select * from t6 where exists (select * from t7 where uq = clinic_uq);
332
329
Warnings:
333
330
Note    1276    Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1
334
331
Note    1003    select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where exists(select 1 AS `Not_used` from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`))
335
 
# not unique fields
336
332
select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
337
333
ERROR 23000: Column 'a' in field list is ambiguous
338
 
# different tipes & group functions
339
334
drop table t1,t2,t3;
340
 
CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0');
 
335
CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0') ENGINE=MyISAM;
341
336
INSERT INTO t3 VALUES ('W','a'),('A','c'),('J','b');
342
 
CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0');
 
337
CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0') ENGINE=MyISAM;
343
338
INSERT INTO t2 VALUES ('W','1'),('A','3'),('J','2');
344
 
CREATE TABLE t1 (a varchar(20),b date NULL);
 
339
CREATE TABLE t1 (a varchar(20),b date NULL) ENGINE=MyISAM;
345
340
INSERT INTO t1 VALUES ('W','1732-02-22'),('A','1735-10-30'),('J','1743-04-13');
346
341
SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1);
347
342
a       b
357
352
`email` varchar(60) NOT NULL default '',
358
353
PRIMARY KEY  (`pseudo`),
359
354
UNIQUE KEY `email` (`email`)
360
 
);
 
355
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
361
356
INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
362
357
INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
363
358
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
364
359
EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
365
360
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
366
 
1       PRIMARY t8      const   PRIMARY PRIMARY 142     const   #       100.00  Using index
367
 
4       SUBQUERY        t8      const   PRIMARY PRIMARY 142             #       100.00  Using index
368
 
2       SUBQUERY        t8      const   PRIMARY PRIMARY 142     const   #       100.00  
369
 
3       SUBQUERY        t8      const   PRIMARY PRIMARY 142             #       100.00  Using index
 
361
1       PRIMARY t8      const   PRIMARY PRIMARY 142     const   1       100.00  Using index
 
362
4       SUBQUERY        t8      const   PRIMARY PRIMARY 142             1       100.00  Using index
 
363
2       SUBQUERY        t8      const   PRIMARY PRIMARY 142     const   1       100.00  
 
364
3       SUBQUERY        t8      const   PRIMARY PRIMARY 142             1       100.00  Using index
370
365
Warnings:
371
366
Note    1003    select 'joce' AS `pseudo`,(select 'test' AS `email` from `test`.`t8` where ('joce' = (select 'joce' AS `pseudo` from `test`.`t8` where ('joce' = 'joce')))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where ('joce' = (select 'joce' AS `pseudo` from `test`.`t8` where ('joce' = 'joce')))
372
367
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
381
376
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo LIKE '%joce%');
382
377
ERROR 21000: Subquery returns more than 1 row
383
378
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
384
 
#searchconthardwarefr3 forumconthardwarefr7
385
 
CREATE TEMPORARY TABLE `t1` (
 
379
CREATE TABLE `t1` (
386
380
`topic` bigint NOT NULL default '0',
387
381
`date` date NULL,
388
382
`pseudo` varchar(35) NOT NULL default '',
393
387
('43506','2002-10-02','joce'),('40143','2002-08-03','joce');
394
388
EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
395
389
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
396
 
1       SIMPLE  t1      index   NULL    PRIMARY 154     NULL    2       100.00  Using where; Using index
 
390
1       SIMPLE  t1      index   NULL    PRIMARY 153     NULL    2       100.00  Using where; Using index
397
391
Warnings:
398
392
Note    1003    select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')
399
393
EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
400
394
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
401
395
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
402
 
2       SUBQUERY        t1      index   NULL    PRIMARY 154     NULL    2       100.00  Using where; Using index
 
396
2       SUBQUERY        t1      index   NULL    PRIMARY 153     NULL    2       100.00  Using where; Using index
403
397
Warnings:
404
398
Note    1003    select (select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')`
405
399
SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
424
418
Warnings:
425
419
Note    1003    select 1 AS `1` from `test`.`t1` where 1
426
420
drop table t1;
427
 
#forumconthardwarefr7 searchconthardwarefr7
428
421
CREATE TABLE `t1` (
429
422
`numeropost` bigint NOT NULL auto_increment,
430
423
`maxnumrep` int NOT NULL default '0',
431
424
PRIMARY KEY  (`numeropost`),
432
425
UNIQUE KEY `maxnumrep` (`maxnumrep`)
433
 
);
 
426
) ENGINE=MyISAM ROW_FORMAT=FIXED;
434
427
INSERT INTO t1 (numeropost,maxnumrep) VALUES (40143,1),(43506,2);
435
428
CREATE TABLE `t2` (
436
429
`mot` varchar(30) NOT NULL default '',
438
431
`date` date NULL,
439
432
`pseudo` varchar(35) NOT NULL default '',
440
433
PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`)
441
 
);
 
434
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
442
435
INSERT INTO t2 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce'), ('joce','43506','2002-10-22','joce');
443
436
select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
444
437
a
497
490
joce    40143   2002-10-22      joce    1
498
491
joce    43506   2002-10-22      joce    0
499
492
drop table t1,t2;
500
 
#forumconthardwarefr7
501
493
CREATE TABLE `t1` (
502
494
`numeropost` bigint NOT NULL auto_increment,
503
495
`maxnumrep` int NOT NULL default '0',
504
496
PRIMARY KEY  (`numeropost`),
505
497
UNIQUE KEY `maxnumrep` (`maxnumrep`)
506
 
);
 
498
) ENGINE=MyISAM ROW_FORMAT=FIXED;
507
499
INSERT INTO t1 (numeropost,maxnumrep) VALUES (1,0),(2,1);
508
500
select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
509
501
ERROR 21000: Subquery returns more than 1 row
510
502
select numeropost as a FROM t1 ORDER BY (SELECT 1 FROM t1 HAVING a=1);
511
503
ERROR 21000: Subquery returns more than 1 row
512
504
drop table t1;
513
 
create table t1 (a int);
 
505
create table t1 (a int) ENGINE=MyISAM;
514
506
insert into t1 values (1),(2),(3);
515
507
(select * from t1) union (select * from t1) order by (select a from t1 limit 1);
516
508
a
518
510
2
519
511
3
520
512
drop table t1;
521
 
#iftest
522
 
CREATE TEMPORARY TABLE t1 (field char(1) NOT NULL DEFAULT 'b') ENGINE=MyISAM;
 
513
CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b') ENGINE=MyISAM;
523
514
INSERT INTO t1 VALUES ();
524
515
SELECT field FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) a HAVING field='b');
525
516
ERROR 21000: Subquery returns more than 1 row
526
517
drop table t1;
527
 
# threadhardwarefr7
528
518
CREATE TABLE `t1` (
529
519
`numeropost` bigint NOT NULL default '0',
530
520
`numreponse` int NOT NULL auto_increment,
532
522
PRIMARY KEY  (`numeropost`,`numreponse`),
533
523
UNIQUE KEY `numreponse` (`numreponse`),
534
524
KEY `pseudo` (`pseudo`,`numeropost`)
535
 
);
 
525
) ENGINE=MyISAM;
536
526
SELECT (SELECT numeropost FROM t1 HAVING numreponse=a),numreponse FROM (SELECT * FROM t1) as a;
537
527
ERROR 42S22: Reference 'numreponse' not supported (forward reference in item list)
538
528
SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=a) FROM (SELECT * FROM t1) as a;
544
534
ERROR 21000: Subquery returns more than 1 row
545
535
EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1';
546
536
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
547
 
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    #       NULL    Select tables optimized away
 
537
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Select tables optimized away
548
538
Warnings:
549
539
Note    1003    select max(`test`.`t1`.`numreponse`) AS `MAX(numreponse)` from `test`.`t1` where multiple equal(1, `test`.`t1`.`numeropost`)
550
540
EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1');
551
541
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
552
 
1       PRIMARY t1      const   PRIMARY,numreponse      PRIMARY 12      const,const     #       100.00  Using index
553
 
2       SUBQUERY        NULL    NULL    NULL    NULL    NULL    NULL    #       NULL    Select tables optimized away
 
542
1       PRIMARY t1      const   PRIMARY,numreponse      PRIMARY 12      const,const     1       100.00  Using index
 
543
2       SUBQUERY        NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Select tables optimized away
554
544
Warnings:
555
545
Note    1003    select '3' AS `numreponse` from `test`.`t1` where 1
556
546
drop table t1;
557
 
CREATE TEMPORARY TABLE t1 (a int) ENGINE=MyISAM;
 
547
CREATE TABLE t1 (a int) ENGINE=MyISAM;
558
548
INSERT INTO t1 VALUES (1);
559
549
SELECT 1 FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1;
560
550
1
561
551
1
562
552
drop table t1;
563
 
#update with subselects
564
 
create table t1 (a int NOT NULL, b int, primary key (a));
565
 
create table t2 (a int NOT NULL, b int, primary key (a));
 
553
create table t1 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
 
554
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
566
555
insert into t1 values (0, 10),(1, 11),(2, 12);
567
556
insert into t2 values (1, 21),(2, 22),(3, 23);
568
557
select * from t1;
581
570
1       21
582
571
2       22
583
572
drop table t1, t2;
584
 
#delete with subselects
585
 
create table t1 (a int NOT NULL, b int, primary key (a));
586
 
create table t2 (a int NOT NULL, b int, primary key (a));
 
573
create table t1 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
 
574
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
587
575
insert into t1 values (0, 10),(1, 11),(2, 12);
588
576
insert into t2 values (1, 21),(2, 12),(3, 23);
589
577
select * from t1;
604
592
0       10
605
593
1       11
606
594
drop table t1, t2;
607
 
#insert with subselects
608
 
CREATE TABLE t1 (x int);
609
 
create table t2 (a int);
610
 
create table t3 (b int);
 
595
create table t11 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
 
596
create table t12 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
 
597
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
 
598
insert into t11 values (0, 10),(1, 11),(2, 12);
 
599
insert into t12 values (33, 10),(22, 11),(2, 12);
 
600
insert into t2 values (1, 21),(2, 12),(3, 23);
 
601
select * from t11;
 
602
a       b
 
603
0       10
 
604
1       11
 
605
2       12
 
606
select * from t12;
 
607
a       b
 
608
2       12
 
609
22      11
 
610
33      10
 
611
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
 
612
ERROR HY000: You can't specify target table 't12' for update in FROM clause
 
613
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
 
614
ERROR 21000: Subquery returns more than 1 row
 
615
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
 
616
select * from t11;
 
617
a       b
 
618
0       10
 
619
1       11
 
620
select * from t12;
 
621
a       b
 
622
22      11
 
623
33      10
 
624
drop table t11, t12, t2;
 
625
CREATE TABLE t1 (x int) ENGINE=MyISAM;
 
626
create table t2 (a int) ENGINE=MyISAM;
 
627
create table t3 (b int) ENGINE=MyISAM;
611
628
insert into t2 values (1);
612
629
insert into t3 values (1),(2);
613
630
INSERT INTO t1 (x) VALUES ((SELECT x FROM t1));
631
648
2
632
649
3
633
650
3
634
 
# After this, only data based on old t1 records should have been added.
635
651
INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2;
636
652
select * from t1;
637
653
x
653
669
11
654
670
11
655
671
2
656
 
#
657
 
#TODO: should be uncommented after bug 380 fix pushed
658
 
#INSERT INTO t1 (x) SELECT (SELECT SUM(a)+b FROM t2) from t3;
659
 
#select * from t1;
660
672
drop table t1, t2, t3;
661
 
#replace with subselects
662
 
CREATE TABLE t1 (x int not null, y int, primary key (x));
663
 
create table t2 (a int);
664
 
create temporary table t3 (a int) ENGINE=MyISAM;
 
673
CREATE TABLE t1 (x int not null, y int, primary key (x)) ENGINE=MyISAM;
 
674
create table t2 (a int) ENGINE=MyISAM;
 
675
create table t3 (a int) ENGINE=MyISAM;
665
676
insert into t2 values (1);
666
677
insert into t3 values (1),(2);
667
678
select * from t1;
697
708
drop table t1, t2, t3;
698
709
SELECT * FROM (SELECT 1) b WHERE 1 IN (SELECT *);
699
710
ERROR HY000: No tables used
700
 
CREATE TABLE t2 (id int default NULL, KEY id (id));
 
711
CREATE TABLE t2 (id int default NULL, KEY id (id)) ENGINE=MyISAM;
701
712
INSERT INTO t2 VALUES (1),(2);
702
713
SELECT * FROM t2 WHERE id IN (SELECT 1);
703
714
id
704
715
1
705
716
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1);
706
717
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
707
 
1       PRIMARY t2      ref     id      id      5       const   1       100.00  Using where; Using index
 
718
1       PRIMARY t2      ref     id      id      5       const   1       100.00  Using index
708
719
Warnings:
709
720
Note    1249    Select 2 was reduced during optimization
710
721
Note    1003    select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = 1)
716
727
2
717
728
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1));
718
729
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
719
 
1       PRIMARY t2      ref     id      id      5       const   1       100.00  Using where; Using index
 
730
1       PRIMARY t2      ref     id      id      5       const   1       100.00  Using index
720
731
Warnings:
721
732
Note    1249    Select 3 was reduced during optimization
722
733
Note    1249    Select 2 was reduced during optimization
723
 
Note    1003    select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = <cache>((1 + 1)))
 
734
Note    1003    select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = (1 + 1))
724
735
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3);
725
736
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
726
737
1       PRIMARY t2      index   NULL    id      5       NULL    2       100.00  Using where; Using index
742
753
id
743
754
1
744
755
2
745
 
CREATE TEMPORARY TABLE t1 (id int default NULL, KEY id (id)) ENGINE=MyISAM;
 
756
CREATE TABLE t1 (id int default NULL, KEY id (id)) ENGINE=MyISAM;
746
757
INSERT INTO t1 values (1),(1);
747
758
UPDATE t2 SET id=(SELECT * FROM t1);
748
759
ERROR 21000: Subquery returns more than 1 row
749
760
drop table t2, t1;
750
 
#NULL test
751
 
create temporary table t1 (a int) ENGINE=MyISAM;
 
761
create table t1 (a int) ENGINE=MyISAM;
752
762
insert into t1 values (1),(2),(3);
753
763
select 1 IN (SELECT * from t1);
754
764
1 IN (SELECT * from t1)
782
792
10 > ANY (SELECT * from t1)
783
793
1
784
794
drop table t1;
785
 
create temporary table t1 (a varchar(20)) ENGINE=MyISAM;
 
795
create table t1 (a varchar(20)) ENGINE=MyISAM;
786
796
insert into t1 values ('A'),('BC'),('DEF');
787
797
select 'A' IN (SELECT * from t1);
788
798
'A' IN (SELECT * from t1)
816
826
'XYZS' > ANY (SELECT * from t1)
817
827
1
818
828
drop table t1;
819
 
create temporary table t1 (a float) ENGINE=MyISAM;
 
829
create table t1 (a float) ENGINE=MyISAM;
820
830
insert into t1 values (1.5),(2.5),(3.5);
821
831
select 1.5 IN (SELECT * from t1);
822
832
1.5 IN (SELECT * from t1)
862
872
4.5
863
873
NULL
864
874
drop table t1;
865
 
#
866
 
# Null with keys
867
 
#
868
 
CREATE TEMPORARY TABLE t1 (a int NOT NULL default '0', PRIMARY KEY  (a)) ENGINE=MyISAM;
869
 
CREATE TEMPORARY TABLE t2 (a int default '0', INDEX (a)) ENGINE=MyISAM;
 
875
CREATE TABLE t1 (a int NOT NULL default '0', PRIMARY KEY  (a)) ENGINE=MyISAM;
 
876
CREATE TABLE t2 (a int default '0', INDEX (a)) ENGINE=MyISAM;
870
877
INSERT INTO t1 VALUES (1),(2),(3),(4);
871
878
INSERT INTO t2 VALUES (1),(2),(3);
872
879
SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
881
888
2       DEPENDENT SUBQUERY      t2      index_subquery  a       a       5       func    2       100.00  Using index
882
889
Warnings:
883
890
Note    1003    select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t2 on a checking NULL having <is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2)` from `test`.`t1`
884
 
CREATE TEMPORARY TABLE t3 (a int default '0') ENGINE=MyISAM;
 
891
CREATE TABLE t3 (a int default '0') ENGINE=MyISAM;
885
892
INSERT INTO t3 VALUES (1),(2),(3);
886
893
SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
887
894
a       t1.a in (select t2.a from t2,t3 where t3.a=t2.a)
892
899
explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
893
900
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
894
901
1       PRIMARY t1      index   NULL    PRIMARY 4       NULL    4       100.00  Using index
895
 
2       DEPENDENT SUBQUERY      t2      ref_or_null     a       a       5       func    2       100.00  Using where; Using index
 
902
2       DEPENDENT SUBQUERY      t2      ref_or_null     a       a       5       func    2       100.00  Using index
896
903
2       DEPENDENT SUBQUERY      t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where; Using join buffer
897
904
Warnings:
898
905
Note    1003    select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
899
906
drop table t1,t2,t3;
900
 
#LIMIT is not supported now
901
 
#create table t1 (a float) ENGINE=MyISAM;
902
 
#--error ER_NOT_SUPPORTED_YET
903
 
#select 10.5 IN (SELECT * from t1 LIMIT 1);
904
 
#--error ER_NOT_SUPPORTED_YET
905
 
#select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
906
 
#drop table t1;
907
 
#
908
 
#create table t1 (a int, b int, c varchar(10)) ENGINE=MyISAM;
909
 
#create table t2 (a int) ENGINE=MyISAM;
910
 
#insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c');
911
 
#insert into t2 values (1),(2),(NULL);
912
 
#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;
913
 
#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;
914
 
#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;
915
 
#drop table t1,t2;
916
 
#
917
 
#create table t1 (a int, b real, c varchar(10)) ENGINE=MyISAM;
918
 
#insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');
919
 
#select ROW(1, 1, 'a') IN (select a,b,c from t1);
920
 
#select ROW(1, 2, 'a') IN (select a,b,c from t1);
921
 
#select ROW(1, 1, 'a') IN (select b,a,c from t1);
922
 
#select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null);
923
 
#select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null);
924
 
#select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null);
925
 
#select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a');
926
 
#select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a');
927
 
#select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
928
 
#--error ER_NOT_SUPPORTED_YET
929
 
#select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
930
 
#drop table t1;
931
 
#test of uncacheable subqueries
932
 
CREATE TABLE t1 (a int);
 
907
CREATE TABLE t1 (a int) ENGINE=MyISAM;
933
908
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
934
909
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
935
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    1       100.00  
936
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    1       100.00  
 
910
1       PRIMARY t1      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
 
911
2       SUBQUERY        t1      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
937
912
Warnings:
938
913
Note    1003    select (select rand() AS `RAND()` from `test`.`t1`) AS `(SELECT RAND() FROM t1)` from `test`.`t1`
939
914
EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1;
940
915
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
941
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    1       100.00  
942
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    1       100.00  
 
916
1       PRIMARY t1      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
 
917
2       SUBQUERY        t1      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
943
918
Warnings:
944
919
Note    1003    select (select benchmark(1,1) AS `BENCHMARK(1,1)` from `test`.`t1`) AS `(SELECT BENCHMARK(1,1) FROM t1)` from `test`.`t1`
945
920
drop table t1;
946
 
CREATE TEMPORARY TABLE `t1` (
 
921
CREATE TABLE `t1` (
947
922
`mot` varchar(30) NOT NULL default '',
948
923
`topic` bigint NOT NULL default '0',
949
924
`date` date NULL DEFAULT '2009-01-20',
952
927
KEY `pseudo` (`pseudo`,`date`,`topic`),
953
928
KEY `topic` (`topic`)
954
929
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
955
 
CREATE TEMPORARY TABLE `t2` (
 
930
CREATE TABLE `t2` (
956
931
`mot` varchar(30) NOT NULL default '',
957
932
`topic` bigint NOT NULL default '0',
958
933
`date` date NULL default '1997-08-29',
961
936
KEY `pseudo` (`pseudo`,`date`,`topic`),
962
937
KEY `topic` (`topic`)
963
938
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
964
 
CREATE TEMPORARY TABLE `t3` (
 
939
CREATE TABLE `t3` (
965
940
`numeropost` bigint NOT NULL auto_increment,
966
941
`maxnumrep` int NOT NULL default '0',
967
942
PRIMARY KEY  (`numeropost`),
987
962
SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
988
963
a       (SELECT a)
989
964
1       1
990
 
CREATE TEMPORARY TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT 1)) a;
991
 
SHOW CREATE TABLE t1;
992
 
Table   Create Table
993
 
t1      CREATE TEMPORARY TABLE `t1` (
994
 
  `a` INT NOT NULL DEFAULT '0',
995
 
  `(SELECT 1)` INT NOT NULL DEFAULT '0'
996
 
) ENGINE=MyISAM COLLATE = utf8_general_ci
997
 
drop table t1;
998
 
CREATE TEMPORARY TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
999
 
SHOW CREATE TABLE t1;
1000
 
Table   Create Table
1001
 
t1      CREATE TEMPORARY TABLE `t1` (
1002
 
  `a` INT NOT NULL DEFAULT '0',
1003
 
  `(SELECT a)` INT NOT NULL DEFAULT '0'
1004
 
) ENGINE=MyISAM COLLATE = utf8_general_ci
1005
 
drop table t1;
1006
 
CREATE TEMPORARY TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a;
1007
 
SHOW CREATE TABLE t1;
1008
 
Table   Create Table
1009
 
t1      CREATE TEMPORARY TABLE `t1` (
1010
 
  `a` INT NOT NULL DEFAULT '0',
1011
 
  `(SELECT a+0)` INT NOT NULL DEFAULT '0'
1012
 
) ENGINE=MyISAM COLLATE = utf8_general_ci
1013
 
drop table t1;
1014
 
CREATE TEMPORARY TABLE t1 ENGINE=MyISAM SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a;
 
965
CREATE TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT 1)) a;
 
966
SHOW CREATE TABLE t1;
 
967
Table   Create Table
 
968
t1      CREATE TABLE `t1` (
 
969
  `a` int NOT NULL DEFAULT '0',
 
970
  `(SELECT 1)` int NOT NULL DEFAULT '0'
 
971
) ENGINE=MyISAM
 
972
drop table t1;
 
973
CREATE TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
 
974
SHOW CREATE TABLE t1;
 
975
Table   Create Table
 
976
t1      CREATE TABLE `t1` (
 
977
  `a` int NOT NULL DEFAULT '0',
 
978
  `(SELECT a)` int NOT NULL DEFAULT '0'
 
979
) ENGINE=MyISAM
 
980
drop table t1;
 
981
CREATE TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a;
 
982
SHOW CREATE TABLE t1;
 
983
Table   Create Table
 
984
t1      CREATE TABLE `t1` (
 
985
  `a` int NOT NULL DEFAULT '0',
 
986
  `(SELECT a+0)` int NOT NULL DEFAULT '0'
 
987
) ENGINE=MyISAM
 
988
drop table t1;
 
989
CREATE TABLE t1 ENGINE=MyISAM SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a;
1015
990
select * from t1;
1016
991
a
1017
992
2
1018
993
SHOW CREATE TABLE t1;
1019
994
Table   Create Table
1020
 
t1      CREATE TEMPORARY TABLE `t1` (
1021
 
  `a` BIGINT NOT NULL
1022
 
) ENGINE=MyISAM COLLATE = utf8_general_ci
 
995
t1      CREATE TABLE `t1` (
 
996
  `a` bigint NOT NULL
 
997
) ENGINE=MyISAM
1023
998
drop table t1;
1024
 
create table t1 (a int);
 
999
create table t1 (a int) ENGINE=MyISAM;
1025
1000
insert into t1 values (1), (2), (3);
1026
1001
explain extended select a,(select (select rand() from t1 limit 1)  from t1 limit 1)
1027
1002
from t1;
1028
1003
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1029
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  
1030
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    #       100.00  
1031
 
3       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    #       100.00  
 
1004
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  
 
1005
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    3       100.00  
 
1006
3       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    3       100.00  
1032
1007
Warnings:
1033
1008
Note    1003    select `test`.`t1`.`a` AS `a`,(select (select rand() AS `rand()` from `test`.`t1` limit 1) AS `(select rand() from t1 limit 1)` from `test`.`t1` limit 1) AS `(select (select rand() from t1 limit 1)  from t1 limit 1)` from `test`.`t1`
1034
1009
drop table t1;
1035
 
#
1036
 
# error in IN
1037
 
#
1038
1010
select t1.Continent, t2.Name, t2.Population from t1 LEFT JOIN t2 ON t1.Code = t2.Country  where t2.Population IN (select max(t2.Population) AS Population from t2, t1 where t2.Country = t1.Code group by Continent);
1039
 
ERROR 42S02: Unknown table 'test.t1'
1040
 
#
1041
 
# complex subquery
1042
 
#
 
1011
ERROR 42S02: Table 'test.t1' doesn't exist
1043
1012
CREATE TABLE t1 (
1044
1013
ID int NOT NULL auto_increment,
1045
1014
name char(35) NOT NULL default '',
1047
1016
District char(20) NOT NULL default '',
1048
1017
Population int NOT NULL default '0',
1049
1018
PRIMARY KEY  (ID)
1050
 
);
 
1019
) ENGINE=MyISAM;
1051
1020
INSERT INTO t1 VALUES (130,'Sydney','AUS','New South Wales',3276207);
1052
1021
INSERT INTO t1 VALUES (131,'Melbourne','AUS','Victoria',2865329);
1053
1022
INSERT INTO t1 VALUES (132,'Brisbane','AUS','Queensland',1291117);
1068
1037
Capital int default NULL,
1069
1038
Code2 char(2) NOT NULL default '',
1070
1039
PRIMARY KEY  (Code)
1071
 
);
 
1040
) ENGINE=MyISAM;
1072
1041
INSERT INTO t2 VALUES ('AUS','Australia','Oceania','Australia and New Zealand',7741220.00,1901,18886000,79.8,351182.00,392911.00,'Australia','Constitutional Monarchy, Federation','Elisabeth II',135,'AU');
1073
1042
INSERT INTO t2 VALUES ('AZE','Azerbaijan','Asia','Middle East',86600.00,1991,7734000,62.9,4127.00,4100.00,'Azärbaycan','Federal Republic','Heydär Äliyev',144,'AZ');
1074
1043
select t2.Continent, t1.Name, t1.Population from t2 LEFT JOIN t1 ON t2.Code = t1.t2  where t1.Population IN (select max(t1.Population) AS Population from t1, t2 where t1.t2 = t2.Code group by Continent);
1075
1044
Continent       Name    Population
1076
1045
Oceania Sydney  3276207
1077
1046
drop table t1, t2;
1078
 
#
1079
 
# constants in IN
1080
 
#
1081
 
CREATE TEMPORARY TABLE `t1` (
 
1047
CREATE TABLE `t1` (
1082
1048
`id` bigint NOT NULL auto_increment,
1083
1049
`pseudo` varchar(35) NOT NULL default '',
1084
1050
PRIMARY KEY  (`id`),
1085
1051
UNIQUE KEY `pseudo` (`pseudo`)
1086
 
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
 
1052
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
1087
1053
INSERT INTO t1 (pseudo) VALUES ('test');
1088
1054
SELECT 0 IN (SELECT 1 FROM t1 a);
1089
1055
0 IN (SELECT 1 FROM t1 a)
1105
1071
Warnings:
1106
1072
Note    1003    select <in_optimizer>(0,<exists>(select 1 AS `Not_used` from `test`.`t1` `a` where 0)) AS `0 IN (SELECT 1 FROM t1 a)`
1107
1073
drop table t1;
1108
 
CREATE TEMPORARY TABLE `t1` (
 
1074
CREATE TABLE `t1` (
1109
1075
`i` int NOT NULL default '0',
1110
1076
PRIMARY KEY  (`i`)
1111
1077
) ENGINE=MyISAM;
1118
1084
i
1119
1085
3
1120
1086
drop table t1;
1121
 
#
1122
 
# correct NULL in <CONSTANT> IN (SELECT ...)
1123
 
#
1124
 
create temporary table t1 (a int, unique index indexa (a)) ENGINE=MyISAM;
 
1087
CREATE TABLE t1 (
 
1088
id int default NULL
 
1089
) ENGINE=MyISAM;
 
1090
INSERT INTO t1 VALUES (1),(1),(2),(2),(1),(3);
 
1091
CREATE TABLE t2 (
 
1092
id int default NULL,
 
1093
name varchar(15) default NULL
 
1094
) ENGINE=MyISAM;
 
1095
INSERT INTO t2 VALUES (4,'vita'), (1,'vita'), (2,'vita'), (1,'vita');
 
1096
update t1, t2 set t2.name='lenka' where t2.id in (select id from t1);
 
1097
select * from t2;
 
1098
id      name
 
1099
4       vita
 
1100
1       lenka
 
1101
2       lenka
 
1102
1       lenka
 
1103
drop table t1,t2;
 
1104
create table t1 (a int, unique index indexa (a)) ENGINE=MyISAM;
1125
1105
insert into t1 values (-1), (-4), (-2), (NULL);
1126
1106
select -10 IN (select a from t1 FORCE INDEX (indexa));
1127
1107
-10 IN (select a from t1 FORCE INDEX (indexa))
1128
1108
NULL
1129
1109
drop table t1;
1130
 
#
1131
 
# Test optimization for sub selects
1132
 
#
1133
 
create table t1 (id int not null auto_increment primary key, salary int, key(salary));
 
1110
create table t1 (id int not null auto_increment primary key, salary int, key(salary)) ENGINE=MyISAM;
1134
1111
insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000);
1135
1112
explain extended SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1);
1136
1113
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1137
 
1       PRIMARY t1      ref     salary  salary  5       const   #       100.00  Using where; Using index
1138
 
2       SUBQUERY        NULL    NULL    NULL    NULL    NULL    NULL    #       NULL    Select tables optimized away
 
1114
1       PRIMARY t1      ref     salary  salary  5       const   1       100.00  Using where
 
1115
2       SUBQUERY        NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Select tables optimized away
1139
1116
Warnings:
1140
1117
Note    1003    select `test`.`t1`.`id` AS `id` from `test`.`t1` where (`test`.`t1`.`salary` = (select max(`test`.`t1`.`salary`) AS `MAX(salary)` from `test`.`t1`))
1141
1118
drop table t1;
1148
1125
UNIQUE KEY t1_PK (ID,SUB_ID),
1149
1126
KEY t1_FK (REF_ID,REF_SUB),
1150
1127
KEY t1_REFID (REF_ID)
1151
 
);
 
1128
) ENGINE=MyISAM;
1152
1129
INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
1153
1130
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
1154
1131
REF_ID
1155
1132
DROP TABLE t1;
1156
 
#
1157
 
# uninterruptable update
1158
 
#
1159
 
create temporary table t1 (a int, b int) ENGINE=MyISAM;
1160
 
create temporary table t2 (a int, b int) ENGINE=MyISAM;
 
1133
create table t1 (a int, b int) ENGINE=MyISAM;
 
1134
create table t2 (a int, b int) ENGINE=MyISAM;
1161
1135
insert into t1 values (1,0), (2,0), (3,0);
1162
1136
insert into t2 values (1,1), (2,1), (3,1), (2,2);
1163
1137
update ignore t1 set b=(select b from t2 where t1.a=t2.a);
1169
1143
2       NULL
1170
1144
3       1
1171
1145
drop table t1, t2;
1172
 
#
1173
 
# reduced subselect in ORDER BY & GROUP BY clauses
1174
 
#
1175
 
CREATE TEMPORARY TABLE `t1` (
 
1146
CREATE TABLE `t1` (
1176
1147
`id` bigint NOT NULL auto_increment,
1177
1148
`pseudo` varchar(35) NOT NULL default '',
1178
1149
`email` varchar(60) NOT NULL default '',
1179
1150
PRIMARY KEY  (`id`),
1180
1151
UNIQUE KEY `email` (`email`),
1181
1152
UNIQUE KEY `pseudo` (`pseudo`)
1182
 
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
 
1153
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
1183
1154
INSERT INTO t1 (id,pseudo,email) VALUES (1,'test','test'),(2,'test1','test1');
1184
1155
SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT id*1);
1185
1156
a       b
1189
1160
(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0);
1190
1161
a
1191
1162
1
1192
 
#
1193
 
# IN subselect optimization test
1194
 
#
1195
 
create temporary table t1 (a int not null, b int, primary key (a)) ENGINE=MyISAM;
1196
 
create temporary table t2 (a int not null, primary key (a)) ENGINE=MyISAM;
1197
 
create temporary table t3 (a int not null, b int, primary key (a)) ENGINE=MyISAM;
 
1163
create table t1 (a int not null, b int, primary key (a)) ENGINE=MyISAM;
 
1164
create table t2 (a int not null, primary key (a)) ENGINE=MyISAM;
 
1165
create table t3 (a int not null, b int, primary key (a)) ENGINE=MyISAM;
1198
1166
insert into t1 values (1,10), (2,20), (3,30),  (4,40);
1199
1167
insert into t2 values (2), (3), (4), (5);
1200
1168
insert into t3 values (10,3), (20,4), (30,5);
1205
1173
4
1206
1174
explain extended select * from t2 where t2.a in (select a from t1);
1207
1175
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1208
 
1       PRIMARY t2      index   NULL    PRIMARY 4       NULL    4       100.00  Using where; Using index
1209
 
2       SUBQUERY        t1      index   NULL    PRIMARY 4       NULL    4       100.00  Using index
 
1176
1       PRIMARY t2      index   PRIMARY PRIMARY 4       NULL    4       100.00  Using index
 
1177
1       PRIMARY t1      index   PRIMARY PRIMARY 4       NULL    4       75.00   Using where; Using index; Using join buffer
1210
1178
Warnings:
1211
 
Note    1003    select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (select `test`.`t1`.`a` AS `a` from `test`.`t1` ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key)))
 
1179
Note    1003    select `test`.`t2`.`a` AS `a` from (`test`.`t1`) join `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)
1212
1180
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1213
1181
a
1214
1182
2
1215
1183
4
1216
1184
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1217
1185
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1218
 
1       PRIMARY t2      index   NULL    PRIMARY 4       NULL    4       100.00  Using where; Using index
1219
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
1186
1       PRIMARY t2      index   PRIMARY PRIMARY 4       NULL    4       100.00  Using index
 
1187
1       PRIMARY t1      ALL     PRIMARY NULL    NULL    NULL    4       75.00   Using where; Using join buffer
1220
1188
Warnings:
1221
 
Note    1003    select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`b` <> 30) ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key)))
 
1189
Note    1003    select `test`.`t2`.`a` AS `a` from (`test`.`t1`) join `test`.`t2` where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
1222
1190
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
1223
1191
a
1224
1192
2
1225
1193
3
1226
1194
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
1227
1195
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1228
 
1       PRIMARY t2      index   NULL    PRIMARY 4       NULL    4       100.00  Using where; Using index
1229
 
2       SUBQUERY        t3      index   PRIMARY PRIMARY 4       NULL    3       100.00  Using index
1230
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    4       100.00  Using where; Using join buffer
 
1196
1       PRIMARY t2      index   PRIMARY PRIMARY 4       NULL    4       100.00  Using index
 
1197
1       PRIMARY t1      ALL     PRIMARY NULL    NULL    NULL    4       75.00   Using where; Using join buffer
 
1198
1       PRIMARY t3      eq_ref  PRIMARY PRIMARY 4       test.t1.b       1       100.00  Using index
1231
1199
Warnings:
1232
 
Note    1003    select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (select `test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t3` where (`test`.`t1`.`b` = `test`.`t3`.`a`) ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key)))
 
1200
Note    1003    select `test`.`t2`.`a` AS `a` from (`test`.`t1` join `test`.`t3`) join `test`.`t2` where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`b`))
1233
1201
drop table t1, t2, t3;
1234
 
create temporary table t1 (a int, b int, index a (a,b)) ENGINE=MyISAM;
1235
 
create temporary table t2 (a int, index a (a)) ENGINE=MyISAM;
1236
 
create temporary table t3 (a int, b int, index a (a)) ENGINE=MyISAM;
 
1202
create table t1 (a int, b int, index a (a,b)) ENGINE=MyISAM;
 
1203
create table t2 (a int, index a (a)) ENGINE=MyISAM;
 
1204
create table t3 (a int, b int, index a (a)) ENGINE=MyISAM;
1237
1205
insert into t1 values (1,10), (2,20), (3,30), (4,40);
1238
 
# making table large enough
1239
1206
insert into t2 values (2), (3), (4), (5);
1240
1207
insert into t3 values (10,3), (20,4), (30,5);
1241
1208
select * from t2 where t2.a in (select a from t1);
1245
1212
4
1246
1213
explain extended select * from t2 where t2.a in (select a from t1);
1247
1214
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1248
 
1       PRIMARY t2      index   NULL    a       5       NULL    4       100.00  Using where; Using index
1249
 
2       SUBQUERY        t1      index   NULL    a       10      NULL    10004   100.00  Using index
 
1215
1       PRIMARY t2      index   a       a       5       NULL    4       100.00  Using index
 
1216
1       PRIMARY t1      ref     a       a       5       test.t2.a       101     100.00  Using index; FirstMatch(t2)
1250
1217
Warnings:
1251
 
Note    1003    select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (select `test`.`t1`.`a` AS `a` from `test`.`t1` ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key)))
 
1218
Note    1003    select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where (`test`.`t1`.`a` = `test`.`t2`.`a`)
1252
1219
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1253
1220
a
1254
1221
2
1255
1222
4
1256
1223
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1257
1224
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1258
 
1       PRIMARY t2      index   NULL    a       5       NULL    4       100.00  Using where; Using index
1259
 
2       SUBQUERY        t1      index   NULL    a       10      NULL    10004   100.00  Using where; Using index
 
1225
1       PRIMARY t2      index   a       a       5       NULL    4       100.00  Using index
 
1226
1       PRIMARY t1      ref     a       a       5       test.t2.a       101     100.00  Using where; Using index; FirstMatch(t2)
1260
1227
Warnings:
1261
 
Note    1003    select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`b` <> 30) ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key)))
 
1228
Note    1003    select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
1262
1229
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
1263
1230
a
1264
1231
2
1265
1232
3
1266
1233
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
1267
1234
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1268
 
1       PRIMARY t2      index   NULL    a       5       NULL    4       100.00  Using where; Using index
1269
 
2       SUBQUERY        t3      index   a       a       5       NULL    3       100.00  Using index
1270
 
2       SUBQUERY        t1      index   NULL    a       10      NULL    10004   100.00  Using where; Using index; Using join buffer
 
1235
1       PRIMARY t2      index   a       a       5       NULL    4       100.00  Using index; Start temporary
 
1236
1       PRIMARY t1      ref     a       a       5       test.t2.a       101     100.00  Using index; FirstMatch(t2)
 
1237
1       PRIMARY t3      index   a       a       5       NULL    3       100.00  Using where; Using index; End temporary; Using join buffer
1271
1238
Warnings:
1272
 
Note    1003    select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (select `test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t3` where (`test`.`t1`.`b` = `test`.`t3`.`a`) ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key)))
 
1239
Note    1003    select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`b`))
1273
1240
insert into t1 values (3,31);
1274
1241
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1275
1242
a
1282
1249
4
1283
1250
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1284
1251
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1285
 
1       PRIMARY t2      index   NULL    a       5       NULL    4       100.00  Using where; Using index
1286
 
2       SUBQUERY        t1      index   NULL    a       10      NULL    10005   100.00  Using where; Using index
 
1252
1       PRIMARY t2      index   a       a       5       NULL    4       100.00  Using index
 
1253
1       PRIMARY t1      ref     a       a       5       test.t2.a       101     100.00  Using where; Using index; FirstMatch(t2)
1287
1254
Warnings:
1288
 
Note    1003    select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`b` <> 30) ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key)))
 
1255
Note    1003    select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
1289
1256
drop table t1, t2, t3;
1290
 
#
1291
 
# alloc_group_fields() working
1292
 
#
1293
 
create temporary table t1 (a int, b int) ENGINE=MyISAM;
1294
 
create temporary table t2 (a int, b int) ENGINE=MyISAM;
1295
 
create temporary table t3 (a int, b int) ENGINE=MyISAM;
 
1257
create table t1 (a int, b int) ENGINE=MyISAM;
 
1258
create table t2 (a int, b int) ENGINE=MyISAM;
 
1259
create table t3 (a int, b int) ENGINE=MyISAM;
1296
1260
insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10);
1297
1261
insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1);
1298
1262
insert into t3 values (3,3), (2,2), (1,1);
1302
1266
2       2
1303
1267
1       2
1304
1268
drop table t1,t2,t3;
1305
 
#
1306
 
# aggregate functions in HAVING test
1307
 
#
1308
 
create temporary table t1 (s1 int) ENGINE=MyISAM;
1309
 
create temporary table t2 (s1 int) ENGINE=MyISAM;
 
1269
create table t1 (s1 int) ENGINE=MyISAM;
 
1270
create table t2 (s1 int) ENGINE=MyISAM;
1310
1271
insert into t1 values (1);
1311
1272
insert into t2 values (1);
1312
1273
select * from t1 where exists (select s1 from t2 having max(t2.s1)=t1.s1);
1313
1274
s1
1314
1275
1
1315
1276
drop table t1,t2;
1316
 
#
1317
 
# update subquery with wrong field (to force name resolving
1318
 
# in UPDATE name space)
1319
 
#
1320
 
create temporary table t1 (s1 int) ENGINE=MyISAM;
1321
 
create temporary table t2 (s1 int) ENGINE=MyISAM;
 
1277
create table t1 (s1 int) ENGINE=MyISAM;
 
1278
create table t2 (s1 int) ENGINE=MyISAM;
1322
1279
insert into t1 values (1);
1323
1280
insert into t2 values (1);
1324
1281
update t1 set  s1 = s1 + 1 where 1 = (select x.s1 as A from t2 WHERE t2.s1 > t1.s1 order by A);
1325
1282
ERROR 42S22: Unknown column 'x.s1' in 'field list'
1326
1283
DROP TABLE t1, t2;
1327
 
#
1328
 
# collation test
1329
 
#
1330
 
#CREATE TABLE t1 (s1 CHAR(5) COLLATE latin1_german1_ci,
1331
 
#                 s2 CHAR(5) COLLATE latin1_swedish_ci) ENGINE=MyISAM;
1332
 
#INSERT INTO t1 VALUES ('z','?');
1333
 
#--error ER_CANT_AGGREGATE_2COLLATIONS
1334
 
#select * from t1 where s1 > (select max(s2) from t1);
1335
 
#--error ER_CANT_AGGREGATE_2COLLATIONS
1336
 
#select * from t1 where s1 > any (select max(s2) from t1);
1337
 
#drop table t1;
1338
 
#
1339
 
# aggregate functions reinitialization
1340
 
#
1341
 
create table t1(toid int,rd int);
1342
 
create table t2(userid int,pmnew int,pmtotal int);
 
1284
create table t1(toid int,rd int) ENGINE=MyISAM;
 
1285
create table t2(userid int,pmnew int,pmtotal int) ENGINE=MyISAM;
1343
1286
insert into t2 values(1,0,0),(2,0,0);
1344
1287
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);
1345
1288
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);
1347
1290
1       0       0       9       3
1348
1291
2       0       0       4       2
1349
1292
drop table t1, t2;
1350
 
#
1351
 
# row union
1352
 
#
1353
 
create table t1 (s1 char(5));
 
1293
create table t1 (s1 char(5)) ENGINE=MyISAM;
1354
1294
select (select 'a','b' from t1 union select 'a','b' from t1) from t1;
1355
1295
ERROR 21000: Operand should contain 1 column(s)
1356
1296
insert into t1 values ('tttt');
1359
1299
tttt
1360
1300
explain extended (select * from t1);
1361
1301
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1362
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    #       100.00  
 
1302
1       SIMPLE  t1      system  NULL    NULL    NULL    NULL    1       100.00  
1363
1303
Warnings:
1364
 
Note    1003    (select `test`.`t1`.`s1` AS `s1` from `test`.`t1`)
 
1304
Note    1003    (select 'tttt' AS `s1` from `test`.`t1`)
1365
1305
(select * from t1);
1366
1306
s1
1367
1307
tttt
1368
1308
drop table t1;
1369
 
#
1370
 
# IN optimisation test results
1371
 
#
1372
 
create temporary table t1 (s1 char(5), index s1(s1)) ENGINE=MyISAM;
1373
 
create temporary table t2 (s1 char(5), index s1(s1)) ENGINE=MyISAM;
 
1309
create table t1 (s1 char(5), index s1(s1)) ENGINE=MyISAM;
 
1310
create table t2 (s1 char(5), index s1(s1)) ENGINE=MyISAM;
1374
1311
insert into t1 values ('a1'),('a2'),('a3');
1375
1312
insert into t2 values ('a1'),('a2');
1376
1313
select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
1418
1355
Warnings:
1419
1356
Note    1003    select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1`
1420
1357
drop table t1,t2;
1421
 
#
1422
 
# correct ALL optimisation
1423
 
#
1424
 
create temporary table t2 (a int, b int) ENGINE=MyISAM;
1425
 
create temporary table t3 (a int) ENGINE=MyISAM;
 
1358
create table t2 (a int, b int) ENGINE=MyISAM;
 
1359
create table t3 (a int) ENGINE=MyISAM;
1426
1360
insert into t3 values (6),(7),(3);
1427
1361
select * from t3 where a >= all (select b from t2);
1428
1362
a
1434
1368
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
1435
1369
2       SUBQUERY        t2      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
1436
1370
Warnings:
1437
 
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>((`test`.`t3`.`a` < (select max(NULL) from `test`.`t2`)))
 
1371
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>((`test`.`t3`.`a` < (select max('0') from `test`.`t2`)))
1438
1372
select * from t3 where a >= some (select b from t2);
1439
1373
a
1440
1374
explain extended select * from t3 where a >= some (select b from t2);
1442
1376
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
1443
1377
2       SUBQUERY        t2      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
1444
1378
Warnings:
1445
 
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>((`test`.`t3`.`a` >= (select min(NULL) from `test`.`t2`)))
 
1379
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>((`test`.`t3`.`a` >= (select min('0') from `test`.`t2`)))
1446
1380
select * from t3 where a >= all (select b from t2 group by 1);
1447
1381
a
1448
1382
6
1453
1387
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
1454
1388
2       SUBQUERY        t2      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
1455
1389
Warnings:
1456
 
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>((`test`.`t3`.`a` < <max>(select NULL AS `b` from `test`.`t2` group by 1)))
 
1390
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>((`test`.`t3`.`a` < <max>(select '0' AS `b` from `test`.`t2` group by 1)))
1457
1391
select * from t3 where a >= some (select b from t2 group by 1);
1458
1392
a
1459
1393
explain extended select * from t3 where a >= some (select b from t2 group by 1);
1461
1395
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
1462
1396
2       SUBQUERY        t2      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
1463
1397
Warnings:
1464
 
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>((`test`.`t3`.`a` >= <min>(select NULL AS `b` from `test`.`t2` group by 1)))
 
1398
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>((`test`.`t3`.`a` >= <min>(select '0' AS `b` from `test`.`t2` group by 1)))
1465
1399
select * from t3 where NULL >= any (select b from t2);
1466
1400
a
1467
1401
explain extended select * from t3 where NULL >= any (select b from t2);
1494
1428
2       SUBQUERY        t2      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
1495
1429
Warnings:
1496
1430
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
1497
 
#
1498
 
# optimized static ALL/ANY with grouping
1499
 
#
1500
1431
insert into t2 values (2,2), (2,1), (3,3), (3,1);
1501
1432
select * from t3 where a > all (select max(b) from t2 group by a);
1502
1433
a
1509
1440
Warnings:
1510
1441
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>((`test`.`t3`.`a` <= <max>(select max(`test`.`t2`.`b`) AS `max(b)` from `test`.`t2` group by `test`.`t2`.`a`)))
1511
1442
drop table t2, t3;
1512
 
#
1513
 
# correct used_tables()
1514
 
#
1515
 
CREATE TEMPORARY TABLE `t1` ( `id` bigint NOT NULL auto_increment, `taskid` bigint NOT NULL default '0', `dbid` int NOT NULL default '0', `create_date` datetime, `last_update` datetime, PRIMARY KEY  (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 ;
 
1443
CREATE TABLE `t1` ( `id` bigint NOT NULL auto_increment, `taskid` bigint NOT NULL default '0', `dbid` int NOT NULL default '0', `create_date` datetime, `last_update` datetime, PRIMARY KEY  (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 ;
1516
1444
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());
1517
 
CREATE TEMPORARY 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;
 
1445
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;
1518
1446
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);
1519
 
CREATE TEMPORARY 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 ;
 
1447
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 ;
1520
1448
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);
1521
 
CREATE TEMPORARY TABLE `t4` (`task_id` int NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM;
 
1449
CREATE TABLE `t4` (`task_id` int NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM;
1522
1450
INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
1523
1451
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;
1524
1452
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')
1530
1458
-1      Valid
1531
1459
-1      Valid 2
1532
1460
drop table t1,t2,t3,t4;
1533
 
#
1534
 
# cardinality check
1535
 
#
1536
 
CREATE TEMPORARY TABLE t1 (id int default NULL) ENGINE=MyISAM;
 
1461
CREATE TABLE t1 (id int default NULL) ENGINE=MyISAM;
1537
1462
INSERT INTO t1 VALUES (1),(5);
1538
 
CREATE TEMPORARY TABLE t2 (id int default NULL) ENGINE=MyISAM;
 
1463
CREATE TABLE t2 (id int default NULL) ENGINE=MyISAM;
1539
1464
INSERT INTO t2 VALUES (2),(6);
1540
1465
select * from t1 where (1,2,6) in (select * from t2);
1541
1466
ERROR 21000: Operand should contain 3 column(s)
1542
1467
DROP TABLE t1,t2;
1543
 
#
1544
 
# optimized ALL/ANY with union
1545
 
#
1546
 
create table t1 (s1 char);
 
1468
create table t1 (s1 char) ENGINE=MyISAM;
1547
1469
insert into t1 values ('e');
1548
1470
select * from t1 where 'f' > any (select s1 from t1);
1549
1471
s1
1553
1475
e
1554
1476
explain extended select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
1555
1477
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1556
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  
1557
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    #       100.00  
1558
 
3       UNION   t1      ALL     NULL    NULL    NULL    NULL    #       100.00  
1559
 
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    #       NULL    
 
1478
1       PRIMARY t1      system  NULL    NULL    NULL    NULL    1       100.00  
 
1479
2       SUBQUERY        t1      system  NULL    NULL    NULL    NULL    1       100.00  
 
1480
3       UNION   t1      system  NULL    NULL    NULL    NULL    1       100.00  
 
1481
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
1560
1482
Warnings:
1561
 
Note    1003    select `test`.`t1`.`s1` AS `s1` from `test`.`t1` where 1
 
1483
Note    1003    select 'e' AS `s1` from `test`.`t1` where 1
1562
1484
drop table t1;
1563
 
#
1564
 
# filesort in subquery (restoring join_tab)
1565
 
#
1566
 
CREATE TEMPORARY TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM;
 
1485
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM;
1567
1486
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
1568
 
CREATE TEMPORARY TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM;
 
1487
CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM;
1569
1488
INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6');
1570
1489
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;
1571
1490
phone   code
1574
1493
89356874041     NULL
1575
1494
95895001874     NULL
1576
1495
drop table t1, t2;
1577
 
#
1578
 
# unresolved field error
1579
 
#
1580
 
create temporary table t1 (s1 int) ENGINE=MyISAM;
1581
 
create temporary table t2 (s1 int) ENGINE=MyISAM;
 
1496
create table t1 (s1 int) ENGINE=MyISAM;
 
1497
create table t2 (s1 int) ENGINE=MyISAM;
1582
1498
select * from t1 where (select count(*) from t2 where t1.s2) = 1;
1583
1499
ERROR 42S22: Unknown column 't1.s2' in 'where clause'
1584
1500
select * from t1 where (select count(*) from t2 group by t1.s2) = 1;
1586
1502
select count(*) from t2 group by t1.s2;
1587
1503
ERROR 42S22: Unknown column 't1.s2' in 'group statement'
1588
1504
drop table t1, t2;
1589
 
#
1590
 
# fix_fields() in add_ref_to_table_cond()
1591
 
#
1592
 
CREATE TEMPORARY TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB)) ENGINE=MyISAM;
1593
 
CREATE TEMPORARY TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA)) ENGINE=MyISAM;
 
1505
CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB)) ENGINE=MyISAM;
 
1506
CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA)) ENGINE=MyISAM;
1594
1507
INSERT INTO t1 VALUES (1,1,'1A3240'), (1,2,'4W2365');
1595
1508
INSERT INTO t2 VALUES (100, 200, 'C');
1596
1509
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
1597
1510
COLC
1598
1511
DROP TABLE t1, t2;
1599
 
CREATE TEMPORARY TABLE t1 (a int) ENGINE=MyISAM;
 
1512
CREATE TABLE t1 (a int) ENGINE=MyISAM;
1600
1513
INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5);
1601
1514
SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100;
1602
1515
(SELECT a)
1606
1519
4
1607
1520
5
1608
1521
DROP TABLE t1;
1609
 
#
1610
 
# Bug 2479
1611
 
#
1612
 
CREATE TEMPORARY TABLE `t1` (
 
1522
CREATE TABLE `t1` (
1613
1523
`id` int NOT NULL auto_increment,
1614
1524
`id_cns` int NOT NULL default '0',
1615
1525
`tipo` enum('','UNO','DUE') NOT NULL default '',
1622
1532
UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`))
1623
1533
ENGINE=MyISAM;
1624
1534
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);
1625
 
CREATE TEMPORARY TABLE `t2` (
 
1535
CREATE TABLE `t2` (
1626
1536
`id` int NOT NULL auto_increment,
1627
1537
`max_anno_dep` int NOT NULL default '0',
1628
1538
PRIMARY KEY  (`id`)) ENGINE=MyISAM;
1633
1543
50      1990    0
1634
1544
51      1990    NULL
1635
1545
DROP TABLE t1, t2;
1636
 
#
1637
 
# GLOBAL LIMIT
1638
 
#
1639
 
create temporary table t1 (a int) ENGINE=MyISAM;
 
1546
create table t1 (a int) ENGINE=MyISAM;
1640
1547
insert into t1 values (1), (2), (3);
1641
1548
SET SQL_SELECT_LIMIT=1;
1642
1549
select sum(a) from (select * from t1) as a;
1647
1554
1
1648
1555
SET SQL_SELECT_LIMIT=default;
1649
1556
drop table t1;
1650
 
#
1651
 
# Bug #3118: subselect + order by
1652
 
#
1653
 
CREATE TABLE t1 (a int, b int, INDEX (a));
 
1557
CREATE TABLE t1 (a int, b int, INDEX (a)) ENGINE=MyISAM;
1654
1558
INSERT INTO t1 VALUES (1, 1), (1, 2), (1, 3);
1655
1559
SELECT * FROM t1 WHERE a = (SELECT MAX(a) FROM t1 WHERE a = 1) ORDER BY b;
1656
1560
a       b
1658
1562
1       2
1659
1563
1       3
1660
1564
DROP TABLE t1;
1661
 
# Item_cond fix field
1662
 
#
1663
 
create table t1(val varchar(10));
 
1565
create table t1(val varchar(10)) ENGINE=MyISAM;
1664
1566
insert into t1 values ('aaa'), ('bbb'),('eee'),('mmm'),('ppp');
1665
1567
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%');
1666
1568
count(*)
1667
1569
0
1668
1570
drop table t1;
1669
 
#
1670
 
# ref_or_null replacing with ref
1671
 
#
1672
 
create table t1 (id int not null, text varchar(20) not null default '', primary key (id));
 
1571
create table t1 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM;
1673
1572
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');
1674
1573
select * from t1 where id not in (select id from t1 where id < 8);
1675
1574
id      text
1687
1586
12      text12
1688
1587
explain extended select * from t1 where id not in (select id from t1 where id < 8);
1689
1588
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1690
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
1691
 
2       DEPENDENT SUBQUERY      t1      unique_subquery PRIMARY PRIMARY 4       func    #       100.00  Using index; Using where
 
1589
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    12      100.00  Using where
 
1590
2       DEPENDENT SUBQUERY      t1      unique_subquery PRIMARY PRIMARY 4       func    1       100.00  Using index; Using where
1692
1591
Warnings:
1693
1592
Note    1003    select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`)))))))
1694
1593
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);
1695
1594
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1696
 
1       PRIMARY tt      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
1697
 
2       DEPENDENT SUBQUERY      t1      eq_ref  PRIMARY PRIMARY 4       test.tt.id      #       100.00  Using where; Using index
 
1595
1       PRIMARY tt      ALL     NULL    NULL    NULL    NULL    12      100.00  Using where
 
1596
2       DEPENDENT SUBQUERY      t1      eq_ref  PRIMARY PRIMARY 4       test.tt.id      1       100.00  Using where; Using index
1698
1597
Warnings:
1699
1598
Note    1276    Field or reference 'test.tt.id' of SELECT #2 was resolved in SELECT #1
1700
1599
Note    1003    select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(exists(select `test`.`t1`.`id` AS `id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null))))
1701
1600
insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
1702
 
create temporary table t2 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM;
 
1601
create table t2 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM;
1703
1602
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');
1704
1603
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);
1705
1604
id      text    id      text    id      text
1719
1618
1001    text1001        NULL    NULL    1000    text1000
1720
1619
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);
1721
1620
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1722
 
1       SIMPLE  a       ALL     NULL    NULL    NULL    NULL    #       100.00  
1723
 
1       SIMPLE  b       eq_ref  PRIMARY PRIMARY 4       test.a.id       #       100.00  
1724
 
1       SIMPLE  c       eq_ref  PRIMARY PRIMARY 4       func    #       100.00  Using where
 
1621
1       SIMPLE  a       ALL     NULL    NULL    NULL    NULL    14      100.00  
 
1622
1       SIMPLE  b       eq_ref  PRIMARY PRIMARY 4       test.a.id       2       100.00  
 
1623
1       SIMPLE  c       eq_ref  PRIMARY PRIMARY 4       func    1       100.00  Using where
1725
1624
Warnings:
1726
1625
Note    1003    select `test`.`a`.`id` AS `id`,`test`.`a`.`text` AS `text`,`test`.`b`.`id` AS `id`,`test`.`b`.`text` AS `text`,`test`.`c`.`id` AS `id`,`test`.`c`.`text` AS `text` from `test`.`t1` `a` left join `test`.`t2` `b` on(((`test`.`b`.`id` = `test`.`a`.`id`) or isnull(`test`.`b`.`id`))) join `test`.`t1` `c` where (if(isnull(`test`.`b`.`id`),1000,`test`.`b`.`id`) = `test`.`c`.`id`)
1727
1626
drop table t1,t2;
1728
 
#
1729
 
# Static tables & rund() in subqueries
1730
 
#
1731
 
create temporary table t1 (a int) ENGINE=MyISAM;
 
1627
create table t1 (a int) ENGINE=MyISAM;
1732
1628
insert into t1 values (1);
1733
1629
explain select benchmark(1000, (select a from t1 where a=rand()));
1734
1630
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1735
1631
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
1736
1632
2       SUBQUERY        t1      system  NULL    NULL    NULL    NULL    1       
1737
1633
drop table t1;
1738
 
#
1739
 
# bug 3188
1740
 
#
1741
 
create temporary table t1(id int) ENGINE=MyISAM;
1742
 
create temporary table t2(id int) ENGINE=MyISAM;
1743
 
create temporary table t3(flag int) ENGINE=MyISAM;
 
1634
create table t1(id int) ENGINE=MyISAM;
 
1635
create table t2(id int) ENGINE=MyISAM;
 
1636
create table t3(flag int) ENGINE=MyISAM;
1744
1637
select (select * from t3 where id not null) from t1, t2;
1745
1638
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'null) from t1, t2' at line 1
1746
1639
drop table t1,t2,t3;
1747
 
#
1748
 
# aggregate functions (Bug #3505)
1749
 
#
1750
 
CREATE TABLE t1 (id INT);
1751
 
CREATE TABLE t2 (id INT);
 
1640
CREATE TABLE t1 (id INT) ENGINE=MyISAM;
 
1641
CREATE TABLE t2 (id INT) ENGINE=MyISAM;
1752
1642
INSERT INTO t1 VALUES (1), (2);
1753
1643
INSERT INTO t2 VALUES (1);
1754
1644
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);
1768
1658
1       1
1769
1659
2       0
1770
1660
DROP TABLE t1,t2;
1771
 
#
1772
 
# ALL/ANY test
1773
 
#
1774
 
CREATE TABLE t1 ( a int, b int );
 
1661
CREATE TABLE t1 ( a int, b int ) ENGINE=MyISAM;
1775
1662
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
1776
1663
SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 );
1777
1664
a
1815
1702
a
1816
1703
1
1817
1704
3
1818
 
# with index
1819
1705
ALTER TABLE t1 ADD INDEX (a);
1820
1706
SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 );
1821
1707
a
1859
1745
a
1860
1746
1
1861
1747
3
1862
 
# having clause test
1863
1748
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2);
1864
1749
a
1865
1750
3
1902
1787
a
1903
1788
1
1904
1789
3
1905
 
# union test
1906
1790
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
1907
1791
a
1908
1792
3
1945
1829
a
1946
1830
1
1947
1831
3
1948
 
# union + having test
1949
1832
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
1950
1833
a
1951
1834
3
1988
1871
a
1989
1872
1
1990
1873
3
1991
 
# row tests
1992
 
# < > >= <= and = ALL/ <> ANY do not support row operation
1993
1874
SELECT a FROM t1 WHERE (1,2) > ANY (SELECT a FROM t1 WHERE b = 2);
1994
1875
ERROR 21000: Operand should contain 1 column(s)
1995
1876
SELECT a FROM t1 WHERE a > ANY (SELECT a,2 FROM t1 WHERE b = 2);
2006
1887
ERROR 21000: Operand should contain 1 column(s)
2007
1888
SELECT a FROM t1 WHERE (1,2) <> ANY (SELECT a,2 FROM t1 WHERE b = 2);
2008
1889
ERROR 21000: Operand should contain 1 column(s)
2009
 
# following should be converted to IN
2010
1890
SELECT a FROM t1 WHERE (1,2) = ANY (SELECT a FROM t1 WHERE b = 2);
2011
1891
ERROR 21000: Operand should contain 2 column(s)
2012
1892
SELECT a FROM t1 WHERE a = ANY (SELECT a,2 FROM t1 WHERE b = 2);
2050
1930
a
2051
1931
1
2052
1932
3
2053
 
# without optimisation
2054
1933
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 group by a);
2055
1934
a
2056
1935
3
2093
1972
a
2094
1973
1
2095
1974
3
2096
 
# without optimisation + having
2097
1975
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 group by a HAVING a = 2);
2098
1976
a
2099
1977
3
2136
2014
a
2137
2015
1
2138
2016
3
2139
 
# EXISTS in string contence
2140
2017
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a > t1.a), '-') from t1 a;
2141
2018
concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a > t1.a), '-')
2142
2019
0-
2153
2030
1-
2154
2031
0-
2155
2032
DROP TABLE t1;
2156
 
CREATE TABLE t1 ( a double, b double );
 
2033
CREATE TABLE t1 ( a double, b double ) ENGINE=MyISAM;
2157
2034
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
2158
2035
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2e0);
2159
2036
a
2198
2075
1
2199
2076
3
2200
2077
DROP TABLE t1;
2201
 
CREATE TABLE t1 ( a char(1), b char(1));
 
2078
CREATE TABLE t1 ( a char(1), b char(1)) ENGINE=MyISAM;
2202
2079
INSERT INTO t1 VALUES ('1','1'),('2','2'),('3','3');
2203
2080
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = '2');
2204
2081
a
2243
2120
1
2244
2121
3
2245
2122
DROP TABLE t1;
2246
 
#
2247
 
# SELECT(EXISTS * ...)optimisation
2248
 
#
2249
 
create table t1 (a int, b int);
 
2123
create table t1 (a int, b int) ENGINE=MyISAM;
2250
2124
insert into t1 values (1,2),(3,4);
2251
2125
select * from t1 up where exists (select * from t1 where t1.a=up.a);
2252
2126
a       b
2254
2128
3       4
2255
2129
explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
2256
2130
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
2257
 
1       PRIMARY up      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
2258
 
2       DEPENDENT SUBQUERY      t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
 
2131
1       PRIMARY up      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
 
2132
2       DEPENDENT SUBQUERY      t1      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
2259
2133
Warnings:
2260
2134
Note    1276    Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
2261
2135
Note    1003    select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where exists(select 1 AS `Not_used` from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`))
2262
2136
drop table t1;
2263
 
#
2264
 
# Bug #4102: subselect in HAVING
2265
 
#
2266
 
CREATE TEMPORARY TABLE t1 (t1_a int) ENGINE=MyISAM;
 
2137
CREATE TABLE t1 (t1_a int) ENGINE=MyISAM;
2267
2138
INSERT INTO t1 VALUES (1);
2268
 
CREATE TABLE t2 (t2_a int, t2_b int, PRIMARY KEY (t2_a, t2_b));
 
2139
CREATE TABLE t2 (t2_a int, t2_b int, PRIMARY KEY (t2_a, t2_b)) ENGINE=MyISAM;
2269
2140
INSERT INTO t2 VALUES (1, 1), (1, 2);
2270
2141
SELECT * FROM t1, t2 table2 WHERE t1_a = 1 AND table2.t2_a = 1
2271
2142
HAVING table2.t2_b = (SELECT MAX(t2_b) FROM t2 WHERE t2_a = table2.t2_a);
2272
2143
t1_a    t2_a    t2_b
2273
2144
1       1       2
2274
2145
DROP TABLE t1, t2;
2275
 
#
2276
 
# Test problem with NULL and derived tables (Bug #4097)
2277
 
#
2278
 
CREATE TEMPORARY TABLE t1 (id int default NULL,name varchar(10) default NULL) ENGINE=MyISAM;
 
2146
CREATE TABLE t1 (id int default NULL,name varchar(10) default NULL) ENGINE=MyISAM;
2279
2147
INSERT INTO t1 VALUES (1,'Tim'),(2,'Rebecca'),(3,NULL);
2280
 
CREATE TEMPORARY TABLE t2 (id int default NULL, pet varchar(10) default NULL) ENGINE=MyISAM;
 
2148
CREATE TABLE t2 (id int default NULL, pet varchar(10) default NULL) ENGINE=MyISAM;
2281
2149
INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix');
2282
2150
SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id;
2283
2151
id      name    id      pet
2285
2153
2       Rebecca 2       Spot
2286
2154
3       NULL    3       Felix
2287
2155
drop table t1,t2;
2288
 
#
2289
 
# Aggregate function comparation with ALL/ANY/SOME subselect
2290
 
#
2291
 
CREATE TEMPORARY TABLE `t1` ( `a` int default NULL) ENGINE=MyISAM;
 
2156
CREATE TABLE `t1` ( `a` int default NULL) ENGINE=MyISAM;
2292
2157
insert into t1 values (1);
2293
 
CREATE TEMPORARY TABLE `t2` ( `b` int default NULL, `a` int default NULL) ENGINE=MyISAM;
 
2158
CREATE TABLE `t2` ( `b` int default NULL, `a` int default NULL) ENGINE=MyISAM;
2294
2159
insert into t2 values (1,2);
2295
2160
select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1);
2296
2161
a       C
2297
2162
1       1
2298
2163
drop table t1,t2;
2299
 
#
2300
 
# BUG#5003 - like in subselect
2301
 
#
2302
 
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);
 
2164
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;
2303
2165
CREATE INDEX AK01IZAVORGANG ON t1(izaAnalyseart_id,Kuerzel);
2304
2166
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000001','601','D0000000001','I0000000001');
2305
2167
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000002','602','D0000000001','I0000000001');
2309
2171
IZAVORGANG_ID
2310
2172
D0000000001
2311
2173
drop table t1;
2312
 
#
2313
 
# Optimized IN with compound index
2314
 
#
2315
 
CREATE TEMPORARY TABLE `t1` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`)) ENGINE=MyISAM;
2316
 
CREATE TEMPORARY TABLE `t2` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`)) ENGINE=MyISAM;
 
2174
CREATE TABLE `t1` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`)) ENGINE=MyISAM;
 
2175
CREATE TABLE `t2` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`)) ENGINE=MyISAM;
2317
2176
insert into t1 values (1,1),(1,2),(2,1),(2,2);
2318
2177
insert into t2 values (1,2),(2,2);
2319
2178
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
2333
2192
1       1
2334
2193
2       1
2335
2194
drop table t1,t2;
2336
 
#
2337
 
# resolving fields of grouped outer SELECT
2338
 
#
2339
 
CREATE TABLE t1 (howmanyvalues bigint, avalue int);
 
2195
CREATE TABLE t1 (howmanyvalues bigint, avalue int) ENGINE=MyISAM;
2340
2196
INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4);
2341
2197
SELECT howmanyvalues, count(*) from t1 group by howmanyvalues;
2342
2198
howmanyvalues   count(*)
2370
2226
3       1
2371
2227
4       1
2372
2228
drop table t1;
2373
 
create table t1 (x int);
 
2229
create table t1 (x int) ENGINE=MyISAM;
2374
2230
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;
2375
2231
(select b.x from t1 as b where b.x=a.x)
2376
2232
drop table t1;
2377
 
#
2378
 
# Test of correct maybe_null flag returning by subquwery for temporary table
2379
 
# creation
2380
 
#
2381
 
CREATE TEMPORARY 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;
 
2233
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;
2382
2234
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);
2383
 
CREATE TEMPORARY 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 ;
 
2235
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 ;
2384
2236
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');
2385
2237
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;
2386
2238
ERROR 42S22: Unknown column 'b.sc' in 'field list'
2389
2241
700
2390
2242
NULL
2391
2243
drop tables t1,t2;
2392
 
#
2393
 
# Subselect in non-select command just after connection
2394
 
#
2395
2244
set @got_val= (SELECT 1 FROM (SELECT 'A' as my_col) as T1 ) ;
2396
 
#
2397
 
# primary query with temporary table and subquery with groupping
2398
 
#
2399
 
create temporary table t1 (a int, b int) ENGINE=MyISAM;
2400
 
create temporary table t2 (a int, b int) ENGINE=MyISAM;
 
2245
create table t1 (a int, b int) ENGINE=MyISAM;
 
2246
create table t2 (a int, b int) ENGINE=MyISAM;
2401
2247
insert into t1 values (1,1),(1,2),(1,3),(2,4),(2,5);
2402
2248
insert into t2 values (1,3),(2,1);
2403
2249
select distinct a,b, (select max(b) from t2 where t1.b=t2.a) from t1 order by t1.b;
2408
2254
2       4       NULL
2409
2255
2       5       NULL
2410
2256
drop table t1, t2;
2411
 
#
2412
 
# Equal operation under row and empty subquery
2413
 
#
2414
 
create table t1 (s1 int,s2 int);
 
2257
create table t1 (s1 int,s2 int) ENGINE=MyISAM;
2415
2258
insert into t1 values (20,15);
2416
2259
select * from t1 where  (('a',null) <=> (select 'a',s2 from t1 where s1 = 0));
2417
2260
s1      s2
2418
2261
drop table t1;
2419
 
#
2420
 
# ALL/ANY with NULL
2421
 
#
2422
 
create table t1 (s1 int);
 
2262
create table t1 (s1 int) ENGINE=MyISAM;
2423
2263
insert into t1 values (1),(null);
2424
2264
select * from t1 where s1 < all (select s1 from t1);
2425
2265
s1
2428
2268
1       0
2429
2269
NULL    NULL
2430
2270
drop table t1;
2431
 
#
2432
 
# reference on changable fields from subquery
2433
 
#
2434
2271
CREATE TABLE t1 (
2435
2272
Code char(3) NOT NULL default '',
2436
2273
Name char(52) NOT NULL default '',
2447
2284
HeadOfState char(60) default NULL,
2448
2285
Capital int default NULL,
2449
2286
Code2 char(2) NOT NULL default ''
2450
 
);
 
2287
) ENGINE=MyISAM;
2451
2288
INSERT INTO t1 VALUES ('XXX','Xxxxx','Oceania','Xxxxxx',26.00,0,0,0,0,0,'Xxxxx','Xxxxx','Xxxxx',NULL,'XX');
2452
2289
INSERT INTO t1 VALUES ('ASM','American Samoa','Oceania','Polynesia',199.00,0,68000,75.1,334.00,NULL,'Amerika Samoa','US Territory','George W. Bush',54,'AS');
2453
2290
INSERT INTO t1 VALUES ('ATF','French Southern territories','Antarctica','Antarctica',7780.00,0,0,NULL,0.00,NULL,'Terres australes françaises','Nonmetropolitan Territory of France','Jacques Chirac',NULL,'TF');
2454
2291
INSERT INTO t1 VALUES ('UMI','United States Minor Outlying Islands','Oceania','Micronesia/Caribbean',16.00,0,0,NULL,0.00,NULL,'United States Minor Outlying Islands','Dependent Territory of the US','George W. Bush',NULL,'UM');
2455
2292
/*!40000 ALTER TABLE t1 ENABLE KEYS */;
2456
 
Warnings:
2457
 
Note    1031    Table storage engine for 't1' doesn't have this option
2458
2293
SELECT DISTINCT Continent AS c FROM t1 outr WHERE 
2459
2294
Code <> SOME ( SELECT Code FROM t1 WHERE Continent = outr.Continent AND 
2460
2295
Population < 200);
2461
2296
c
2462
2297
Oceania
2463
2298
drop table t1;
2464
 
#
2465
 
# Test for BUG#7885: Server crash when 'any' subselect compared to
2466
 
# non-existant field.
2467
 
#
2468
 
create temporary table t1 (a1 int) ENGINE=MyISAM;
2469
 
create temporary table t2 (b1 int) ENGINE=MyISAM;
 
2299
create table t1 (a1 int) ENGINE=MyISAM;
 
2300
create table t2 (b1 int) ENGINE=MyISAM;
2470
2301
select * from t1 where a2 > any(select b1 from t2);
2471
2302
ERROR 42S22: Unknown column 'a2' in 'IN/ALL/ANY subquery'
2472
2303
select * from t1 where a1 > any(select b1 from t2);
2473
2304
a1
2474
2305
drop table t1,t2;
2475
 
#
2476
 
# Comparison subquery with * and row
2477
 
#
2478
 
create temporary table t1 (a integer, b integer) ENGINE=MyISAM;
 
2306
create table t1 (a integer, b integer) ENGINE=MyISAM;
2479
2307
select (select * from t1) = (select 1,2);
2480
2308
(select * from t1) = (select 1,2)
2481
2309
NULL
2482
2310
select (select 1,2) = (select * from t1);
2483
2311
(select 1,2) = (select * from t1)
2484
2312
NULL
2485
 
# queries whih can be converted to IN
2486
2313
select  row(1,2) = ANY (select * from t1);
2487
2314
row(1,2) = ANY (select * from t1)
2488
2315
0
2490
2317
row(1,2) != ALL (select * from t1)
2491
2318
1
2492
2319
drop table t1;
2493
 
#
2494
 
# Comparison subquery and row with nested rows
2495
 
#
2496
 
create temporary table t1 (a integer, b integer) ENGINE=MyISAM;
 
2320
create table t1 (a integer, b integer) ENGINE=MyISAM;
2497
2321
select row(1,(2,2)) in (select * from t1 );
2498
2322
ERROR 21000: Operand should contain 2 column(s)
2499
2323
select row(1,(2,2)) = (select * from t1 );
2501
2325
select (select * from t1) = row(1,(2,2));
2502
2326
ERROR 21000: Operand should contain 1 column(s)
2503
2327
drop table t1;
2504
 
#
2505
 
# Forward reference detection
2506
 
#
2507
2328
create  table t1 (a integer);
2508
2329
insert into t1 values (1);
2509
2330
select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx ;
2516
2337
select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx;
2517
2338
ERROR 42S22: Reference 'xx' not supported (forward reference in item list)
2518
2339
drop table t1;
2519
 
#
2520
 
# Test for BUG#8218
2521
 
#
2522
 
CREATE TEMPORARY TABLE t1 (
 
2340
CREATE TABLE t1 (
2523
2341
categoryId int NOT NULL,
2524
2342
courseId int NOT NULL,
2525
2343
startDate datetime NOT NULL,
2537
2355
(2,89,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
2538
2356
(3,51,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''),
2539
2357
(5,12,'2004-02-18','2010-01-01','2004-02-18','2004-02-18','');
2540
 
CREATE TEMPORARY TABLE t2 (
 
2358
CREATE TABLE t2 (
2541
2359
userId int NOT NULL,
2542
2360
courseId int NOT NULL,
2543
2361
date datetime NOT NULL)
2548
2366
(5141,12,'2004-08-06'),(5141,86,'2004-10-21'),
2549
2367
(5141,87,'2004-10-21'),(5141,88,'2004-10-21'),
2550
2368
(5141,89,'2004-10-22'),(5141,51,'2004-10-26');
2551
 
CREATE TEMPORARY TABLE t3 (
 
2369
CREATE TABLE t3 (
2552
2370
groupId int NOT NULL,
2553
2371
parentId int NOT NULL,
2554
2372
startDate datetime NOT NULL,
2558
2376
ordering int)
2559
2377
engine=myisam;
2560
2378
INSERT INTO t3 VALUES (12,9,'1000-01-01','3999-12-31','2004-01-29','2004-01-29',NULL);
2561
 
CREATE TEMPORARY TABLE t4 (
 
2379
CREATE TABLE t4 (
2562
2380
id int NOT NULL,
2563
2381
groupTypeId int NOT NULL,
2564
2382
groupKey varchar(50) NOT NULL,
2570
2388
engine=myisam;
2571
2389
INSERT INTO t4 VALUES (9,5,'stationer','stationer',0,'Stationer','2004-01-29','2004-01-29'),
2572
2390
(12,5,'group2','group2',0,'group2','2004-01-29','2004-01-29');
2573
 
CREATE TEMPORARY TABLE t5 (
 
2391
CREATE TABLE t5 (
2574
2392
userId int NOT NULL,
2575
2393
groupId int NOT NULL,
2576
2394
createDate datetime NOT NULL,
2618
2436
1       5141    12      group2  12      group2  5       1       2       88      Oct04
2619
2437
1       5141    12      group2  12      group2  5       1       2       89      Oct04
2620
2438
drop table t1, t2, t3, t4, t5;
2621
 
#
2622
 
# Transformation in left expression of subquery (BUG#8888)
2623
 
#
2624
 
create temporary table t1 (a int) ENGINE=MyISAM;
 
2439
create table t1 (a int) ENGINE=MyISAM;
2625
2440
insert into t1 values (1), (2), (3);
2626
2441
SELECT 1 FROM t1 WHERE (SELECT 1) in (SELECT 1);
2627
2442
1
2629
2444
1
2630
2445
1
2631
2446
drop table t1;
2632
 
#
2633
 
# single row subqueries and row operations (code covarage improvement)
2634
 
#
2635
 
create temporary table t1 (a int, b int) ENGINE=MyISAM;
 
2447
create table t1 (a int, b int) ENGINE=MyISAM;
2636
2448
insert into t1 values (1,2);
2637
2449
select 1 = (select * from t1);
2638
2450
ERROR 21000: Operand should contain 1 column(s)
2647
2459
select (select * from t1) = (1,2,3);
2648
2460
ERROR 21000: Operand should contain 2 column(s)
2649
2461
drop table t1;
2650
 
#
2651
 
# Item_int_with_ref check (BUG#10020)
2652
 
#
2653
 
#CREATE TABLE `t1` (
2654
 
#  `itemid` bigint NOT NULL auto_increment,
2655
 
#  `sessionid` bigint default NULL,
2656
 
#  `time` int NOT NULL default '0',
2657
 
#  `data` text collate latin1_general_ci NOT NULL,
2658
 
#  PRIMARY KEY  (`itemid`)
2659
 
#);
2660
 
#INSERT INTO `t1` VALUES (1, 1, 1, '');
2661
 
#CREATE TABLE `t2` (
2662
 
#  `sessionid` bigint NOT NULL auto_increment,
2663
 
#  `pid` int NOT NULL default '0',
2664
 
#  `date` int NOT NULL default '0',
2665
 
#  `ip` varchar(15) collate latin1_general_ci NOT NULL default '',
2666
 
#  PRIMARY KEY  (`sessionid`)
2667
 
#);
2668
 
#INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
2669
 
#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;
2670
 
#drop tables t1,t2;
2671
 
# BUG#11821 : Select from subselect using aggregate function on an enum
2672
 
# segfaults:
2673
 
create temporary table t1 (fld enum('0','1')) ENGINE=MyISAM;
 
2462
create table t1 (fld enum('0','1')) ENGINE=MyISAM;
2674
2463
insert into t1 values ('1');
2675
2464
select * from (select max(fld) from t1) as foo;
2676
2465
max(fld)
2677
2466
1
2678
2467
drop table t1;
2679
 
#
2680
 
# Bug #11867: queries with ROW(,elems>) IN (SELECT DISTINCT <cols> FROM ...)
2681
 
#
2682
 
CREATE TABLE t1 (one int, two int, flag char(1));
2683
 
CREATE TABLE t2 (one int, two int, flag char(1));
 
2468
CREATE TABLE t1 (one int, two int, flag char(1)) ENGINE=MyISAM;
 
2469
CREATE TABLE t2 (one int, two int, flag char(1)) ENGINE=MyISAM;
2684
2470
INSERT INTO t1 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
2685
2471
INSERT INTO t2 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
2686
2472
SELECT * FROM t1
2752
2538
Note    1003    select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
2753
2539
explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
2754
2540
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
2755
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    8       100.00  Using where
2756
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    9       100.00  Using where
 
2541
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    8       100.00  Start temporary
 
2542
1       PRIMARY t2      ALL     NULL    NULL    NULL    NULL    9       100.00  Using where; End temporary; Using join buffer
2757
2543
Warnings:
2758
 
Note    1003    select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),(`test`.`t1`.`one`,`test`.`t1`.`two`) in ( <materialize> (select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where (`test`.`t2`.`flag` = 'N') ), <primary_index_lookup>(`test`.`t1`.`one` in <temporary table> on distinct_key)))
 
2544
Note    1003    select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`two` = `test`.`t1`.`two`) and (`test`.`t2`.`one` = `test`.`t1`.`one`) and (`test`.`t2`.`flag` = 'N'))
2759
2545
explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
2760
2546
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
2761
2547
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    8       100.00  
2763
2549
Warnings:
2764
2550
Note    1003    select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
2765
2551
DROP TABLE t1,t2;
2766
 
#
2767
 
# Bug #12392: where cond with IN predicate for rows and NULL values in table 
2768
 
#
2769
 
CREATE TEMPORARY TABLE t1 (a char(5), b char(5)) ENGINE=MyISAM;
 
2552
CREATE TABLE t1 (a char(5), b char(5)) ENGINE=MyISAM;
2770
2553
INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
2771
2554
SELECT * FROM t1 WHERE (a,b) IN (('aaa','aaa'), ('aaa','bbb'));
2772
2555
a       b
2773
2556
aaa     aaa
2774
2557
DROP TABLE t1;
2775
 
#
2776
 
# Bug #11479: subquery over left join with an empty inner table 
2777
 
#
2778
 
CREATE TEMPORARY TABLE t1 (a int) ENGINE=MyISAM;
2779
 
CREATE TEMPORARY TABLE t2 (a int, b int) ENGINE=MyISAM;
2780
 
CREATE TEMPORARY TABLE t3 (b int NOT NULL) ENGINE=MyISAM;
 
2558
CREATE TABLE t1 (a int) ENGINE=MyISAM;
 
2559
CREATE TABLE t2 (a int, b int) ENGINE=MyISAM;
 
2560
CREATE TABLE t3 (b int NOT NULL) ENGINE=MyISAM;
2781
2561
INSERT INTO t1 VALUES (1), (2), (3), (4);
2782
2562
INSERT INTO t2 VALUES (1,10), (3,30);
2783
2563
SELECT * FROM t2 LEFT JOIN t3 ON t2.b=t3.b
2792
2572
3
2793
2573
4
2794
2574
DROP TABLE t1,t2,t3;
2795
 
#
2796
 
# Bug#18503: Queries with a quantified subquery returning empty set may
2797
 
# return a wrong result. 
2798
 
#
2799
 
CREATE TEMPORARY TABLE t1 (f1 INT) ENGINE=MyISAM;
2800
 
CREATE TEMPORARY TABLE t2 (f2 INT) ENGINE=MyISAM;
 
2575
CREATE TABLE t1 (f1 INT) ENGINE=MyISAM;
 
2576
CREATE TABLE t2 (f2 INT) ENGINE=MyISAM;
2801
2577
INSERT INTO t1 VALUES (1);
2802
2578
SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2);
2803
2579
f1
2811
2587
f1
2812
2588
1
2813
2589
DROP TABLE t1, t2;
2814
 
# BUG#20975 Wrong query results for subqueries within NOT
2815
 
create table t1 (s1 char);
 
2590
create table t1 (s1 char) ENGINE=MyISAM;
2816
2591
insert into t1 values (1),(2);
2817
2592
select * from t1 where (s1 < any (select s1 from t1));
2818
2593
s1
2839
2614
s1
2840
2615
2
2841
2616
drop table t1;
2842
 
#
2843
 
# Bug #16255: Subquery in where
2844
 
#
2845
2617
create table t1 (
2846
2618
retailerID varchar(8) NOT NULL,
2847
2619
statusID   int NOT NULL,
2848
2620
changed    datetime NOT NULL,
2849
 
UNIQUE KEY retailerID (retailerID, statusID, changed));
 
2621
UNIQUE KEY retailerID (retailerID, statusID, changed))
 
2622
ENGINE=MyISAM;
2850
2623
INSERT INTO t1 VALUES("0026", "1", "2005-12-06 12:18:56");
2851
2624
INSERT INTO t1 VALUES("0026", "2", "2006-01-06 12:25:53");
2852
2625
INSERT INTO t1 VALUES("0037", "1", "2005-12-06 12:18:56");
2863
2636
0048    1       2006-01-06 12:37:50
2864
2637
0059    1       2006-01-06 12:37:50
2865
2638
drop table t1;
2866
 
#
2867
 
# Bug #21180: Subselect with index for both WHERE and ORDER BY 
2868
 
#             produces empty result
2869
 
#
2870
 
create table t1(a int, primary key (a));
 
2639
create table t1(a int, primary key (a)) ENGINE=MyISAM;
2871
2640
insert into t1 values (10);
2872
 
create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
 
2641
create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)) ENGINE=MyISAM;
2873
2642
insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
2874
2643
explain SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r 
2875
2644
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' 
2876
2645
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
2877
2646
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2878
 
1       PRIMARY t1      const   PRIMARY PRIMARY 4       const   #       Using index
2879
 
1       PRIMARY r       const   PRIMARY PRIMARY 4       const   #       
2880
 
2       DEPENDENT SUBQUERY      t2      ref     b       b       5               #       Using where; Using index
 
2647
1       PRIMARY t1      system  PRIMARY NULL    NULL    NULL    1       
 
2648
1       PRIMARY r       const   PRIMARY PRIMARY 4       const   1       
 
2649
2       DEPENDENT SUBQUERY      t2      range   b       b       136     NULL    2       Using where
2881
2650
SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r 
2882
2651
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' 
2883
2652
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
2887
2656
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' 
2888
2657
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
2889
2658
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2890
 
1       PRIMARY t1      const   PRIMARY PRIMARY 4       const   1       Using index
 
2659
1       PRIMARY t1      system  PRIMARY NULL    NULL    NULL    1       
2891
2660
1       PRIMARY r       const   PRIMARY PRIMARY 4       const   1       
2892
 
2       DEPENDENT SUBQUERY      t2      ref     b       b       5               3       Using where; Using index
 
2661
2       DEPENDENT SUBQUERY      t2      range   b       b       136     NULL    2       Using where; Using MRR
2893
2662
SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r 
2894
2663
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' 
2895
2664
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
2896
2665
a       a       b
2897
2666
10      1       359
2898
2667
drop table t1,t2;
2899
 
#
2900
 
# Bug #21853: assert failure for a grouping query with
2901
 
#             an ALL/ANY quantified subquery in HAVING 
2902
 
#
2903
 
CREATE TEMPORARY TABLE t1 (                  
 
2668
CREATE TABLE t1 (                  
2904
2669
field1 int NOT NULL,                 
2905
2670
field2 int NOT NULL,                 
2906
2671
field3 int NOT NULL,                 
2907
2672
PRIMARY KEY  (field1,field2,field3))
2908
2673
ENGINE=MyISAM;
2909
 
CREATE TEMPORARY TABLE t2 (             
 
2674
CREATE TABLE t2 (             
2910
2675
fieldA int NOT NULL,            
2911
2676
fieldB int NOT NULL,            
2912
2677
PRIMARY KEY  (fieldA,fieldB))
2936
2701
1       1
2937
2702
1       3
2938
2703
DROP TABLE t1, t2;
2939
 
#
2940
 
# Bug #23478: not top-level IN subquery returning a non-empty result set
2941
 
#             with possible NULL values by index access from the outer query
2942
 
#
2943
 
CREATE TEMPORARY TABLE t1(a int, INDEX (a)) ENGINE=MyISAM;
 
2704
CREATE TABLE t1(a int, INDEX (a)) ENGINE=MyISAM;
2944
2705
INSERT INTO t1 VALUES (1), (3), (5), (7);
2945
2706
INSERT INTO t1 VALUES (NULL);
2946
 
CREATE TEMPORARY TABLE t2(a int) ENGINE=MyISAM;
 
2707
CREATE TABLE t2(a int) ENGINE=MyISAM;
2947
2708
INSERT INTO t2 VALUES (1),(2),(3);
2948
2709
EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2;
2949
2710
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2955
2716
2       NULL
2956
2717
3       1
2957
2718
DROP TABLE t1,t2;
2958
 
#
2959
 
# Bug #11302: getObject() returns a String for a sub-query of type datetime
2960
 
#
2961
 
CREATE TABLE t1 (a DATETIME);
 
2719
CREATE TABLE t1 (a DATETIME) ENGINE=MyISAM;
2962
2720
INSERT INTO t1 VALUES ('1998-09-23'), ('2003-03-25');
2963
 
CREATE TEMPORARY TABLE t2 ENGINE=MyISAM AS SELECT 
 
2721
CREATE TABLE t2 ENGINE=MyISAM AS SELECT 
2964
2722
(SELECT a FROM t1 WHERE a < '2000-01-01') AS sub_a 
2965
2723
FROM t1 WHERE a > '2000-01-01';
2966
2724
SHOW CREATE TABLE t2;
2967
2725
Table   Create Table
2968
 
t2      CREATE TEMPORARY TABLE `t2` (
2969
 
  `sub_a` DATETIME DEFAULT NULL
2970
 
) ENGINE=MyISAM COLLATE = utf8_general_ci
2971
 
CREATE TEMPORARY TABLE t3 ENGINE=MyISAM AS (SELECT a FROM t1 WHERE a < '2000-01-01') UNION (SELECT a FROM t1 WHERE a > '2000-01-01');
 
2726
t2      CREATE TABLE `t2` (
 
2727
  `sub_a` datetime DEFAULT NULL
 
2728
) ENGINE=MyISAM
 
2729
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');
2972
2730
SHOW CREATE TABLE t3;
2973
2731
Table   Create Table
2974
 
t3      CREATE TEMPORARY TABLE `t3` (
2975
 
  `a` DATETIME DEFAULT NULL
2976
 
) ENGINE=MyISAM COLLATE = utf8_general_ci
 
2732
t3      CREATE TABLE `t3` (
 
2733
  `a` datetime DEFAULT NULL
 
2734
) ENGINE=MyISAM
2977
2735
DROP TABLE t1,t2,t3;
2978
 
#
2979
 
# Bug 24653: sorting by expressions containing subselects
2980
 
#            that return more than one row
2981
 
#
2982
 
CREATE TEMPORARY TABLE t1 (a int) ENGINE=MyISAM;
 
2736
CREATE TABLE t1 (a int) ENGINE=MyISAM;
2983
2737
INSERT INTO t1 VALUES (2), (4), (1), (3);
2984
 
CREATE TABLE t2 (b int, c int);
 
2738
CREATE TABLE t2 (b int, c int) ENGINE=MyISAM;
2985
2739
INSERT INTO t2 VALUES
2986
2740
(2,1), (1,3), (2,1), (4,4), (2,2), (1,4);
2987
2741
SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 2 );
3053
2807
(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b));
3054
2808
ERROR 21000: Subquery returns more than 1 row
3055
2809
DROP TABLE t1,t2;
3056
 
# End of 4.1 tests
3057
 
#
3058
 
#decimal-related tests
3059
 
#
3060
 
create table t1 (df decimal(5,1));
 
2810
create table t1 (df decimal(5,1)) ENGINE=MyISAM;
3061
2811
insert into t1 values(1.1);
3062
2812
insert into t1 values(2.2);
3063
2813
select * from t1 where df <= all (select avg(df) from t1 group by df);
3067
2817
df
3068
2818
2.2
3069
2819
drop table t1;
3070
 
create temporary table t1 (df decimal(5,1)) ENGINE=MyISAM;
 
2820
create table t1 (df decimal(5,1)) ENGINE=MyISAM;
3071
2821
insert into t1 values(1.1);
3072
2822
select 1.1 * exists(select * from t1);
3073
2823
1.1 * exists(select * from t1)
3074
2824
1.1
3075
2825
drop table t1;
3076
 
CREATE TEMPORARY TABLE t1 (
 
2826
CREATE TABLE t1 (
3077
2827
grp int default NULL,
3078
2828
a decimal(10,2) default NULL) ENGINE=MyISAM;
3079
2829
insert into t1 values (1, 1), (2, 2), (2, 3), (3, 4), (3, 5), (3, 6), (NULL, NULL);
3093
2843
2.00
3094
2844
4.00
3095
2845
drop table t1;
3096
 
#
3097
 
# Test for bug #9338: lame substitution of c1 instead of c2 
3098
 
#
3099
 
CREATE temporary table t1 ( c1 integer ) ENGINE=MyISAM;
 
2846
CREATE table t1 ( c1 integer ) ENGINE=MyISAM;
3100
2847
INSERT INTO t1 VALUES ( 1 );
3101
2848
INSERT INTO t1 VALUES ( 2 );
3102
2849
INSERT INTO t1 VALUES ( 3 );
3103
 
CREATE TABLE t2 ( c2 integer );
 
2850
CREATE TABLE t2 ( c2 integer ) ENGINE=MyISAM;
3104
2851
INSERT INTO t2 VALUES ( 1 );
3105
2852
INSERT INTO t2 VALUES ( 4 );
3106
2853
INSERT INTO t2 VALUES ( 5 );
3112
2859
c1      c2
3113
2860
1       1
3114
2861
DROP TABLE t1,t2;
3115
 
#
3116
 
# Test for bug #9516: wrong evaluation of not_null_tables attribute in SQ 
3117
 
#
3118
 
CREATE TEMPORARY TABLE t1 ( c1 integer ) ENGINE=MyISAM;
 
2862
CREATE TABLE t1 ( c1 integer ) ENGINE=MyISAM;
3119
2863
INSERT INTO t1 VALUES ( 1 );
3120
2864
INSERT INTO t1 VALUES ( 2 );
3121
2865
INSERT INTO t1 VALUES ( 3 );
3122
2866
INSERT INTO t1 VALUES ( 6 );
3123
 
CREATE TEMPORARY TABLE t2 ( c2 integer ) ENGINE=MyISAM;
 
2867
CREATE TABLE t2 ( c2 integer ) ENGINE=MyISAM;
3124
2868
INSERT INTO t2 VALUES ( 1 );
3125
2869
INSERT INTO t2 VALUES ( 4 );
3126
2870
INSERT INTO t2 VALUES ( 5 );
3127
2871
INSERT INTO t2 VALUES ( 6 );
3128
 
CREATE TEMPORARY TABLE t3 ( c3 integer ) ENGINE=MyISAM;
 
2872
CREATE TABLE t3 ( c3 integer ) ENGINE=MyISAM;
3129
2873
INSERT INTO t3 VALUES ( 7 );
3130
2874
INSERT INTO t3 VALUES ( 8 );
3131
2875
SELECT c1,c2 FROM t1 LEFT JOIN t2 ON c1 = c2 
3134
2878
2       NULL
3135
2879
3       NULL
3136
2880
DROP TABLE t1,t2,t3;
3137
 
#
3138
 
# Correct building of equal fields list (do not include outer
3139
 
# fields) (BUG#6384)
3140
 
#
3141
 
CREATE TEMPORARY TABLE t1 (EMPNUM   CHAR(3)) ENGINE=MyISAM;
3142
 
CREATE TEMPORARY TABLE t2 (EMPNUM   CHAR(3) ) ENGINE=MyISAM;
 
2881
CREATE TABLE t1 (EMPNUM   CHAR(3)) ENGINE=MyISAM;
 
2882
CREATE TABLE t2 (EMPNUM   CHAR(3) ) ENGINE=MyISAM;
3143
2883
INSERT INTO t1 VALUES ('E1'),('E2');
3144
2884
INSERT INTO t2 VALUES ('E1');
3145
2885
DELETE FROM t1
3151
2891
EMPNUM
3152
2892
E1
3153
2893
DROP TABLE t1,t2;
3154
 
#
3155
 
# Test for bug #11487: range access in a subquery
3156
 
#
3157
 
CREATE TEMPORARY TABLE t1(select_id BIGINT, values_id BIGINT) ENGINE=MyISAM;
 
2894
CREATE TABLE t1(select_id BIGINT, values_id BIGINT) ENGINE=MyISAM;
3158
2895
INSERT INTO t1 VALUES (1, 1);
3159
 
CREATE TEMPORARY TABLE t2 (select_id BIGINT, values_id BIGINT, 
 
2896
CREATE TABLE t2 (select_id BIGINT, values_id BIGINT, 
3160
2897
PRIMARY KEY(select_id,values_id)) ENGINE=MyISAM;
3161
2898
INSERT INTO t2 VALUES (0, 1), (0, 2), (0, 3), (1, 5);
3162
2899
SELECT values_id FROM t1 
3175
2912
values_id
3176
2913
1
3177
2914
DROP TABLE t1, t2;
3178
 
# BUG#11821 : Select from subselect using aggregate function on an enum
3179
 
# segfaults:
3180
 
create temporary table t1 (fld enum('0','1')) ENGINE=MyISAM;
 
2915
create table t1 (fld enum('0','1')) ENGINE=MyISAM;
3181
2916
insert into t1 values ('1');
3182
2917
select * from (select max(fld) from t1) as foo;
3183
2918
max(fld)
3184
2919
1
3185
2920
drop table t1;
3186
 
#
3187
 
# Test for bug #11762: subquery with an aggregate function in HAVING
3188
 
#
3189
 
CREATE TEMPORARY TABLE t1 (a int, b int) ENGINE=MyISAM;
3190
 
CREATE TEMPORARY TABLE t2 (c int, d int) ENGINE=MyISAM;
3191
 
CREATE TEMPORARY TABLE t3 (e int) ENGINE=MyISAM;
 
2921
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
 
2922
CREATE TABLE t2 (c int, d int) ENGINE=MyISAM;
 
2923
CREATE TABLE t3 (e int) ENGINE=MyISAM;
3192
2924
INSERT INTO t1 VALUES 
3193
2925
(1,10), (2,10), (1,20), (2,20), (3,20), (2,30), (4,40);
3194
2926
INSERT INTO t2 VALUES
3329
3061
3       20
3330
3062
4       40
3331
3063
DROP TABLE t1,t2,t3;
3332
 
#
3333
 
# Test for bug #16603: GROUP BY in a row subquery with a quantifier 
3334
 
#                      when an index is defined on the grouping field
3335
 
CREATE TABLE t1 (a varchar(5), b varchar(10));
 
3064
CREATE TABLE t1 (a varchar(5), b varchar(10)) ENGINE=MyISAM;
3336
3065
INSERT INTO t1 VALUES
3337
3066
('AAA', 5), ('BBB', 4), ('BBB', 1), ('CCC', 2),
3338
3067
('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8);
3344
3073
EXPLAIN
3345
3074
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
3346
3075
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
3347
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       Using where
3348
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    #       Using temporary; Using filesort
 
3076
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    9       Using where
 
3077
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    9       Using temporary; Using filesort
3349
3078
ALTER TABLE t1 ADD INDEX(a);
3350
3079
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
3351
3080
a       b
3355
3084
EXPLAIN
3356
3085
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
3357
3086
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
3358
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       Using where
3359
 
2       SUBQUERY        t1      index   NULL    a       23      NULL    #       
 
3087
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    9       Using where
 
3088
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    9       Using temporary; Using filesort
3360
3089
DROP TABLE t1;
3361
 
#
3362
 
# Bug#17366: Unchecked Item_int results in server crash
3363
 
#
3364
 
create table t1( f1 int,f2 int);
 
3090
create table t1( f1 int,f2 int) ENGINE=MyISAM;
3365
3091
insert into t1 values (1,1),(2,2);
3366
3092
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';
3367
3093
t
3368
3094
crash1
3369
3095
crash1
3370
3096
drop table t1;
3371
 
#
3372
 
# Bug #18306: server crash on delete using subquery.
3373
 
#
3374
 
create temporary table t1 (c int, key(c)) ENGINE=MyISAM;
 
3097
create table t1 (c int, key(c)) ENGINE=MyISAM;
3375
3098
insert into t1 values (1142477582), (1142455969);
3376
 
create temporary table t2 (a int, b int) ENGINE=MyISAM;
 
3099
create table t2 (a int, b int) ENGINE=MyISAM;
3377
3100
insert into t2 values (2, 1), (1, 0);
3378
3101
delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1;
3379
3102
drop table t1, t2;
3380
 
#
3381
 
# Bug#19077: A nested materialized derived table is used before being populated.
3382
 
#
3383
 
create table t1 (i int, j bigint);
 
3103
create table t1 (i int, j bigint) ENGINE=MyISAM;
3384
3104
insert into t1 values (1, 2), (2, 2), (3, 2);
3385
3105
select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3;
3386
3106
min(i)
3387
3107
1
3388
3108
drop table t1;
3389
 
3390
 
# Bug#19700: subselect returning BIGINT always returned it as SIGNED
3391
 
#
3392
 
CREATE TEMPORARY TABLE t1 (i BIGINT) ENGINE=MyISAM;
 
3109
CREATE TABLE t1 (i BIGINT) ENGINE=MyISAM;
3393
3110
INSERT INTO t1 VALUES (10000000000000000);
3394
3111
INSERT INTO t1 VALUES (1);
3395
 
CREATE TEMPORARY TABLE t2 (i BIGINT) ENGINE=MyISAM;
 
3112
CREATE TABLE t2 (i BIGINT) ENGINE=MyISAM;
3396
3113
INSERT INTO t2 VALUES (10000000000000000);
3397
3114
INSERT INTO t2 VALUES (1);
3398
3115
/* simple test */
3410
3127
10000000000000000
3411
3128
DROP TABLE t1;
3412
3129
DROP TABLE t2;
3413
 
3414
 
# Bug#20519: subselect with LIMIT M, N
3415
 
#
3416
 
CREATE TEMPORARY TABLE t1 (
 
3130
CREATE TABLE t1 (
3417
3131
id bigint NOT NULL auto_increment,
3418
3132
name varchar(255) NOT NULL,
3419
3133
PRIMARY KEY  (id))
3424
3138
id bigint NOT NULL auto_increment,
3425
3139
mid bigint NOT NULL,
3426
3140
date date NOT NULL,
3427
 
PRIMARY KEY  (id));
 
3141
PRIMARY KEY  (id))
 
3142
ENGINE=MyISAM;
3428
3143
INSERT INTO t2 VALUES 
3429
3144
(1, 1, '2006-03-30'), (2, 2, '2006-04-06'), (3, 3, '2006-04-13'),
3430
3145
(4, 2, '2006-04-20'), (5, 1, '2006-05-01');
3457
3172
2       Joe     2006-04-20      2006-04-06
3458
3173
3       Frank   2006-04-13      NULL
3459
3174
DROP TABLE t1,t2;
3460
 
#
3461
 
# Bug#20869: subselect with range access by DESC
3462
 
#
3463
3175
CREATE TABLE t1 (
3464
3176
i1 int NOT NULL default '0',
3465
3177
i2 int NOT NULL default '0',
3466
3178
t datetime,
3467
 
PRIMARY KEY  (i1,i2,t));
 
3179
PRIMARY KEY  (i1,i2,t))
 
3180
ENGINE=MyISAM;
3468
3181
INSERT INTO t1 VALUES 
3469
3182
(24,1,'2005-03-03 16:31:31'),(24,1,'2005-05-27 12:40:07'),
3470
3183
(24,1,'2005-05-27 12:40:08'),(24,1,'2005-05-27 12:40:10'),
3476
3189
i1 int NOT NULL default '0',
3477
3190
i2 int NOT NULL default '0',
3478
3191
t datetime default NULL,
3479
 
PRIMARY KEY  (i1));
 
3192
PRIMARY KEY  (i1))
 
3193
ENGINE=MyISAM;
3480
3194
INSERT INTO t2 VALUES (24,1,'2006-06-20 12:29:40');
3481
3195
EXPLAIN
3482
3196
SELECT * FROM t1,t2
3484
3198
WHERE t1.t < t2.t  AND t1.i2=1 AND t2.i1=t1.i1
3485
3199
ORDER BY t1.t DESC LIMIT 1);
3486
3200
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
3487
 
1       PRIMARY t2      ALL     NULL    NULL    NULL    NULL    1       
3488
 
1       PRIMARY t1      index   NULL    PRIMARY 16      NULL    11      Using where; Using index; Using join buffer
3489
 
2       DEPENDENT SUBQUERY      t1      ref     PRIMARY PRIMARY 8       test.t2.i1,const        5       Using where; Using index; Using filesort
 
3201
1       PRIMARY t2      system  NULL    NULL    NULL    NULL    1       
 
3202
1       PRIMARY t1      index   NULL    PRIMARY 16      NULL    11      Using where; Using index
 
3203
2       DEPENDENT SUBQUERY      t1      range   PRIMARY PRIMARY 16      NULL    5       Using where; Using index
3490
3204
SELECT * FROM t1,t2
3491
3205
WHERE t1.t = (SELECT t1.t FROM t1 
3492
3206
WHERE t1.t < t2.t  AND t1.i2=1 AND t2.i1=t1.i1
3494
3208
i1      i2      t       i1      i2      t
3495
3209
24      1       2005-05-27 12:40:30     24      1       2006-06-20 12:29:40
3496
3210
DROP TABLE t1, t2;
3497
 
#
3498
 
# Bug#14654 : Cannot select from the same table twice within a UNION
3499
 
# statement 
3500
 
#
3501
 
CREATE TABLE t1 (i INT);
 
3211
CREATE TABLE t1 (i INT) ENGINE=MyISAM;
3502
3212
(SELECT i FROM t1) UNION (SELECT i FROM t1);
3503
3213
i
3504
3214
SELECT * FROM t1 WHERE NOT EXISTS 
3507
3217
(SELECT i FROM t1)
3508
3218
);
3509
3219
i
3510
 
#TODO:not supported
3511
3220
SELECT * FROM t1 
3512
3221
WHERE NOT EXISTS (((SELECT i FROM t1) UNION (SELECT i FROM t1)));
3513
3222
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION (SELECT i FROM t1)))' at line 1
3514
 
#TODO:not supported
3515
3223
explain select ((select t11.i from t1 t11) union (select t12.i from t1 t12))
3516
3224
from t1;
3517
3225
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'union (select t12.i from t1 t12))
3519
3227
explain select * from t1 where not exists 
3520
3228
((select t11.i from t1 t11) union (select t12.i from t1 t12));
3521
3229
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
3522
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       
3523
 
2       SUBQUERY        t11     ALL     NULL    NULL    NULL    NULL    #       
3524
 
3       UNION   t12     ALL     NULL    NULL    NULL    NULL    #       
3525
 
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    #       
 
3230
1       PRIMARY t1      system  NULL    NULL    NULL    NULL    0       const row not found
 
3231
2       SUBQUERY        NULL    NULL    NULL    NULL    NULL    NULL    NULL    no matching row in const table
 
3232
3       UNION   NULL    NULL    NULL    NULL    NULL    NULL    NULL    no matching row in const table
 
3233
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    NULL    
3526
3234
DROP TABLE t1;
3527
 
#
3528
 
# Bug #21540: Subqueries with no from and aggregate functions return 
3529
 
#              wrong results
3530
 
CREATE TABLE t1 (a INT, b INT);
3531
 
CREATE TABLE t2 (a INT);
 
3235
CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM;
 
3236
CREATE TABLE t2 (a INT) ENGINE=MyISAM;
3532
3237
INSERT INTO t2 values (1);
3533
3238
INSERT INTO t1 VALUES (1,1),(1,2),(2,3),(3,4);
3534
3239
SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a;
3567
3272
2
3568
3273
2
3569
3274
DROP TABLE t1,t2;
3570
 
#
3571
 
# Bug #21727: Correlated subquery that requires filesort:
3572
 
#             slow with big sort_buffer_size 
3573
 
#
3574
 
CREATE TEMPORARY TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b)) ENGINE=MyISAM;
3575
 
CREATE TEMPORARY TABLE t2 (x int auto_increment, y int, z int,
 
3275
CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b)) ENGINE=MyISAM;
 
3276
CREATE TABLE t2 (x int auto_increment, y int, z int,
3576
3277
PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b)) ENGINE=MyISAM;
3577
3278
SET SESSION sort_buffer_size = 32 * 1024;
3578
3279
Warnings:
3589
3290
COUNT(*)
3590
3291
3000
3591
3292
DROP TABLE t2,t1;
3592
 
#
3593
 
# Bug #25219: EXIST subquery with UNION over a mix of
3594
 
#             correlated and uncorrelated selects
3595
 
#
3596
 
CREATE TABLE t1 (id char(4) PRIMARY KEY, c int);
3597
 
CREATE TABLE t2 (c int);
 
3293
CREATE TABLE t1 (id char(4) PRIMARY KEY, c int) ENGINE=MyISAM;
 
3294
CREATE TABLE t2 (c int) ENGINE=MyISAM;
3598
3295
INSERT INTO t1 VALUES ('aa', 1);
3599
3296
INSERT INTO t2 VALUES (1);
3600
3297
SELECT * FROM t1
3614
3311
cc      3
3615
3312
dd      1
3616
3313
INSERT INTO t2 VALUES (2);
3617
 
CREATE TEMPORARY TABLE t3 (c int) ENGINE=MyISAM;
 
3314
CREATE TABLE t3 (c int) ENGINE=MyISAM;
3618
3315
INSERT INTO t3 VALUES (1);
3619
3316
SELECT * FROM t1
3620
3317
WHERE EXISTS (SELECT t2.c FROM t2 JOIN t3 ON t2.c=t3.c WHERE t2.c=1
3626
3323
cc      3
3627
3324
dd      1
3628
3325
DROP TABLE t1,t2,t3;
3629
 
#
3630
 
# Bug#21904 (parser problem when using IN with a double "(())")
3631
 
#
3632
3326
DROP TABLE IF EXISTS t1;
3633
3327
DROP TABLE IF EXISTS t2;
3634
3328
DROP TABLE IF EXISTS t1xt2;
3635
 
CREATE TEMPORARY TABLE t1 (
 
3329
CREATE TABLE t1 (
3636
3330
id_1 int NOT NULL,
3637
3331
t varchar(4) DEFAULT NULL)
3638
3332
ENGINE=MyISAM;
3639
 
CREATE TEMPORARY TABLE t2 (
 
3333
CREATE TABLE t2 (
3640
3334
id_2 int NOT NULL,
3641
3335
t varchar(4) DEFAULT NULL)
3642
3336
ENGINE=MyISAM;
3643
 
CREATE TEMPORARY TABLE t1xt2 (
 
3337
CREATE TABLE t1xt2 (
3644
3338
id_1 int NOT NULL,
3645
3339
id_2 int NOT NULL)
3646
3340
ENGINE=MyISAM;
3647
3341
INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd');
3648
3342
INSERT INTO t2 VALUES (2, 'bb'), (3, 'cc'), (4, 'dd'), (12, 'aa');
3649
3343
INSERT INTO t1xt2 VALUES (2, 2), (3, 3), (4, 4);
3650
 
# subselect returns 0 rows
3651
3344
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3652
3345
(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
3653
3346
id_1
3679
3372
3
3680
3373
4
3681
3374
insert INTO t1xt2 VALUES (1, 12);
3682
 
# subselect returns 1 row
3683
3375
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3684
3376
(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
3685
3377
id_1
3711
3403
3
3712
3404
4
3713
3405
insert INTO t1xt2 VALUES (2, 12);
3714
 
# subselect returns more than 1 row
3715
3406
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3716
3407
(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
3717
3408
id_1
3745
3436
DROP TABLE t1;
3746
3437
DROP TABLE t2;
3747
3438
DROP TABLE t1xt2;
3748
 
#
3749
 
# Bug #26728: derived table with concatanation of literals in select list
3750
 
#  
3751
 
CREATE TEMPORARY TABLE t1 (a int) ENGINE=MyISAM;
 
3439
CREATE TABLE t1 (a int) ENGINE=MyISAM;
3752
3440
INSERT INTO t1 VALUES (3), (1), (2);
3753
3441
SELECT 'this is ' 'a test.' AS col1, a AS col2 FROM t1;
3754
3442
col1    col2
3761
3449
this is a test. 1
3762
3450
this is a test. 2
3763
3451
DROP table t1;
3764
 
#
3765
 
# Bug #27257: COUNT(*) aggregated in outer query
3766
 
#  
3767
 
CREATE TEMPORARY TABLE t1 (a int, b int) ENGINE=MyISAM;
3768
 
CREATE TEMPORARY TABLE t2 (m int, n int) ENGINE=MyISAM;
 
3452
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
 
3453
CREATE TABLE t2 (m int, n int) ENGINE=MyISAM;
3769
3454
INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
3770
3455
INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
3771
3456
SELECT COUNT(*), a,
3789
3474
2       2
3790
3475
3       3
3791
3476
DROP TABLE t1,t2;
3792
 
#
3793
 
# Bug #27229: GROUP_CONCAT in subselect with COUNT() as an argument 
3794
 
#  
3795
 
CREATE TEMPORARY TABLE t1 (a int, b int) ENGINE=MyISAM;
3796
 
CREATE TEMPORARY TABLE t2 (m int, n int) ENGINE=MyISAM;
 
3477
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
 
3478
CREATE TABLE t2 (m int, n int) ENGINE=MyISAM;
3797
3479
INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
3798
3480
INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
3799
3481
SELECT COUNT(*) c, a,
3811
3493
3       3       4
3812
3494
1       4       2,2
3813
3495
DROP table t1,t2;
3814
 
#
3815
 
# Bug#27321: Wrong subquery result in a grouping select
3816
 
#
3817
 
CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b));
 
3496
CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b)) ENGINE=MyISAM;
3818
3497
INSERT INTO t1 VALUES (1,1,0,'a'), (1,2,0,'b'), (1,3,0,'c'), (1,4,0,'d'),
3819
3498
(1,5,0,'e'), (2,1,0,'f'), (2,2,0,'g'), (2,3,0,'h'), (3,4,0,'i'), (3,3,0,'j'),
3820
3499
(3,2,0,'k'), (3,1,0,'l'), (1,9,0,'m'), (1,0,10,'n'), (2,0,5,'o'), (3,0,7,'p');
3879
3558
2       o
3880
3559
3       p
3881
3560
DROP TABLE t1;
3882
 
#
3883
 
# Bug #27363: nested aggregates in outer, subquery / sum(select
3884
 
# count(outer))
3885
 
#
3886
 
CREATE TABLE t1 (a INT);
 
3561
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
3887
3562
INSERT INTO t1 values (1),(1),(1),(1);
3888
 
CREATE TEMPORARY TABLE t2 (x INT) ENGINE=MyISAM;
 
3563
CREATE TABLE t2 (x INT) ENGINE=MyISAM;
3889
3564
INSERT INTO t1 values (1000),(1001),(1002);
3890
3565
SELECT SUM( (SELECT COUNT(a) FROM t2) ) FROM t1;
3891
3566
ERROR HY000: Invalid use of group function
3900
3575
FROM t1;
3901
3576
ERROR HY000: Invalid use of group function
3902
3577
DROP TABLE t1,t2;
3903
 
#
3904
 
# Bug #27807: Server crash when executing subquery with EXPLAIN
3905
 
#  
3906
 
CREATE TABLE t1 (a int, b int, KEY (a));
 
3578
CREATE TABLE t1 (a int, b int, KEY (a)) ENGINE=MyISAM;
3907
3579
INSERT INTO t1 VALUES (1,1),(2,1);
3908
3580
EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b);
3909
3581
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
3910
3582
1       PRIMARY t1      ref     a       a       5       const   1       Using where; Using index
3911
3583
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    2       Using temporary; Using filesort
3912
3584
DROP TABLE t1;
3913
 
#
3914
 
# Bug #28377: grouping query with a correlated subquery in WHERE condition
3915
 
#  
3916
 
CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id));
 
3585
CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)) ENGINE=MyISAM;
3917
3586
INSERT INTO t1 VALUES
3918
3587
(3,'FL'), (2,'GA'), (4,'FL'), (1,'GA'), (5,'NY'), (7,'FL'), (6,'NY');
3919
 
CREATE TEMPORARY TABLE t2 (id int NOT NULL, INDEX idx(id)) ENGINE=MyISAM;
 
3588
CREATE TABLE t2 (id int NOT NULL, INDEX idx(id)) ENGINE=MyISAM;
3920
3589
INSERT INTO t2 VALUES (7), (5), (1), (3);
3921
3590
SELECT id, st FROM t1 
3922
3591
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
3943
3612
2       GA
3944
3613
4       FL
3945
3614
DROP TABLE t1,t2;
3946
 
#
3947
 
# Bug #28728: crash with EXPLAIN EXTENDED for a query with a derived table
3948
 
#             over a grouping subselect
3949
 
3950
 
CREATE TEMPORARY TABLE t1 (a int) ENGINE=MyISAM;
 
3615
CREATE TABLE t1 (a int) ENGINE=MyISAM;
3951
3616
INSERT INTO t1 VALUES (1), (2);
3952
3617
EXPLAIN EXTENDED
3953
3618
SELECT * FROM (SELECT count(*) FROM t1 GROUP BY a) as res;
3957
3622
Warnings:
3958
3623
Note    1003    select `res`.`count(*)` AS `count(*)` from (select count(0) AS `count(*)` from `test`.`t1` group by `test`.`t1`.`a`) `res`
3959
3624
DROP TABLE t1;
3960
 
#
3961
 
# Bug #28811: crash for query containing subquery with ORDER BY and LIMIT 1 
3962
 
#
3963
3625
CREATE TABLE t1 (
3964
3626
a varchar(255) default NULL,
3965
3627
b timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
3966
 
INDEX idx(a,b));
 
3628
INDEX idx(a,b))
 
3629
ENGINE=MyISAM;
3967
3630
CREATE TABLE t2 (
3968
 
a varchar(255) default NULL);
 
3631
a varchar(255) default NULL)
 
3632
ENGINE=MyISAM;
3969
3633
INSERT INTO t1 VALUES ('abcdefghijk','2007-05-07 06:00:24');
3970
3634
INSERT INTO t1 SELECT * FROM t1;
3971
3635
INSERT INTO t1 SELECT * FROM t1;
3986
3650
1
3987
3651
1
3988
3652
DROP TABLE t1,t2;
3989
 
#
3990
 
# Bug #27333: subquery grouped for aggregate of outer query / no aggregate
3991
 
# of subquery
3992
 
#
3993
 
CREATE TEMPORARY TABLE t1 (a INTEGER, b INTEGER) ENGINE=MyISAM;
3994
 
CREATE TEMPORARY TABLE t2 (x INTEGER) ENGINE=MyISAM;
 
3653
CREATE TABLE t1 (a INTEGER, b INTEGER) ENGINE=MyISAM;
 
3654
CREATE TABLE t2 (x INTEGER) ENGINE=MyISAM;
3995
3655
INSERT INTO t1 VALUES (1,11), (2,22), (2,22);
3996
3656
INSERT INTO t2 VALUES (1), (2);
3997
 
# wasn't failing, but should
3998
3657
SELECT a, COUNT(b), (SELECT COUNT(b) FROM t2) FROM t1 GROUP BY a;
3999
3658
ERROR 21000: Subquery returns more than 1 row
4000
 
# fails as it should
4001
3659
SELECT a, COUNT(b), (SELECT COUNT(b)+0 FROM t2) FROM t1 GROUP BY a;
4002
3660
ERROR 21000: Subquery returns more than 1 row
4003
3661
SELECT (SELECT SUM(t1.a)/AVG(t2.x) FROM t2) FROM t1;
4004
3662
(SELECT SUM(t1.a)/AVG(t2.x) FROM t2)
4005
3663
3.3333
4006
3664
DROP TABLE t1,t2;
4007
 
# second test case from 27333
4008
 
CREATE TABLE t1 (a INT, b INT);
 
3665
CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM;
4009
3666
INSERT INTO t1 VALUES (1, 2), (1,3), (1,4), (2,1), (2,2);
4010
 
# returns no rows, when it should
4011
3667
SELECT a1.a, COUNT(*) FROM t1 a1 WHERE a1.a = 1
4012
3668
AND EXISTS( SELECT a2.a FROM t1 a2 WHERE a2.a = a1.a)
4013
3669
GROUP BY a1.a;
4014
3670
a       COUNT(*)
4015
3671
1       3
4016
3672
DROP TABLE t1;
4017
 
#test cases from 29297
4018
 
CREATE TEMPORARY TABLE t1 (a INT) ENGINE=MyISAM;
4019
 
CREATE TEMPORARY TABLE t2 (a INT) ENGINE=MyISAM;
 
3673
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
 
3674
CREATE TABLE t2 (a INT) ENGINE=MyISAM;
4020
3675
INSERT INTO t1 VALUES (1),(2);
4021
3676
INSERT INTO t2 VALUES (1),(2);
4022
3677
SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=0) FROM t1;
4028
3683
(SELECT SUM(t1.a) FROM t2 WHERE a=1)
4029
3684
3
4030
3685
DROP TABLE t1,t2;
4031
 
#
4032
 
# Bug #31884: Assertion + crash in subquery in the SELECT clause.
4033
 
#
4034
 
CREATE TEMPORARY TABLE t1 (a1 INT, a2 INT) ENGINE=MyISAM;
4035
 
CREATE TEMPORARY TABLE t2 (b1 INT, b2 INT) ENGINE=MyISAM;
 
3686
CREATE TABLE t1 (a1 INT, a2 INT) ENGINE=MyISAM;
 
3687
CREATE TABLE t2 (b1 INT, b2 INT) ENGINE=MyISAM;
4036
3688
INSERT INTO t1 VALUES (100, 200);
4037
3689
INSERT INTO t1 VALUES (101, 201);
4038
3690
INSERT INTO t2 VALUES (101, 201);
4042
3694
0
4043
3695
0
4044
3696
DROP TABLE t1, t2;
4045
 
#
4046
 
# Bug #30788: Inconsistent retrieval of char/varchar
4047
 
#
4048
 
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10));
 
3697
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10)) ENGINE=MyISAM;
4049
3698
INSERT INTO t1 VALUES ('a', 'aa');
4050
3699
INSERT INTO t1 VALUES ('a', 'aaa');
4051
3700
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
4052
3701
a       b
4053
 
a       aa
4054
 
a       aaa
4055
3702
CREATE INDEX I1 ON t1 (a);
4056
3703
CREATE INDEX I2 ON t1 (b);
4057
3704
EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
4058
3705
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
4059
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       Using where
4060
 
2       SUBQUERY        t1      index   NULL    I1      7       NULL    #       Using index
 
3706
1       PRIMARY t1      index   I1      I1      7       NULL    2       Using index; LooseScan
 
3707
1       PRIMARY t1      ref     I2      I2      43      test.t1.a       2       Using where
4061
3708
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
4062
3709
a       b
4063
 
a       aa
4064
 
a       aaa
4065
 
CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10));
 
3710
CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10)) ENGINE=MyISAM;
4066
3711
INSERT INTO t2 SELECT * FROM t1;
4067
3712
CREATE INDEX I1 ON t2 (a);
4068
3713
CREATE INDEX I2 ON t2 (b);
4069
3714
EXPLAIN SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
4070
3715
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
4071
 
1       PRIMARY t2      ALL     NULL    NULL    NULL    NULL    #       Using where
4072
 
2       SUBQUERY        t2      index   NULL    I1      7       NULL    #       Using index
 
3716
1       PRIMARY t2      index   I1      I1      7       NULL    2       Using index; LooseScan
 
3717
1       PRIMARY t2      ref     I2      I2      43      test.t2.a       2       Using where
4073
3718
SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
4074
3719
a       b
4075
 
a       aa
4076
 
a       aaa
4077
3720
EXPLAIN
4078
3721
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
4079
3722
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
4080
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       Using where
4081
 
2       SUBQUERY        t1      index   NULL    I1      7       NULL    #       Using where; Using index
 
3723
1       PRIMARY t1      index   I1      I1      7       NULL    2       Using where; Using index; LooseScan
 
3724
1       PRIMARY t1      ref     I2      I2      43      test.t1.a       2       Using where
4082
3725
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
4083
3726
a       b
4084
 
a       aa
4085
 
a       aaa
4086
3727
DROP TABLE t1,t2;
4087
 
#
4088
 
# Bug #32400: Complex SELECT query returns correct result only on some
4089
 
# occasions
4090
 
#
4091
 
CREATE TABLE t1(a INT, b INT);
 
3728
CREATE TABLE t1(a INT, b INT) ENGINE=MyISAM;
4092
3729
INSERT INTO t1 VALUES (1,1), (1,2), (2,3), (2,4);
4093
3730
EXPLAIN 
4094
3731
SELECT a AS out_a, MIN(b) FROM t1
4104
3741
WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a)
4105
3742
GROUP BY a;
4106
3743
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
4107
 
1       PRIMARY t1_outer        ALL     NULL    NULL    NULL    NULL    #       Using where; Using temporary; Using filesort
4108
 
2       DEPENDENT SUBQUERY      t1      ALL     NULL    NULL    NULL    NULL    #       Using where
 
3744
1       PRIMARY t1_outer        ALL     NULL    NULL    NULL    NULL    4       Using where; Using temporary; Using filesort
 
3745
2       DEPENDENT SUBQUERY      t1      ALL     NULL    NULL    NULL    NULL    4       Using where
4109
3746
SELECT a AS out_a, MIN(b) FROM t1 t1_outer
4110
3747
WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a)
4111
3748
GROUP BY a;
4113
3750
1       2
4114
3751
2       4
4115
3752
DROP TABLE t1;
4116
 
#
4117
 
# Bug #32036: EXISTS within a WHERE clause with a UNION crashes MySQL 5.122
4118
 
#
4119
 
CREATE TEMPORARY TABLE t1 (a INT) ENGINE=MyISAM;
4120
 
CREATE TABLE t2 (a INT);
 
3753
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
 
3754
CREATE TABLE t2 (a INT) ENGINE=MyISAM;
4121
3755
INSERT INTO t1 VALUES (1),(2);
4122
3756
INSERT INTO t2 VALUES (1),(2);
4123
3757
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
4136
3770
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION 
4137
3771
(SELECT 1 FROM t2 WHERE t1.a = t2.a));
4138
3772
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
4139
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
4140
 
2       DEPENDENT SUBQUERY      t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
4141
 
3       DEPENDENT UNION t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
4142
 
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    #       NULL    
 
3773
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
 
3774
2       DEPENDENT SUBQUERY      t2      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
 
3775
3       DEPENDENT UNION t2      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
 
3776
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
4143
3777
Warnings:
4144
3778
Note    1276    Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
4145
3779
Note    1276    Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1
4146
3780
Note    1003    select 2 AS `2` from `test`.`t1` where exists((select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)) union (select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)))
4147
3781
DROP TABLE t1,t2;
4148
 
#
4149
 
# BUG#33794 "MySQL crashes executing specific query on specific dump"
4150
 
#
4151
 
CREATE TEMPORARY TABLE t4 (
 
3782
CREATE TABLE t4 (
4152
3783
f7 varchar(32) collate utf8_bin NOT NULL default '',
4153
3784
f10 varchar(32) collate utf8_bin default NULL,
4154
3785
PRIMARY KEY  (f7))
4159
3790
f2 varchar(50) collate utf8_bin default NULL,
4160
3791
f3 varchar(10) collate utf8_bin default NULL,
4161
3792
PRIMARY KEY  (f4),
4162
 
UNIQUE KEY uk1 (f2));
 
3793
UNIQUE KEY uk1 (f2))
 
3794
ENGINE=MyISAM;
4163
3795
INSERT INTO t2 VALUES(1,1,null), (2,2,null);
4164
 
CREATE TEMPORARY TABLE t1  (
 
3796
CREATE TABLE t1  (
4165
3797
f8 varchar(32) collate utf8_bin NOT NULL default '',
4166
3798
f1 varchar(10) collate utf8_bin default NULL,
4167
3799
f9 varchar(32) collate utf8_bin default NULL,
4168
3800
PRIMARY KEY  (f8))
4169
3801
ENGINE=MyISAM;
4170
3802
INSERT INTO t1 VALUES (1,'P',1), (2,'P',1), (3,'R',2);
4171
 
CREATE TEMPORARY TABLE t3 (
 
3803
CREATE TABLE t3 (
4172
3804
f6 varchar(32) collate utf8_bin NOT NULL default '',
4173
3805
f5 varchar(50) collate utf8_bin default NULL,
4174
3806
PRIMARY KEY (f6))
4196
3828
2       NULL    NULL
4197
3829
DROP TABLE t1, t2, t3, t4;
4198
3830
End of 5.0 tests.
4199
 
#
4200
 
#  Test [NOT] IN truth table (both as top-level and general predicate).
4201
 
#
4202
 
create temporary table t_out (subcase char(3),
 
3831
create table t_out (subcase char(3),
4203
3832
a1 char(2), b1 char(2), c1 char(2)) ENGINE=MyISAM;
4204
 
create table t_in  (a2 char(2), b2 char(2), c2 char(2));
 
3833
create table t_in  (a2 char(2), b2 char(2), c2 char(2)) ENGINE=MyISAM;
4205
3834
insert into t_out values ('A.1','2a', NULL, '2a');
4206
 
#------------------------- A.2 - impossible
4207
3835
insert into t_out values ('A.3', '2a', NULL, '2a');
4208
3836
insert into t_out values ('A.4', '2a', NULL, 'xx');
4209
3837
insert into t_out values ('B.1', '2a', '2a', '2a');
4303
3931
NOT((a1, b1, c1) IN (select * from t_in));
4304
3932
not_pred_in
4305
3933
F
4306
 
# test non-top level result indirectly
4307
3934
select case when count(*) > 0 then 'N' else 'wrong result' end as pred_in from t_out
4308
3935
where subcase = 'A.3' and
4309
3936
((a1, b1, c1) IN (select * from t_in)) is NULL and
4374
4001
NOT((a1, b1, c1) IN (select * from t_in));
4375
4002
not_pred_in
4376
4003
F
4377
 
# test non-top level result indirectly
4378
4004
select case when count(*) > 0 then 'N' else 'wrong result' end as pred_in from t_out
4379
4005
where subcase = 'B.3' and
4380
4006
((a1, b1, c1) IN (select * from t_in)) is NULL and
4399
4025
T
4400
4026
drop table t_out;
4401
4027
drop table t_in;
4402
 
#
4403
 
# Bug#20835 (literal string with =any values)
4404
 
#
4405
 
CREATE TABLE t1 (s1 char(1));
 
4028
CREATE TABLE t1 (s1 char(1)) ENGINE=MyISAM;
4406
4029
INSERT INTO t1 VALUES ('a');
4407
4030
SELECT * FROM t1 WHERE 'a' = ANY (SELECT s1 FROM t1);
4408
4031
s1
4409
4032
a
4410
4033
DROP TABLE t1;
4411
 
#
4412
 
# Bug#33204: INTO is allowed in subselect, causing inconsistent results
4413
 
#
4414
 
CREATE TABLE t1( a INT );
 
4034
CREATE TABLE t1( a INT ) ENGINE=MyISAM;
4415
4035
INSERT INTO t1 VALUES (1),(2);
4416
 
CREATE TABLE t2( a INT, b INT );
 
4036
CREATE TABLE t2( a INT, b INT ) ENGINE=MyISAM;
4417
4037
SELECT * 
4418
4038
FROM (SELECT a INTO @var FROM t1 WHERE a = 2) t1a;
4419
4039
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @var FROM t1 WHERE a = 2) t1a' at line 2
4464
4084
a
4465
4085
1
4466
4086
2
4467
 
# This was not allowed previously. Possibly, it should be allowed on the future.
4468
 
# For now, the intent is to keep the fix as non-intrusive as possible.
4469
4087
SELECT * FROM ((SELECT 1 a) UNION SELECT 1 a);
4470
4088
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near ')' at line 1
4471
4089
SELECT * FROM (SELECT 1 a UNION (SELECT 1 a)) alias;
4504
4122
SELECT * FROM (SELECT 1 a UNION SELECT 1 a ORDER BY a LIMIT 1) t1a;
4505
4123
a
4506
4124
1
4507
 
# Test of rule
4508
 
# table_factor:  '(' get_select_lex query_expression_body ')' opt_table_alias
4509
 
# UNION should not be allowed inside the parentheses, nor should
4510
 
# aliases after.
4511
 
4512
4125
SELECT * FROM t1 JOIN  (SELECT 1 UNION SELECT 1) alias ON 1;
4513
4126
a       1
4514
4127
1       1
4524
4137
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
4525
4138
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 't1a ON 1' at line 1
4526
4139
SELECT * FROM t1 JOIN  (t1 t1a)  ON 1;
4527
 
ERROR HY000: Implicit cartesian join attempted.
 
4140
a       a
 
4141
1       1
 
4142
2       1
 
4143
1       2
 
4144
2       2
4528
4145
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
4529
 
ERROR HY000: Implicit cartesian join attempted.
 
4146
a       a
 
4147
1       1
 
4148
2       1
 
4149
1       2
 
4150
2       2
4530
4151
SELECT * FROM (t1 t1a);
4531
4152
a
4532
4153
1
4551
4172
a       a
4552
4173
1       1
4553
4174
2       1
4554
 
# For the join, TABLE_LIST::select_lex == NULL
4555
 
# Check that we handle this.
4556
4175
SELECT * FROM (t1 JOIN (SELECT 1) t1a1 ON 1) t1a2;
4557
4176
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 't1a2' at line 1
4558
4177
SELECT * FROM t1 WHERE a = ALL ( SELECT 1 );
4600
4219
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO OUTFILE 'file' )' at line 1
4601
4220
SELECT ( SELECT 1 UNION SELECT 1 INTO DUMPFILE 'file' );
4602
4221
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO DUMPFILE 'file' )' at line 1
4603
 
# Make sure context is popped when we leave the nested select
4604
4222
SELECT ( SELECT a FROM t1 WHERE a = 1 ), a FROM t1;
4605
4223
( SELECT a FROM t1 WHERE a = 1 )        a
4606
4224
1       1
4609
4227
( SELECT a FROM t1 WHERE a = 1 UNION SELECT 1 ) a
4610
4228
1       1
4611
4229
1       2
4612
 
# Make sure we have feature F561 (see .yy file)
4613
4230
SELECT * FROM t2 WHERE (a, b) IN (SELECT a, b FROM t2);
4614
4231
a       b
4615
 
# Make sure the parser does not allow nested UNIONs anywhere
4616
4232
SELECT 1 UNION ( SELECT 1 UNION SELECT 1 );
4617
4233
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1 )' at line 1
4618
4234
( SELECT 1 UNION SELECT 1 ) UNION SELECT 1;