~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysql-test/r/subselect.result

  • Committer: Monty Taylor
  • Date: 2008-07-05 22:08:52 UTC
  • mto: This revision was merged to the branch mainline in revision 77.
  • Revision ID: monty@inaugust.com-20080705220852-cqd9t6tfkhvlcf73
Removed HAVE_LONG_LONG, as this is now assumed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
8
8
Warnings:
9
9
Note    1249    Select 2 was reduced during optimization
10
 
Note    1003    select 2 AS `(select 2)`
 
10
Note    1003    select 2 AS "(select 2)"
11
11
SELECT (SELECT 1) UNION SELECT (SELECT 2);
12
12
(SELECT 1)
13
13
1
20
20
Warnings:
21
21
Note    1249    Select 2 was reduced during optimization
22
22
Note    1249    Select 4 was reduced during optimization
23
 
Note    1003    select 1 AS `(SELECT 1)` union select 2 AS `(SELECT 2)`
 
23
Note    1003    select 1 AS "(SELECT 1)" union select 2 AS "(SELECT 2)"
24
24
SELECT (SELECT (SELECT 0 UNION SELECT 0));
25
25
(SELECT (SELECT 0 UNION SELECT 0))
26
26
0
32
32
NULL    UNION RESULT    <union3,4>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
33
33
Warnings:
34
34
Note    1249    Select 2 was reduced during optimization
35
 
Note    1003    select (select 0 AS `0` union select 0 AS `0`) AS `(SELECT (SELECT 0 UNION SELECT 0))`
 
35
Note    1003    select (select 0 AS "0" union select 0 AS "0") AS "(SELECT (SELECT 0 UNION SELECT 0))"
36
36
SELECT (SELECT 1 FROM (SELECT 1) as b HAVING a=1) as a;
37
37
ERROR 42S22: Reference 'a' not supported (forward reference in item list)
38
38
SELECT (SELECT 1 FROM (SELECT 1) as b HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) as c HAVING a=1) as b;
50
50
Warnings:
51
51
Note    1276    Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1
52
52
Note    1276    Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1
53
 
Note    1003    select 1 AS `1` from (select 1 AS `a`) `b` having ((select '1' AS `a`) = 1)
 
53
Note    1003    select 1 AS "1" from (select 1 AS "a") "b" having ((select '1' AS "a") = 1)
54
54
SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
55
55
1
56
56
1
183
183
4       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    2       100.00  
184
184
NULL    UNION RESULT    <union1,3>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
185
185
Warnings:
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`)
 
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")
187
187
select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2;
188
188
(select a from t3 where a<t2.a*4 order by 1 desc limit 1)       a
189
189
3       1
199
199
3       DERIVED t2      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
200
200
2       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where; Using filesort
201
201
Warnings:
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`
 
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"
203
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);
204
204
a
205
205
2
220
220
3       DEPENDENT SUBQUERY      t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
221
221
Warnings:
222
222
Note    1276    Field or reference 'test.t4.a' of SELECT #3 was resolved in SELECT #1
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`
 
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"
224
224
select * from t3 where exists (select * from t2 where t2.b=t3.a);
225
225
a
226
226
7
266
266
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
267
267
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    3       100.00  
268
268
Warnings:
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`)))
 
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")))
270
270
select * from t3 where a >= all (select b from t2);
271
271
a
272
272
7
304
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;
305
305
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
306
306
1       PRIMARY t2      ALL     NULL    NULL    NULL    NULL    2       100.00  
307
 
2       DEPENDENT SUBQUERY      t1      ALL     NULL    NULL    NULL    NULL    1       100.00  Using where
 
307
2       DEPENDENT SUBQUERY      t1      system  NULL    NULL    NULL    NULL    1       100.00  
308
308
3       DEPENDENT UNION t5      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
309
309
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
310
310
Warnings:
311
311
Note    1276    Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
312
312
Note    1276    Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1
313
 
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"
314
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;
315
315
ERROR 21000: Subquery returns more than 1 row
316
316
create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq));
328
328
2       DEPENDENT SUBQUERY      t7      eq_ref  PRIMARY PRIMARY 4       test.t6.clinic_uq       1       100.00  Using index
329
329
Warnings:
330
330
Note    1276    Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1
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`))
 
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"))
332
332
select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
333
333
ERROR 23000: Column 'a' in field list is ambiguous
334
334
drop table t1,t2,t3;
348
348
a       b
349
349
W       a
350
350
CREATE TABLE `t8` (
351
 
`pseudo` varchar(35) NOT NULL default '',
352
 
`email` varchar(60) NOT NULL default '',
 
351
`pseudo` varchar(35) character set latin1 NOT NULL default '',
 
352
`email` varchar(60) character set latin1 NOT NULL default '',
353
353
PRIMARY KEY  (`pseudo`),
354
354
UNIQUE KEY `email` (`email`)
355
 
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
 
355
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
356
356
INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
357
357
INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
358
358
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
359
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');
360
360
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
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
 
361
1       PRIMARY t8      const   PRIMARY PRIMARY 37      const   1       100.00  Using index
 
362
4       SUBQUERY        t8      const   PRIMARY PRIMARY 37              1       100.00  Using index
 
363
2       SUBQUERY        t8      const   PRIMARY PRIMARY 37      const   1       100.00  
 
364
3       SUBQUERY        t8      const   PRIMARY PRIMARY 37              1       100.00  Using index
365
365
Warnings:
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')))
 
366
Note    1003    select 'joce' AS "pseudo",(select 'test' AS "email" from "test"."t8" where 1) AS "(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))" from "test"."t8" where 1
367
367
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
368
368
t8 WHERE pseudo='joce');
369
369
ERROR 21000: Operand should contain 1 column(s)
377
377
ERROR 21000: Subquery returns more than 1 row
378
378
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
379
379
CREATE TABLE `t1` (
380
 
`topic` bigint NOT NULL default '0',
 
380
`topic` mediumint(8) unsigned NOT NULL default '0',
381
381
`date` date NOT NULL default '0000-00-00',
382
 
`pseudo` varchar(35) NOT NULL default '',
 
382
`pseudo` varchar(35) character set latin1 NOT NULL default '',
383
383
PRIMARY KEY  (`pseudo`,`date`,`topic`),
384
384
KEY `topic` (`topic`)
385
385
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
387
387
('43506','2002-10-02','joce'),('40143','2002-08-03','joce');
388
388
EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
389
389
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
390
 
1       SIMPLE  t1      index   NULL    PRIMARY 153     NULL    2       100.00  Using where; Using index
 
390
1       SIMPLE  t1      index   NULL    PRIMARY 43      NULL    2       100.00  Using where; Using index
391
391
Warnings:
392
 
Note    1003    select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')
 
392
Note    1003    select distinct "test"."t1"."date" AS "date" from "test"."t1" where ("test"."t1"."date" = '2002-08-03')
393
393
EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
394
394
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
395
395
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
396
 
2       SUBQUERY        t1      index   NULL    PRIMARY 153     NULL    2       100.00  Using where; Using index
 
396
2       SUBQUERY        t1      index   NULL    PRIMARY 43      NULL    2       100.00  Using where; Using index
397
397
Warnings:
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')`
 
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')"
399
399
SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
400
400
date
401
401
2002-08-03
411
411
ERROR 21000: Subquery returns more than 1 row
412
412
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1);
413
413
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
414
 
1       PRIMARY t1      index   NULL    topic   8       NULL    2       100.00  Using index
 
414
1       PRIMARY t1      index   NULL    topic   3       NULL    2       100.00  Using index
415
415
2       SUBQUERY        NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
416
416
3       UNION   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
417
417
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
418
418
Warnings:
419
 
Note    1003    select 1 AS `1` from `test`.`t1` where 1
 
419
Note    1003    select 1 AS "1" from "test"."t1" where 1
420
420
drop table t1;
421
421
CREATE TABLE `t1` (
422
 
`numeropost` bigint NOT NULL auto_increment,
423
 
`maxnumrep` int NOT NULL default '0',
 
422
`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
 
423
`maxnumrep` int(10) unsigned NOT NULL default '0',
424
424
PRIMARY KEY  (`numeropost`),
425
425
UNIQUE KEY `maxnumrep` (`maxnumrep`)
426
426
) ENGINE=MyISAM ROW_FORMAT=FIXED;
427
427
INSERT INTO t1 (numeropost,maxnumrep) VALUES (40143,1),(43506,2);
428
428
CREATE TABLE `t2` (
429
429
`mot` varchar(30) NOT NULL default '',
430
 
`topic` bigint NOT NULL default '0',
 
430
`topic` mediumint(8) unsigned NOT NULL default '0',
431
431
`date` date NOT NULL default '0000-00-00',
432
432
`pseudo` varchar(35) NOT NULL default '',
433
433
PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`)
491
491
joce    43506   2002-10-22      joce    0
492
492
drop table t1,t2;
493
493
CREATE TABLE `t1` (
494
 
`numeropost` bigint NOT NULL auto_increment,
495
 
`maxnumrep` int NOT NULL default '0',
 
494
`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
 
495
`maxnumrep` int(10) unsigned NOT NULL default '0',
496
496
PRIMARY KEY  (`numeropost`),
497
497
UNIQUE KEY `maxnumrep` (`maxnumrep`)
498
498
) ENGINE=MyISAM ROW_FORMAT=FIXED;
516
516
ERROR 21000: Subquery returns more than 1 row
517
517
drop table t1;
518
518
CREATE TABLE `t1` (
519
 
`numeropost` bigint NOT NULL default '0',
520
 
`numreponse` int NOT NULL auto_increment,
 
519
`numeropost` mediumint(8) unsigned NOT NULL default '0',
 
520
`numreponse` int(10) unsigned NOT NULL auto_increment,
521
521
`pseudo` varchar(35) NOT NULL default '',
522
522
PRIMARY KEY  (`numeropost`,`numreponse`),
523
523
UNIQUE KEY `numreponse` (`numreponse`),
536
536
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
537
537
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Select tables optimized away
538
538
Warnings:
539
 
Note    1003    select max(`test`.`t1`.`numreponse`) AS `MAX(numreponse)` from `test`.`t1` where multiple equal(1, `test`.`t1`.`numeropost`)
 
539
Note    1003    select max("test"."t1"."numreponse") AS "MAX(numreponse)" from "test"."t1" where ("test"."t1"."numeropost" = '1')
540
540
EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1');
541
541
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
542
 
1       PRIMARY t1      const   PRIMARY,numreponse      PRIMARY 12      const,const     1       100.00  Using index
 
542
1       PRIMARY t1      const   PRIMARY,numreponse      PRIMARY 7       const,const     1       100.00  Using index
543
543
2       SUBQUERY        NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Select tables optimized away
544
544
Warnings:
545
 
Note    1003    select '3' AS `numreponse` from `test`.`t1` where 1
 
545
Note    1003    select '3' AS "numreponse" from "test"."t1" where (('1' = '1'))
546
546
drop table t1;
547
 
CREATE TABLE t1 (a int);
 
547
CREATE TABLE t1 (a int(1));
548
548
INSERT INTO t1 VALUES (1);
549
549
SELECT 1 FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1;
550
550
1
605
605
2       12
606
606
select * from t12;
607
607
a       b
608
 
2       12
 
608
33      10
609
609
22      11
610
 
33      10
 
610
2       12
611
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
612
ERROR HY000: You can't specify target table 't12' for update in FROM clause
613
613
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
619
619
1       11
620
620
select * from t12;
621
621
a       b
 
622
33      10
622
623
22      11
623
 
33      10
624
624
drop table t11, t12, t2;
625
625
CREATE TABLE t1 (x int);
626
626
create table t2 (a int);
703
703
select * from t1;
704
704
x       y
705
705
1       3
 
706
4       2
706
707
2       1
707
 
4       2
708
708
drop table t1, t2, t3;
709
709
SELECT * FROM (SELECT 1) b WHERE 1 IN (SELECT *);
710
710
ERROR HY000: No tables used
711
 
CREATE TABLE t2 (id int default NULL, KEY id (id)) ENGINE=MyISAM;
 
711
CREATE TABLE t2 (id int(11) default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1;
712
712
INSERT INTO t2 VALUES (1),(2);
713
713
SELECT * FROM t2 WHERE id IN (SELECT 1);
714
714
id
718
718
1       PRIMARY t2      ref     id      id      5       const   1       100.00  Using index
719
719
Warnings:
720
720
Note    1249    Select 2 was reduced during optimization
721
 
Note    1003    select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = 1)
 
721
Note    1003    select "test"."t2"."id" AS "id" from "test"."t2" where ("test"."t2"."id" = 1)
722
722
SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3);
723
723
id
724
724
1
731
731
Warnings:
732
732
Note    1249    Select 3 was reduced during optimization
733
733
Note    1249    Select 2 was reduced during optimization
734
 
Note    1003    select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = (1 + 1))
 
734
Note    1003    select "test"."t2"."id" AS "id" from "test"."t2" where ("test"."t2"."id" = (1 + 1))
735
735
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3);
736
736
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
737
737
1       PRIMARY t2      index   NULL    id      5       NULL    2       100.00  Using where; Using index
739
739
3       DEPENDENT UNION NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
740
740
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
741
741
Warnings:
742
 
Note    1003    select `test`.`t2`.`id` AS `id` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 AS `1` having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 AS `3` having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3))))
 
742
Note    1003    select "test"."t2"."id" AS "id" from "test"."t2" where <in_optimizer>("test"."t2"."id",<exists>(select 1 AS "1" having (<cache>("test"."t2"."id") = <ref_null_helper>(1)) union select 3 AS "3" having (<cache>("test"."t2"."id") = <ref_null_helper>(3))))
743
743
SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3);
744
744
id
745
745
SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2);
753
753
id
754
754
1
755
755
2
756
 
CREATE TABLE t1 (id int default NULL, KEY id (id)) ENGINE=MyISAM;
 
756
CREATE TABLE t1 (id int(11) default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1;
757
757
INSERT INTO t1 values (1),(1);
758
758
UPDATE t2 SET id=(SELECT * FROM t1);
759
759
ERROR 21000: Subquery returns more than 1 row
865
865
Warnings:
866
866
Note    1276    Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
867
867
Note    1249    Select 2 was reduced during optimization
868
 
Note    1003    select (`test`.`t1`.`a` + 1) AS `(select a+1)` from `test`.`t1`
 
868
Note    1003    select ("test"."t1"."a" + 1) AS "(select a+1)" from "test"."t1"
869
869
select (select a+1) from t1;
870
870
(select a+1)
871
871
2.5
 
872
NULL
872
873
4.5
873
 
NULL
874
874
drop table t1;
875
 
CREATE TABLE t1 (a int NOT NULL default '0', PRIMARY KEY  (a));
876
 
CREATE TABLE t2 (a int default '0', INDEX (a));
 
875
CREATE TABLE t1 (a int(11) NOT NULL default '0', PRIMARY KEY  (a));
 
876
CREATE TABLE t2 (a int(11) default '0', INDEX (a));
877
877
INSERT INTO t1 VALUES (1),(2),(3),(4);
878
878
INSERT INTO t2 VALUES (1),(2),(3);
879
879
SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
887
887
1       PRIMARY t1      index   NULL    PRIMARY 4       NULL    4       100.00  Using index
888
888
2       DEPENDENT SUBQUERY      t2      index_subquery  a       a       5       func    2       100.00  Using index
889
889
Warnings:
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`
891
 
CREATE TABLE t3 (a int default '0');
 
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"
 
891
CREATE TABLE t3 (a int(11) default '0');
892
892
INSERT INTO t3 VALUES (1),(2),(3);
893
893
SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
894
894
a       t1.a in (select t2.a from t2,t3 where t3.a=t2.a)
902
902
2       DEPENDENT SUBQUERY      t2      ref_or_null     a       a       5       func    2       100.00  Using index
903
903
2       DEPENDENT SUBQUERY      t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where; Using join buffer
904
904
Warnings:
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`
 
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"
906
906
drop table t1,t2,t3;
907
 
CREATE TABLE t1 (a int);
 
907
create table t1 (a float);
 
908
select 10.5 IN (SELECT * from t1 LIMIT 1);
 
909
ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
 
910
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
 
911
ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
 
912
drop table t1;
 
913
create table t1 (a int, b int, c varchar(10));
 
914
create table t2 (a int);
 
915
insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c');
 
916
insert into t2 values (1),(2),(NULL);
 
917
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;
 
918
a       (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a')   (select c from t1 where a=t2.a)
 
919
1       1       a
 
920
2       0       b
 
921
NULL    0       NULL
 
922
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;
 
923
a       (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b')   (select c from t1 where a=t2.a)
 
924
1       0       a
 
925
2       1       b
 
926
NULL    NULL    NULL
 
927
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;
 
928
a       (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c')   (select c from t1 where a=t2.a)
 
929
1       0       a
 
930
2       0       b
 
931
NULL    0       NULL
 
932
drop table t1,t2;
 
933
create table t1 (a int, b real, c varchar(10));
 
934
insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');
 
935
select ROW(1, 1, 'a') IN (select a,b,c from t1);
 
936
ROW(1, 1, 'a') IN (select a,b,c from t1)
 
937
1
 
938
select ROW(1, 2, 'a') IN (select a,b,c from t1);
 
939
ROW(1, 2, 'a') IN (select a,b,c from t1)
 
940
0
 
941
select ROW(1, 1, 'a') IN (select b,a,c from t1);
 
942
ROW(1, 1, 'a') IN (select b,a,c from t1)
 
943
1
 
944
select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null);
 
945
ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null)
 
946
1
 
947
select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null);
 
948
ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null)
 
949
0
 
950
select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null);
 
951
ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null)
 
952
1
 
953
select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a');
 
954
ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a')
 
955
1
 
956
select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a');
 
957
ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a')
 
958
0
 
959
select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
 
960
ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a')
 
961
1
 
962
select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
 
963
ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
 
964
drop table t1;
 
965
CREATE TABLE t1 (a int(1));
908
966
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
909
967
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
910
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    1       100.00  
911
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    1       100.00  
912
 
Warnings:
913
 
Note    1003    select (select rand() AS `RAND()` from `test`.`t1`) AS `(SELECT RAND() FROM t1)` from `test`.`t1`
 
968
1       PRIMARY t1      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
 
969
2       SUBQUERY        t1      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
 
970
Warnings:
 
971
Note    1003    select (select rand() AS "RAND()" from "test"."t1") AS "(SELECT RAND() FROM t1)" from "test"."t1"
 
972
EXPLAIN EXTENDED SELECT (SELECT ENCRYPT('test') FROM t1) FROM t1;
 
973
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
974
1       PRIMARY t1      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
 
975
2       SUBQUERY        t1      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
 
976
Warnings:
 
977
Note    1003    select (select encrypt('test') AS "ENCRYPT('test')" from "test"."t1") AS "(SELECT ENCRYPT('test') FROM t1)" from "test"."t1"
914
978
EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1;
915
979
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
916
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    1       100.00  
917
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    1       100.00  
 
980
1       PRIMARY t1      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
 
981
2       SUBQUERY        t1      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
918
982
Warnings:
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`
 
983
Note    1003    select (select benchmark(1,1) AS "BENCHMARK(1,1)" from "test"."t1") AS "(SELECT BENCHMARK(1,1) FROM t1)" from "test"."t1"
920
984
drop table t1;
921
985
CREATE TABLE `t1` (
922
 
`mot` varchar(30) NOT NULL default '',
923
 
`topic` bigint NOT NULL default '0',
 
986
`mot` varchar(30) character set latin1 NOT NULL default '',
 
987
`topic` mediumint(8) unsigned NOT NULL default '0',
924
988
`date` date NOT NULL default '0000-00-00',
925
 
`pseudo` varchar(35) NOT NULL default '',
 
989
`pseudo` varchar(35) character set latin1 NOT NULL default '',
926
990
PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`),
927
991
KEY `pseudo` (`pseudo`,`date`,`topic`),
928
992
KEY `topic` (`topic`)
929
 
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
 
993
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
930
994
CREATE TABLE `t2` (
931
 
`mot` varchar(30) NOT NULL default '',
932
 
`topic` bigint NOT NULL default '0',
 
995
`mot` varchar(30) character set latin1 NOT NULL default '',
 
996
`topic` mediumint(8) unsigned NOT NULL default '0',
933
997
`date` date NOT NULL default '0000-00-00',
934
 
`pseudo` varchar(35) NOT NULL default '',
 
998
`pseudo` varchar(35) character set latin1 NOT NULL default '',
935
999
PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`),
936
1000
KEY `pseudo` (`pseudo`,`date`,`topic`),
937
1001
KEY `topic` (`topic`)
938
 
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
 
1002
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
939
1003
CREATE TABLE `t3` (
940
 
`numeropost` bigint NOT NULL auto_increment,
941
 
`maxnumrep` int NOT NULL default '0',
 
1004
`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
 
1005
`maxnumrep` int(10) unsigned NOT NULL default '0',
942
1006
PRIMARY KEY  (`numeropost`),
943
1007
UNIQUE KEY `maxnumrep` (`maxnumrep`)
944
 
) ENGINE=MyISAM;
 
1008
) ENGINE=MyISAM CHARSET=latin1;
945
1009
INSERT INTO t1 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
946
1010
INSERT INTO t2 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
947
1011
INSERT INTO t3 VALUES (1,1);
965
1029
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT 1)) a;
966
1030
SHOW CREATE TABLE t1;
967
1031
Table   Create Table
968
 
t1      CREATE TABLE `t1` (
969
 
  `a` int NOT NULL,
970
 
  `(SELECT 1)` int NOT NULL
971
 
) ENGINE=InnoDB
 
1032
t1      CREATE TABLE "t1" (
 
1033
  "a" int(1) NOT NULL,
 
1034
  "(SELECT 1)" int(1) NOT NULL
 
1035
) ENGINE=MyISAM DEFAULT CHARSET=latin1
972
1036
drop table t1;
973
1037
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
974
1038
SHOW CREATE TABLE t1;
975
1039
Table   Create Table
976
 
t1      CREATE TABLE `t1` (
977
 
  `a` int NOT NULL,
978
 
  `(SELECT a)` int NOT NULL
979
 
) ENGINE=InnoDB
 
1040
t1      CREATE TABLE "t1" (
 
1041
  "a" int(1) NOT NULL,
 
1042
  "(SELECT a)" int(1) NOT NULL
 
1043
) ENGINE=MyISAM DEFAULT CHARSET=latin1
980
1044
drop table t1;
981
1045
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a;
982
1046
SHOW CREATE TABLE t1;
983
1047
Table   Create Table
984
 
t1      CREATE TABLE `t1` (
985
 
  `a` int NOT NULL,
986
 
  `(SELECT a+0)` int NOT NULL
987
 
) ENGINE=InnoDB
 
1048
t1      CREATE TABLE "t1" (
 
1049
  "a" int(1) NOT NULL,
 
1050
  "(SELECT a+0)" int(3) NOT NULL
 
1051
) ENGINE=MyISAM DEFAULT CHARSET=latin1
988
1052
drop table t1;
989
1053
CREATE TABLE t1 SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a;
990
1054
select * from t1;
992
1056
2
993
1057
SHOW CREATE TABLE t1;
994
1058
Table   Create Table
995
 
t1      CREATE TABLE `t1` (
996
 
  `a` bigint NOT NULL
997
 
) ENGINE=InnoDB
 
1059
t1      CREATE TABLE "t1" (
 
1060
  "a" bigint(20) NOT NULL
 
1061
) ENGINE=MyISAM DEFAULT CHARSET=latin1
998
1062
drop table t1;
999
1063
create table t1 (a int);
1000
1064
insert into t1 values (1), (2), (3);
1005
1069
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    3       100.00  
1006
1070
3       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    3       100.00  
1007
1071
Warnings:
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`
 
1072
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"
1009
1073
drop table t1;
1010
1074
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);
1011
1075
ERROR 42S02: Table 'test.t1' doesn't exist
1012
1076
CREATE TABLE t1 (
1013
 
ID int NOT NULL auto_increment,
 
1077
ID int(11) NOT NULL auto_increment,
1014
1078
name char(35) NOT NULL default '',
1015
1079
t2 char(3) NOT NULL default '',
1016
1080
District char(20) NOT NULL default '',
1017
 
Population int NOT NULL default '0',
 
1081
Population int(11) NOT NULL default '0',
1018
1082
PRIMARY KEY  (ID)
1019
1083
) ENGINE=MyISAM;
1020
1084
INSERT INTO t1 VALUES (130,'Sydney','AUS','New South Wales',3276207);
1026
1090
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
1027
1091
Region char(26) NOT NULL default '',
1028
1092
SurfaceArea float(10,2) NOT NULL default '0.00',
1029
 
IndepYear int default NULL,
1030
 
Population int NOT NULL default '0',
 
1093
IndepYear smallint(6) default NULL,
 
1094
Population int(11) NOT NULL default '0',
1031
1095
LifeExpectancy float(3,1) default NULL,
1032
1096
GNP float(10,2) default NULL,
1033
1097
GNPOld float(10,2) default NULL,
1034
1098
LocalName char(45) NOT NULL default '',
1035
1099
GovernmentForm char(45) NOT NULL default '',
1036
1100
HeadOfState char(60) default NULL,
1037
 
Capital int default NULL,
 
1101
Capital int(11) default NULL,
1038
1102
Code2 char(2) NOT NULL default '',
1039
1103
PRIMARY KEY  (Code)
1040
1104
) ENGINE=MyISAM;
1045
1109
Oceania Sydney  3276207
1046
1110
drop table t1, t2;
1047
1111
CREATE TABLE `t1` (
1048
 
`id` bigint NOT NULL auto_increment,
1049
 
`pseudo` varchar(35) NOT NULL default '',
 
1112
`id` mediumint(8) unsigned NOT NULL auto_increment,
 
1113
`pseudo` varchar(35) character set latin1 NOT NULL default '',
1050
1114
PRIMARY KEY  (`id`),
1051
1115
UNIQUE KEY `pseudo` (`pseudo`)
1052
1116
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
1059
1123
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
1060
1124
2       DEPENDENT SUBQUERY      NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE
1061
1125
Warnings:
1062
 
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)`
 
1126
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)"
1063
1127
INSERT INTO t1 (pseudo) VALUES ('test1');
1064
1128
SELECT 0 IN (SELECT 1 FROM t1 a);
1065
1129
0 IN (SELECT 1 FROM t1 a)
1069
1133
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
1070
1134
2       DEPENDENT SUBQUERY      NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE
1071
1135
Warnings:
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)`
 
1136
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)"
1073
1137
drop table t1;
1074
1138
CREATE TABLE `t1` (
1075
 
`i` int NOT NULL default '0',
 
1139
`i` int(11) NOT NULL default '0',
1076
1140
PRIMARY KEY  (`i`)
1077
 
) ENGINE=MyISAM;
 
1141
) ENGINE=MyISAM CHARSET=latin1;
1078
1142
INSERT INTO t1 VALUES (1);
1079
1143
UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i));
1080
1144
UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i));
1085
1149
3
1086
1150
drop table t1;
1087
1151
CREATE TABLE t1 (
1088
 
id int default NULL
1089
 
) ENGINE=MyISAM;
 
1152
id int(11) default NULL
 
1153
) ENGINE=MyISAM CHARSET=latin1;
1090
1154
INSERT INTO t1 VALUES (1),(1),(2),(2),(1),(3);
1091
1155
CREATE TABLE t2 (
1092
 
id int default NULL,
 
1156
id int(11) default NULL,
1093
1157
name varchar(15) default NULL
1094
 
) ENGINE=MyISAM;
 
1158
) ENGINE=MyISAM CHARSET=latin1;
1095
1159
INSERT INTO t2 VALUES (4,'vita'), (1,'vita'), (2,'vita'), (1,'vita');
1096
1160
update t1, t2 set t2.name='lenka' where t2.id in (select id from t1);
1097
1161
select * from t2;
1111
1175
insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000);
1112
1176
explain extended SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1);
1113
1177
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1114
 
1       PRIMARY t1      ref     salary  salary  5       const   1       100.00  Using where; Using index
 
1178
1       PRIMARY t1      ref     salary  salary  5       const   1       100.00  Using index condition
1115
1179
2       SUBQUERY        NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Select tables optimized away
1116
1180
Warnings:
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`))
 
1181
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"))
1118
1182
drop table t1;
1119
1183
CREATE TABLE t1 (
1120
 
ID int NOT NULL auto_increment,
1121
 
SUB_ID int NOT NULL default '0',
1122
 
REF_ID int default NULL,
1123
 
REF_SUB int default '0',
 
1184
ID int(10) unsigned NOT NULL auto_increment,
 
1185
SUB_ID int(3) unsigned NOT NULL default '0',
 
1186
REF_ID int(10) unsigned default NULL,
 
1187
REF_SUB int(3) unsigned default '0',
1124
1188
PRIMARY KEY (ID,SUB_ID),
1125
1189
UNIQUE KEY t1_PK (ID,SUB_ID),
1126
1190
KEY t1_FK (REF_ID,REF_SUB),
1127
1191
KEY t1_REFID (REF_ID)
1128
 
) ENGINE=MyISAM;
 
1192
) ENGINE=MyISAM CHARSET=cp1251;
1129
1193
INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
1130
1194
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
1131
1195
REF_ID
1144
1208
3       1
1145
1209
drop table t1, t2;
1146
1210
CREATE TABLE `t1` (
1147
 
`id` bigint NOT NULL auto_increment,
 
1211
`id` mediumint(8) unsigned NOT NULL auto_increment,
1148
1212
`pseudo` varchar(35) NOT NULL default '',
1149
1213
`email` varchar(60) NOT NULL default '',
1150
1214
PRIMARY KEY  (`id`),
1151
1215
UNIQUE KEY `email` (`email`),
1152
1216
UNIQUE KEY `pseudo` (`pseudo`)
1153
 
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
 
1217
) ENGINE=MyISAM CHARSET=latin1 PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
1154
1218
INSERT INTO t1 (id,pseudo,email) VALUES (1,'test','test'),(2,'test1','test1');
1155
1219
SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT id*1);
1156
1220
a       b
1174
1238
explain extended select * from t2 where t2.a in (select a from t1);
1175
1239
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1176
1240
1       PRIMARY t2      index   PRIMARY PRIMARY 4       NULL    4       100.00  Using index
1177
 
1       PRIMARY t1      eq_ref  PRIMARY PRIMARY 4       test.t2.a       1       100.00  Using index
 
1241
1       PRIMARY t1      index   PRIMARY PRIMARY 4       NULL    4       75.00   Using where; Using index; Using join buffer
1178
1242
Warnings:
1179
 
Note    1003    select `test`.`t2`.`a` AS `a` from (`test`.`t1`) join `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)
 
1243
Note    1003    select "test"."t2"."a" AS "a" from ("test"."t1") join "test"."t2" where ("test"."t1"."a" = "test"."t2"."a")
1180
1244
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1181
1245
a
1182
1246
2
1186
1250
1       PRIMARY t2      index   PRIMARY PRIMARY 4       NULL    4       100.00  Using index
1187
1251
1       PRIMARY t1      ALL     PRIMARY NULL    NULL    NULL    4       75.00   Using where; Using join buffer
1188
1252
Warnings:
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))
 
1253
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))
1190
1254
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
1191
1255
a
1192
1256
2
1197
1261
1       PRIMARY t1      ALL     PRIMARY NULL    NULL    NULL    4       75.00   Using where; Using join buffer
1198
1262
1       PRIMARY t3      eq_ref  PRIMARY PRIMARY 4       test.t1.b       1       100.00  Using index
1199
1263
Warnings:
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`))
 
1264
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"))
1201
1265
drop table t1, t2, t3;
1202
1266
create table t1 (a int, b int, index a (a,b));
1203
1267
create table t2 (a int, index a (a));
1213
1277
explain extended select * from t2 where t2.a in (select a from t1);
1214
1278
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1215
1279
1       PRIMARY t2      index   a       a       5       NULL    4       100.00  Using index
1216
 
1       PRIMARY t1      ref     a       a       5       test.t2.a       1       100.00  Using index; FirstMatch(t2)
 
1280
1       PRIMARY t1      ref     a       a       5       test.t2.a       101     100.00  Using index; FirstMatch(t2)
1217
1281
Warnings:
1218
 
Note    1003    select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where (`test`.`t1`.`a` = `test`.`t2`.`a`)
 
1282
Note    1003    select "test"."t2"."a" AS "a" from "test"."t2" semi join ("test"."t1") where ("test"."t1"."a" = "test"."t2"."a")
1219
1283
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1220
1284
a
1221
1285
2
1223
1287
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1224
1288
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1225
1289
1       PRIMARY t2      index   a       a       5       NULL    4       100.00  Using index
1226
 
1       PRIMARY t1      ref     a       a       5       test.t2.a       1       100.00  Using where; Using index; FirstMatch(t2)
 
1290
1       PRIMARY t1      ref     a       a       5       test.t2.a       101     100.00  Using where; Using index; FirstMatch(t2)
1227
1291
Warnings:
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))
 
1292
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))
1229
1293
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
1230
1294
a
1231
1295
2
1232
1296
3
1233
1297
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
1234
1298
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1235
 
1       PRIMARY t2      index   a       a       5       NULL    4       100.00  Using index
1236
 
1       PRIMARY t1      ref     a       a       5       test.t2.a       1       100.00  Using index; FirstMatch(t2)
1237
 
1       PRIMARY t3      ref     a       a       5       test.t1.b       1       100.00  Using index; FirstMatch(t2)
 
1299
1       PRIMARY t2      index   a       a       5       NULL    4       100.00  Using index; Start temporary
 
1300
1       PRIMARY t1      ref     a       a       5       test.t2.a       101     100.00  Using index; FirstMatch(t2)
 
1301
1       PRIMARY t3      index   a       a       5       NULL    3       100.00  Using where; Using index; End temporary; Using join buffer
1238
1302
Warnings:
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`))
 
1303
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"))
1240
1304
insert into t1 values (3,31);
1241
1305
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1242
1306
a
1250
1314
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1251
1315
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1252
1316
1       PRIMARY t2      index   a       a       5       NULL    4       100.00  Using index
1253
 
1       PRIMARY t1      ref     a       a       5       test.t2.a       1       100.00  Using where; Using index; FirstMatch(t2)
 
1317
1       PRIMARY t1      ref     a       a       5       test.t2.a       101     100.00  Using where; Using index; FirstMatch(t2)
1254
1318
Warnings:
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))
 
1319
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))
1256
1320
drop table t1, t2, t3;
1257
1321
create table t1 (a int, b int);
1258
1322
create table t2 (a int, b int);
1281
1345
update t1 set  s1 = s1 + 1 where 1 = (select x.s1 as A from t2 WHERE t2.s1 > t1.s1 order by A);
1282
1346
ERROR 42S22: Unknown column 'x.s1' in 'field list'
1283
1347
DROP TABLE t1, t2;
 
1348
CREATE TABLE t1 (s1 CHAR(5) COLLATE latin1_german1_ci,
 
1349
s2 CHAR(5) COLLATE latin1_swedish_ci);
 
1350
INSERT INTO t1 VALUES ('z','?');
 
1351
select * from t1 where s1 > (select max(s2) from t1);
 
1352
ERROR HY000: Illegal mix of collations (latin1_german1_ci,IMPLICIT) and (latin1_swedish_ci,IMPLICIT) for operation '>'
 
1353
select * from t1 where s1 > any (select max(s2) from t1);
 
1354
ERROR HY000: Illegal mix of collations (latin1_german1_ci,IMPLICIT) and (latin1_swedish_ci,IMPLICIT) for operation '>'
 
1355
drop table t1;
1284
1356
create table t1(toid int,rd int);
1285
1357
create table t2(userid int,pmnew int,pmtotal int);
1286
1358
insert into t2 values(1,0,0),(2,0,0);
1299
1371
tttt
1300
1372
explain extended (select * from t1);
1301
1373
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1302
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    1       100.00  
 
1374
1       SIMPLE  t1      system  NULL    NULL    NULL    NULL    1       100.00  
1303
1375
Warnings:
1304
 
Note    1003    (select `test`.`t1`.`s1` AS `s1` from `test`.`t1`)
 
1376
Note    1003    (select 'tttt' AS "s1" from "test"."t1")
1305
1377
(select * from t1);
1306
1378
s1
1307
1379
tttt
1332
1404
a3      1
1333
1405
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
1334
1406
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1335
 
1       PRIMARY t1      index   NULL    s1      23      NULL    3       100.00  Using index
1336
 
2       DEPENDENT SUBQUERY      t2      index_subquery  s1      s1      23      func    2       100.00  Using index; Full scan on NULL key
 
1407
1       PRIMARY t1      index   NULL    s1      6       NULL    3       100.00  Using index
 
1408
2       DEPENDENT SUBQUERY      t2      index_subquery  s1      s1      6       func    2       100.00  Using index; Full scan on NULL key
1337
1409
Warnings:
1338
 
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 having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
 
1410
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 having trigcond(<is_not_null_test>("test"."t2"."s1"))))))) AS "s1 NOT IN (SELECT s1 FROM t2)" from "test"."t1"
1339
1411
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
1340
1412
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1341
 
1       PRIMARY t1      index   NULL    s1      23      NULL    3       100.00  Using index
1342
 
2       DEPENDENT SUBQUERY      t2      index_subquery  s1      s1      23      func    2       100.00  Using index; Full scan on NULL key
 
1413
1       PRIMARY t1      index   NULL    s1      6       NULL    3       100.00  Using index
 
1414
2       DEPENDENT SUBQUERY      t2      index_subquery  s1      s1      6       func    2       100.00  Using index; Full scan on NULL key
1343
1415
Warnings:
1344
 
Note    1003    select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
 
1416
Note    1003    select "test"."t1"."s1" AS "s1",<in_optimizer>("test"."t1"."s1",<exists>(<index_lookup>(<cache>("test"."t1"."s1") in t2 on s1 checking NULL having trigcond(<is_not_null_test>("test"."t2"."s1"))))) AS "s1 = ANY (SELECT s1 FROM t2)" from "test"."t1"
1345
1417
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
1346
1418
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1347
 
1       PRIMARY t1      index   NULL    s1      23      NULL    3       100.00  Using index
1348
 
2       DEPENDENT SUBQUERY      t2      index_subquery  s1      s1      23      func    2       100.00  Using index; Full scan on NULL key
 
1419
1       PRIMARY t1      index   NULL    s1      6       NULL    3       100.00  Using index
 
1420
2       DEPENDENT SUBQUERY      t2      index_subquery  s1      s1      6       func    2       100.00  Using index; Full scan on NULL key
1349
1421
Warnings:
1350
 
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 having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
 
1422
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 having trigcond(<is_not_null_test>("test"."t2"."s1"))))))) AS "s1 <> ALL (SELECT s1 FROM t2)" from "test"."t1"
1351
1423
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
1352
1424
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1353
 
1       PRIMARY t1      index   NULL    s1      23      NULL    3       100.00  Using index
1354
 
2       DEPENDENT SUBQUERY      t2      index_subquery  s1      s1      23      func    2       100.00  Using index; Using where; Full scan on NULL key
 
1425
1       PRIMARY t1      index   NULL    s1      6       NULL    3       100.00  Using index
 
1426
2       DEPENDENT SUBQUERY      t2      index_subquery  s1      s1      6       func    2       100.00  Using index; Using where; Full scan on NULL key
1355
1427
Warnings:
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`
 
1428
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"
1357
1429
drop table t1,t2;
1358
1430
create table t2 (a int, b int);
1359
1431
create table t3 (a int);
1366
1438
explain extended select * from t3 where a >= all (select b from t2);
1367
1439
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1368
1440
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
1369
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    1       100.00  
 
1441
2       SUBQUERY        t2      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
1370
1442
Warnings:
1371
 
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>((`test`.`t3`.`a` < (select max(`test`.`t2`.`b`) from `test`.`t2`)))
 
1443
Note    1003    select "test"."t3"."a" AS "a" from "test"."t3" where <not>(("test"."t3"."a" < (select max('0') from "test"."t2")))
1372
1444
select * from t3 where a >= some (select b from t2);
1373
1445
a
1374
1446
explain extended select * from t3 where a >= some (select b from t2);
1375
1447
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1376
1448
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
1377
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    1       100.00  
 
1449
2       SUBQUERY        t2      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
1378
1450
Warnings:
1379
 
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>((`test`.`t3`.`a` >= (select min(`test`.`t2`.`b`) from `test`.`t2`)))
 
1451
Note    1003    select "test"."t3"."a" AS "a" from "test"."t3" where <nop>(("test"."t3"."a" >= (select min('0') from "test"."t2")))
1380
1452
select * from t3 where a >= all (select b from t2 group by 1);
1381
1453
a
1382
1454
6
1385
1457
explain extended select * from t3 where a >= all (select b from t2 group by 1);
1386
1458
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1387
1459
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
1388
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    1       100.00  Using temporary; Using filesort
 
1460
2       SUBQUERY        t2      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
1389
1461
Warnings:
1390
 
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>((`test`.`t3`.`a` < <max>(select `test`.`t2`.`b` AS `b` from `test`.`t2` group by 1)))
 
1462
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)))
1391
1463
select * from t3 where a >= some (select b from t2 group by 1);
1392
1464
a
1393
1465
explain extended select * from t3 where a >= some (select b from t2 group by 1);
1394
1466
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1395
1467
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
1396
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    1       100.00  Using temporary; Using filesort
 
1468
2       SUBQUERY        t2      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
1397
1469
Warnings:
1398
 
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>((`test`.`t3`.`a` >= <min>(select `test`.`t2`.`b` AS `b` from `test`.`t2` group by 1)))
 
1470
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)))
1399
1471
select * from t3 where NULL >= any (select b from t2);
1400
1472
a
1401
1473
explain extended select * from t3 where NULL >= any (select b from t2);
1402
1474
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1403
1475
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE
1404
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    1       100.00  
 
1476
2       SUBQUERY        t2      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
1405
1477
Warnings:
1406
 
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
 
1478
Note    1003    select "test"."t3"."a" AS "a" from "test"."t3" where 0
1407
1479
select * from t3 where NULL >= any (select b from t2 group by 1);
1408
1480
a
1409
1481
explain extended select * from t3 where NULL >= any (select b from t2 group by 1);
1410
1482
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1411
1483
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE
1412
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    1       100.00  Using temporary; Using filesort
 
1484
2       SUBQUERY        t2      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
1413
1485
Warnings:
1414
 
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
 
1486
Note    1003    select "test"."t3"."a" AS "a" from "test"."t3" where 0
1415
1487
select * from t3 where NULL >= some (select b from t2);
1416
1488
a
1417
1489
explain extended select * from t3 where NULL >= some (select b from t2);
1418
1490
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1419
1491
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE
1420
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    1       100.00  
 
1492
2       SUBQUERY        t2      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
1421
1493
Warnings:
1422
 
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
 
1494
Note    1003    select "test"."t3"."a" AS "a" from "test"."t3" where 0
1423
1495
select * from t3 where NULL >= some (select b from t2 group by 1);
1424
1496
a
1425
1497
explain extended select * from t3 where NULL >= some (select b from t2 group by 1);
1426
1498
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1427
1499
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE
1428
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    1       100.00  Using temporary; Using filesort
 
1500
2       SUBQUERY        t2      system  NULL    NULL    NULL    NULL    0       0.00    const row not found
1429
1501
Warnings:
1430
 
Note    1003    select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
 
1502
Note    1003    select "test"."t3"."a" AS "a" from "test"."t3" where 0
1431
1503
insert into t2 values (2,2), (2,1), (3,3), (3,1);
1432
1504
select * from t3 where a > all (select max(b) from t2 group by a);
1433
1505
a
1438
1510
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
1439
1511
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    4       100.00  Using temporary; Using filesort
1440
1512
Warnings:
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`)))
 
1513
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")))
1442
1514
drop table t2, t3;
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 NOT NULL default '0000-00-00 00:00:00', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY  (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 ;
 
1515
CREATE TABLE `t1` ( `id` mediumint(9) NOT NULL auto_increment, `taskid` bigint(20) NOT NULL default '0', `dbid` int(11) NOT NULL default '0', `create_date` datetime NOT NULL default '0000-00-00 00:00:00', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY  (`id`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=3 ;
1444
1516
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());
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;
 
1517
CREATE TABLE `t2` (`db_id` int(11) NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` smallint(6) NOT NULL default '0',`secondary_uid` smallint(6) NOT NULL default '0',PRIMARY KEY  (`db_id`),UNIQUE KEY `name_2` (`name`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2147483647;
1446
1518
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);
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 ;
 
1519
CREATE TABLE `t3` (`taskgenid` mediumint(9) NOT NULL auto_increment,`dbid` int(11) NOT NULL default '0',`taskid` int(11) NOT NULL default '0',`mon` tinyint(4) NOT NULL default '1',`tues` tinyint(4) NOT NULL default '1',`wed` tinyint(4) NOT NULL default '1',`thur` tinyint(4) NOT NULL default '1',`fri` tinyint(4) NOT NULL default '1',`sat` tinyint(4) NOT NULL default '0',`sun` tinyint(4) NOT NULL default '0',`how_often` smallint(6) NOT NULL default '1',`userid` smallint(6) NOT NULL default '0',`active` tinyint(4) NOT NULL default '1',PRIMARY KEY  (`taskgenid`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2 ;
1448
1520
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);
1449
 
CREATE TABLE `t4` (`task_id` int NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM;
 
1521
CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
1450
1522
INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
1451
1523
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;
1452
1524
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')
1458
1530
-1      Valid
1459
1531
-1      Valid 2
1460
1532
drop table t1,t2,t3,t4;
1461
 
CREATE TABLE t1 (id int default NULL) ENGINE=MyISAM;
 
1533
CREATE TABLE t1 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1;
1462
1534
INSERT INTO t1 VALUES (1),(5);
1463
 
CREATE TABLE t2 (id int default NULL) ENGINE=MyISAM;
 
1535
CREATE TABLE t2 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1;
1464
1536
INSERT INTO t2 VALUES (2),(6);
1465
1537
select * from t1 where (1,2,6) in (select * from t2);
1466
1538
ERROR 21000: Operand should contain 3 column(s)
1475
1547
e
1476
1548
explain extended select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
1477
1549
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1478
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    1       100.00  
1479
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    1       100.00  
1480
 
3       UNION   t1      ALL     NULL    NULL    NULL    NULL    1       100.00  
 
1550
1       PRIMARY t1      system  NULL    NULL    NULL    NULL    1       100.00  
 
1551
2       SUBQUERY        t1      system  NULL    NULL    NULL    NULL    1       100.00  
 
1552
3       UNION   t1      system  NULL    NULL    NULL    NULL    1       100.00  
1481
1553
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
1482
1554
Warnings:
1483
 
Note    1003    select `test`.`t1`.`s1` AS `s1` from `test`.`t1` where 1
 
1555
Note    1003    select 'e' AS "s1" from "test"."t1" where 1
1484
1556
drop table t1;
1485
 
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM;
 
1557
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
1486
1558
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
1487
 
CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM;
 
1559
CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM CHARSET=latin1;
1488
1560
INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6');
1489
1561
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;
1490
1562
phone   code
1509
1581
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
1510
1582
COLC
1511
1583
DROP TABLE t1, t2;
1512
 
CREATE TABLE t1 (a int);
 
1584
CREATE TABLE t1 (a int(1));
1513
1585
INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5);
1514
1586
SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100;
1515
1587
(SELECT a)
1520
1592
5
1521
1593
DROP TABLE t1;
1522
1594
CREATE TABLE `t1` (
1523
 
`id` int NOT NULL auto_increment,
1524
 
`id_cns` int NOT NULL default '0',
 
1595
`id` int(11) NOT NULL auto_increment,
 
1596
`id_cns` tinyint(3) unsigned NOT NULL default '0',
1525
1597
`tipo` enum('','UNO','DUE') NOT NULL default '',
1526
 
`anno_dep` int NOT NULL default '0',
1527
 
`particolare` bigint NOT NULL default '0',
1528
 
`generale` bigint NOT NULL default '0',
1529
 
`bis` int NOT NULL default '0',
 
1598
`anno_dep` smallint(4) unsigned zerofill NOT NULL default '0000',
 
1599
`particolare` mediumint(8) unsigned NOT NULL default '0',
 
1600
`generale` mediumint(8) unsigned NOT NULL default '0',
 
1601
`bis` tinyint(3) unsigned NOT NULL default '0',
1530
1602
PRIMARY KEY  (`id`),
1531
1603
UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`),
1532
1604
UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`)
1533
1605
);
1534
1606
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);
1535
1607
CREATE TABLE `t2` (
1536
 
`id` int NOT NULL auto_increment,
1537
 
`max_anno_dep` int NOT NULL default '0',
 
1608
`id` tinyint(3) unsigned NOT NULL auto_increment,
 
1609
`max_anno_dep` smallint(6) unsigned NOT NULL default '0',
1538
1610
PRIMARY KEY  (`id`)
1539
1611
);
1540
1612
INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990);
1590
1662
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    12      100.00  Using where
1591
1663
2       DEPENDENT SUBQUERY      t1      unique_subquery PRIMARY PRIMARY 4       func    1       100.00  Using index; Using where
1592
1664
Warnings:
1593
 
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`)))))))
 
1665
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")))))))
1594
1666
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);
1595
1667
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1596
1668
1       PRIMARY tt      ALL     NULL    NULL    NULL    NULL    12      100.00  Using where
1597
1669
2       DEPENDENT SUBQUERY      t1      eq_ref  PRIMARY PRIMARY 4       test.tt.id      1       100.00  Using where; Using index
1598
1670
Warnings:
1599
1671
Note    1276    Field or reference 'test.tt.id' of SELECT #2 was resolved in SELECT #1
1600
 
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))))
 
1672
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))))
1601
1673
insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
1602
1674
create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
1603
1675
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');
1621
1693
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1622
1694
1       SIMPLE  a       ALL     NULL    NULL    NULL    NULL    14      100.00  
1623
1695
1       SIMPLE  b       eq_ref  PRIMARY PRIMARY 4       test.a.id       2       100.00  
1624
 
1       SIMPLE  c       eq_ref  PRIMARY PRIMARY 4       func    1       100.00  Using where
 
1696
1       SIMPLE  c       eq_ref  PRIMARY PRIMARY 4       func    1       100.00  Using index condition
1625
1697
Warnings:
1626
 
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`)
 
1698
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")
1627
1699
drop table t1,t2;
1628
1700
create table t1 (a int);
1629
1701
insert into t1 values (1);
1630
1702
explain select benchmark(1000, (select a from t1 where a=rand()));
1631
1703
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1632
1704
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
1633
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    1       Using where
 
1705
2       SUBQUERY        t1      system  NULL    NULL    NULL    NULL    1       
1634
1706
drop table t1;
1635
1707
create table t1(id int);
1636
1708
create table t2(id int);
2133
2205
2       DEPENDENT SUBQUERY      t1      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
2134
2206
Warnings:
2135
2207
Note    1276    Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
2136
 
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`))
 
2208
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"))
2137
2209
drop table t1;
2138
2210
CREATE TABLE t1 (t1_a int);
2139
2211
INSERT INTO t1 VALUES (1);
2144
2216
t1_a    t2_a    t2_b
2145
2217
1       1       2
2146
2218
DROP TABLE t1, t2;
2147
 
CREATE TABLE t1 (id int default NULL,name varchar(10) default NULL);
 
2219
CREATE TABLE t1 (id int(11) default NULL,name varchar(10) default NULL);
2148
2220
INSERT INTO t1 VALUES (1,'Tim'),(2,'Rebecca'),(3,NULL);
2149
 
CREATE TABLE t2 (id int default NULL, pet varchar(10) default NULL);
 
2221
CREATE TABLE t2 (id int(11) default NULL, pet varchar(10) default NULL);
2150
2222
INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix');
2151
2223
SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id;
2152
2224
id      name    id      pet
2154
2226
2       Rebecca 2       Spot
2155
2227
3       NULL    3       Felix
2156
2228
drop table t1,t2;
2157
 
CREATE TABLE `t1` ( `a` int default NULL) ENGINE=MyISAM;
 
2229
CREATE TABLE `t1` ( `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
2158
2230
insert into t1 values (1);
2159
 
CREATE TABLE `t2` ( `b` int default NULL, `a` int default NULL) ENGINE=MyISAM;
 
2231
CREATE TABLE `t2` ( `b` int(11) default NULL, `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
2160
2232
insert into t2 values (1,2);
2161
2233
select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1);
2162
2234
a       C
2163
2235
1       1
2164
2236
drop table t1,t2;
2165
 
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);
 
2237
CREATE TABLE t1(`IZAVORGANG_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`KUERZEL` VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_bin,`IZAANALYSEART_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`IZAPMKZ_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin);
2166
2238
CREATE INDEX AK01IZAVORGANG ON t1(izaAnalyseart_id,Kuerzel);
2167
2239
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000001','601','D0000000001','I0000000001');
2168
2240
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000002','602','D0000000001','I0000000001');
2172
2244
IZAVORGANG_ID
2173
2245
D0000000001
2174
2246
drop table t1;
2175
 
CREATE TABLE `t1` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
2176
 
CREATE TABLE `t2` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
 
2247
CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
 
2248
CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
2177
2249
insert into t1 values (1,1),(1,2),(2,1),(2,2);
2178
2250
insert into t2 values (1,2),(2,2);
2179
2251
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
2231
2303
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;
2232
2304
(select b.x from t1 as b where b.x=a.x)
2233
2305
drop table t1;
2234
 
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`));
 
2306
CREATE TABLE `t1` ( `master` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `slave` int(10) unsigned NOT NULL default '0', `access` int(10) unsigned NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`));
2235
2307
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);
2236
 
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`)) ;
 
2308
CREATE TABLE `t2` ( `id` int(10) unsigned NOT NULL default '0', `pid` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `level` tinyint(4) unsigned NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY  (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ;
2237
2309
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');
2238
2310
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;
2239
2311
ERROR 42S22: Unknown column 'b.sc' in 'field list'
2275
2347
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
2276
2348
Region char(26) NOT NULL default '',
2277
2349
SurfaceArea float(10,2) NOT NULL default '0.00',
2278
 
IndepYear int default NULL,
2279
 
Population int NOT NULL default '0',
 
2350
IndepYear smallint(6) default NULL,
 
2351
Population int(11) NOT NULL default '0',
2280
2352
LifeExpectancy float(3,1) default NULL,
2281
2353
GNP float(10,2) default NULL,
2282
2354
GNPOld float(10,2) default NULL,
2283
2355
LocalName char(45) NOT NULL default '',
2284
2356
GovernmentForm char(45) NOT NULL default '',
2285
2357
HeadOfState char(60) default NULL,
2286
 
Capital int default NULL,
 
2358
Capital int(11) default NULL,
2287
2359
Code2 char(2) NOT NULL default ''
2288
2360
) ENGINE=MyISAM;
2289
2361
INSERT INTO t1 VALUES ('XXX','Xxxxx','Oceania','Xxxxxx',26.00,0,0,0,0,0,'Xxxxx','Xxxxx','Xxxxx',NULL,'XX');
2339
2411
ERROR 42S22: Reference 'xx' not supported (forward reference in item list)
2340
2412
drop table t1;
2341
2413
CREATE TABLE t1 (
2342
 
categoryId int NOT NULL,
2343
 
courseId int NOT NULL,
 
2414
categoryId int(11) NOT NULL,
 
2415
courseId int(11) NOT NULL,
2344
2416
startDate datetime NOT NULL,
2345
2417
endDate datetime NOT NULL,
2346
2418
createDate datetime NOT NULL,
2357
2429
(3,51,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''),
2358
2430
(5,12,'2004-02-18','2010-01-01','2004-02-18','2004-02-18','');
2359
2431
CREATE TABLE t2 (
2360
 
userId int NOT NULL,
2361
 
courseId int NOT NULL,
 
2432
userId int(11) NOT NULL,
 
2433
courseId int(11) NOT NULL,
2362
2434
date datetime NOT NULL
2363
2435
);
2364
2436
INSERT INTO t2 VALUES (5141,71,'2003-11-18'),
2368
2440
(5141,87,'2004-10-21'),(5141,88,'2004-10-21'),
2369
2441
(5141,89,'2004-10-22'),(5141,51,'2004-10-26');
2370
2442
CREATE TABLE t3 (
2371
 
groupId int NOT NULL,
2372
 
parentId int NOT NULL,
 
2443
groupId int(11) NOT NULL,
 
2444
parentId int(11) NOT NULL,
2373
2445
startDate datetime NOT NULL,
2374
2446
endDate datetime NOT NULL,
2375
2447
createDate datetime NOT NULL,
2376
2448
modifyDate timestamp NOT NULL,
2377
 
ordering int
 
2449
ordering int(11)
2378
2450
);
2379
2451
INSERT INTO t3 VALUES (12,9,'1000-01-01','3999-12-31','2004-01-29','2004-01-29',NULL);
2380
2452
CREATE TABLE t4 (
2381
 
id int NOT NULL,
2382
 
groupTypeId int NOT NULL,
 
2453
id int(11) NOT NULL,
 
2454
groupTypeId int(11) NOT NULL,
2383
2455
groupKey varchar(50) NOT NULL,
2384
2456
name text,
2385
 
ordering int,
 
2457
ordering int(11),
2386
2458
description text,
2387
2459
createDate datetime NOT NULL,
2388
2460
modifyDate timestamp NOT NULL
2390
2462
INSERT INTO t4 VALUES (9,5,'stationer','stationer',0,'Stationer','2004-01-29','2004-01-29'),
2391
2463
(12,5,'group2','group2',0,'group2','2004-01-29','2004-01-29');
2392
2464
CREATE TABLE t5 (
2393
 
userId int NOT NULL,
2394
 
groupId int NOT NULL,
 
2465
userId int(11) NOT NULL,
 
2466
groupId int(11) NOT NULL,
2395
2467
createDate datetime NOT NULL,
2396
2468
modifyDate timestamp NOT NULL
2397
2469
);
2461
2533
select (select * from t1) = (1,2,3);
2462
2534
ERROR 21000: Operand should contain 2 column(s)
2463
2535
drop table t1;
 
2536
CREATE TABLE `t1` (
 
2537
`itemid` bigint(20) unsigned NOT NULL auto_increment,
 
2538
`sessionid` bigint(20) unsigned default NULL,
 
2539
`time` int(10) unsigned NOT NULL default '0',
 
2540
`type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT
 
2541
NULL default '',
 
2542
`data` text collate latin1_general_ci NOT NULL,
 
2543
PRIMARY KEY  (`itemid`)
 
2544
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
2545
INSERT INTO `t1` VALUES (1, 1, 1, 'D', '');
 
2546
CREATE TABLE `t2` (
 
2547
`sessionid` bigint(20) unsigned NOT NULL auto_increment,
 
2548
`pid` int(10) unsigned NOT NULL default '0',
 
2549
`date` int(10) unsigned NOT NULL default '0',
 
2550
`ip` varchar(15) collate latin1_general_ci NOT NULL default '',
 
2551
PRIMARY KEY  (`sessionid`)
 
2552
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
2553
INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
 
2554
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;
 
2555
ip      count( e.itemid )
 
2556
10.10.10.1      1
 
2557
drop tables t1,t2;
2464
2558
create table t1 (fld enum('0','1'));
2465
2559
insert into t1 values ('1');
2466
2560
select * from (select max(fld) from t1) as foo;
2537
2631
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    8       100.00  
2538
2632
2       DEPENDENT SUBQUERY      t2      ALL     NULL    NULL    NULL    NULL    9       100.00  Using where
2539
2633
Warnings:
2540
 
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`
 
2634
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"
2541
2635
explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
2542
2636
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
2543
2637
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    8       100.00  Start temporary
2544
2638
1       PRIMARY t2      ALL     NULL    NULL    NULL    NULL    9       100.00  Using where; End temporary; Using join buffer
2545
2639
Warnings:
2546
 
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'))
 
2640
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'))
2547
2641
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;
2548
2642
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
2549
2643
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    8       100.00  
2550
2644
2       DEPENDENT SUBQUERY      t2      ALL     NULL    NULL    NULL    NULL    9       100.00  Using where; Using temporary; Using filesort
2551
2645
Warnings:
2552
 
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`
 
2646
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"
2553
2647
DROP TABLE t1,t2;
2554
2648
CREATE TABLE t1 (a char(5), b char(5));
2555
2649
INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
2618
2712
drop table t1;
2619
2713
create table t1 (
2620
2714
retailerID varchar(8) NOT NULL,
2621
 
statusID   int NOT NULL,
 
2715
statusID   int(10) unsigned NOT NULL,
2622
2716
changed    datetime NOT NULL,
2623
2717
UNIQUE KEY retailerID (retailerID, statusID, changed)
2624
2718
);
2646
2740
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' 
2647
2741
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
2648
2742
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2649
 
1       PRIMARY t1      const   PRIMARY PRIMARY 4       const   1       Using index
 
2743
1       PRIMARY t1      system  PRIMARY NULL    NULL    NULL    1       
2650
2744
1       PRIMARY r       const   PRIMARY PRIMARY 4       const   1       
2651
 
2       DEPENDENT SUBQUERY      t2      ref     b       b       5               1       Using where; Using index
 
2745
2       DEPENDENT SUBQUERY      t2      range   b       b       40      NULL    2       Using index condition
2652
2746
SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r 
2653
2747
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' 
2654
2748
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
2658
2752
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' 
2659
2753
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
2660
2754
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2661
 
1       PRIMARY t1      const   PRIMARY PRIMARY 4       const   1       Using index
 
2755
1       PRIMARY t1      system  PRIMARY NULL    NULL    NULL    1       
2662
2756
1       PRIMARY r       const   PRIMARY PRIMARY 4       const   1       
2663
 
2       DEPENDENT SUBQUERY      t2      ref     b       b       5               1       Using where; Using index
 
2757
2       DEPENDENT SUBQUERY      t2      range   b       b       40      NULL    2       Using index condition; Using MRR
2664
2758
SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r 
2665
2759
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' 
2666
2760
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
2725
2819
FROM t1 WHERE a > '2000-01-01';
2726
2820
SHOW CREATE TABLE t2;
2727
2821
Table   Create Table
2728
 
t2      CREATE TABLE `t2` (
2729
 
  `sub_a` datetime
2730
 
) ENGINE=InnoDB
 
2822
t2      CREATE TABLE "t2" (
 
2823
  "sub_a" datetime
 
2824
) ENGINE=MyISAM DEFAULT CHARSET=latin1
2731
2825
CREATE TABLE t3 AS (SELECT a FROM t1 WHERE a < '2000-01-01') UNION (SELECT a FROM t1 WHERE a > '2000-01-01');
2732
2826
SHOW CREATE TABLE t3;
2733
2827
Table   Create Table
2734
 
t3      CREATE TABLE `t3` (
2735
 
  `a` datetime
2736
 
) ENGINE=InnoDB
 
2828
t3      CREATE TABLE "t3" (
 
2829
  "a" datetime
 
2830
) ENGINE=MyISAM DEFAULT CHARSET=latin1
2737
2831
DROP TABLE t1,t2,t3;
2738
2832
CREATE TABLE t1 (a int);
2739
2833
INSERT INTO t1 VALUES (2), (4), (1), (3);
2826
2920
1.1
2827
2921
drop table t1;
2828
2922
CREATE TABLE t1 (
2829
 
grp int default NULL,
 
2923
grp int(11) default NULL,
2830
2924
a decimal(10,2) default NULL);
2831
2925
insert into t1 values (1, 1), (2, 2), (2, 3), (3, 4), (3, 5), (3, 6), (NULL, NULL);
2832
2926
select * from t1;
2880
2974
2       NULL
2881
2975
3       NULL
2882
2976
DROP TABLE t1,t2,t3;
 
2977
CREATE TABLE `t1` (
 
2978
`itemid` bigint(20) unsigned NOT NULL auto_increment,
 
2979
`sessionid` bigint(20) unsigned default NULL,
 
2980
`time` int(10) unsigned NOT NULL default '0',
 
2981
`type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT
 
2982
NULL default '',
 
2983
`data` text collate latin1_general_ci NOT NULL,
 
2984
PRIMARY KEY  (`itemid`)
 
2985
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
2986
INSERT INTO `t1` VALUES (1, 1, 1, 'D', '');
 
2987
CREATE TABLE `t2` (
 
2988
`sessionid` bigint(20) unsigned NOT NULL auto_increment,
 
2989
`pid` int(10) unsigned NOT NULL default '0',
 
2990
`date` int(10) unsigned NOT NULL default '0',
 
2991
`ip` varchar(15) collate latin1_general_ci NOT NULL default '',
 
2992
PRIMARY KEY  (`sessionid`)
 
2993
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
2994
INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
 
2995
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;
 
2996
ip      count( e.itemid )
 
2997
10.10.10.1      1
 
2998
drop tables t1,t2;
2883
2999
CREATE TABLE t1 (EMPNUM   CHAR(3));
2884
3000
CREATE TABLE t2 (EMPNUM   CHAR(3) );
2885
3001
INSERT INTO t1 VALUES ('E1'),('E2');
3087
3203
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
3088
3204
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
3089
3205
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    9       Using where
3090
 
2       SUBQUERY        t1      index   NULL    a       23      NULL    9       
 
3206
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    9       Using temporary; Using filesort
3091
3207
DROP TABLE t1;
3092
3208
create table t1( f1 int,f2 int);
3093
3209
insert into t1 values (1,1),(2,2);
3108
3224
min(i)
3109
3225
1
3110
3226
drop table t1;
3111
 
CREATE TABLE t1 (i BIGINT);
3112
 
INSERT INTO t1 VALUES (10000000000000000);
 
3227
CREATE TABLE t1 (i BIGINT UNSIGNED);
 
3228
INSERT INTO t1 VALUES (10000000000000000000);
3113
3229
INSERT INTO t1 VALUES (1);
3114
 
CREATE TABLE t2 (i BIGINT);
3115
 
INSERT INTO t2 VALUES (10000000000000000);
 
3230
CREATE TABLE t2 (i BIGINT UNSIGNED);
 
3231
INSERT INTO t2 VALUES (10000000000000000000);
3116
3232
INSERT INTO t2 VALUES (1);
3117
3233
/* simple test */
3118
3234
SELECT t1.i FROM t1 JOIN t2 ON t1.i = t2.i;
3119
3235
i
3120
 
10000000000000000
 
3236
10000000000000000000
3121
3237
1
3122
3238
/* subquery test */
3123
3239
SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2);
3124
3240
i
3125
 
10000000000000000
 
3241
10000000000000000000
3126
3242
/* subquery test with cast*/
3127
 
SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2);
 
3243
SELECT t1.i FROM t1 WHERE t1.i = CAST((SELECT MAX(i) FROM t2) AS UNSIGNED);
3128
3244
i
3129
 
10000000000000000
 
3245
10000000000000000000
3130
3246
DROP TABLE t1;
3131
3247
DROP TABLE t2;
3132
3248
CREATE TABLE t1 (
3133
 
id bigint NOT NULL auto_increment,
 
3249
id bigint(20) unsigned NOT NULL auto_increment,
3134
3250
name varchar(255) NOT NULL,
3135
3251
PRIMARY KEY  (id)
3136
3252
);
3137
3253
INSERT INTO t1 VALUES
3138
3254
(1, 'Balazs'), (2, 'Joe'), (3, 'Frank');
3139
3255
CREATE TABLE t2 (
3140
 
id bigint NOT NULL auto_increment,
3141
 
mid bigint NOT NULL,
 
3256
id bigint(20) unsigned NOT NULL auto_increment,
 
3257
mid bigint(20) unsigned NOT NULL,
3142
3258
date date NOT NULL,
3143
3259
PRIMARY KEY  (id)
3144
3260
);
3175
3291
3       Frank   2006-04-13      NULL
3176
3292
DROP TABLE t1,t2;
3177
3293
CREATE TABLE t1 (
3178
 
i1 int NOT NULL default '0',
3179
 
i2 int NOT NULL default '0',
 
3294
i1 int(11) NOT NULL default '0',
 
3295
i2 int(11) NOT NULL default '0',
3180
3296
t datetime NOT NULL default '0000-00-00 00:00:00',
3181
3297
PRIMARY KEY  (i1,i2,t)
3182
3298
);
3188
3304
(24,2,'2005-03-03 16:31:30'),(24,2,'2005-05-27 12:37:02'),
3189
3305
(24,2,'2005-05-27 12:40:06');
3190
3306
CREATE TABLE t2 (
3191
 
i1 int NOT NULL default '0',
3192
 
i2 int NOT NULL default '0',
 
3307
i1 int(11) NOT NULL default '0',
 
3308
i2 int(11) NOT NULL default '0',
3193
3309
t datetime default NULL,
3194
3310
PRIMARY KEY  (i1)
3195
3311
);
3200
3316
WHERE t1.t < t2.t  AND t1.i2=1 AND t2.i1=t1.i1
3201
3317
ORDER BY t1.t DESC LIMIT 1);
3202
3318
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
3203
 
1       PRIMARY t2      ALL     NULL    NULL    NULL    NULL    1       
3204
 
1       PRIMARY t1      index   NULL    PRIMARY 16      NULL    11      Using where; Using index; Using join buffer
3205
 
2       DEPENDENT SUBQUERY      t1      ref     PRIMARY PRIMARY 8       test.t2.i1,const        5       Using where; Using index; Using filesort
 
3319
1       PRIMARY t2      system  NULL    NULL    NULL    NULL    1       
 
3320
1       PRIMARY t1      index   NULL    PRIMARY 16      NULL    11      Using where; Using index
 
3321
2       DEPENDENT SUBQUERY      t1      range   PRIMARY PRIMARY 16      NULL    5       Using where; Using index
3206
3322
SELECT * FROM t1,t2
3207
3323
WHERE t1.t = (SELECT t1.t FROM t1 
3208
3324
WHERE t1.t < t2.t  AND t1.i2=1 AND t2.i1=t1.i1
3229
3345
explain select * from t1 where not exists 
3230
3346
((select t11.i from t1 t11) union (select t12.i from t1 t12));
3231
3347
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
3232
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    1       
3233
 
2       SUBQUERY        t11     ALL     NULL    NULL    NULL    NULL    1       
3234
 
3       UNION   t12     ALL     NULL    NULL    NULL    NULL    1       
 
3348
1       PRIMARY t1      system  NULL    NULL    NULL    NULL    0       const row not found
 
3349
2       SUBQUERY        NULL    NULL    NULL    NULL    NULL    NULL    NULL    no matching row in const table
 
3350
3       UNION   NULL    NULL    NULL    NULL    NULL    NULL    NULL    no matching row in const table
3235
3351
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    NULL    
3236
3352
DROP TABLE t1;
 
3353
CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
 
3354
insert into t1 (a) values (FLOOR(rand() * 100));
 
3355
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
3356
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
3357
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
3358
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
3359
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
3360
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
3361
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
3362
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
3363
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
3364
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
3365
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
3366
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
3367
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
3368
SELECT a, 
 
3369
(SELECT REPEAT(' ',250) FROM t1 i1 
 
3370
WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a 
 
3371
FROM t1 ORDER BY a LIMIT 5;
 
3372
a       a
 
3373
0       NULL
 
3374
0       NULL
 
3375
0       NULL
 
3376
0       NULL
 
3377
0       NULL
 
3378
DROP TABLE t1;
3237
3379
CREATE TABLE t1 (a INT, b INT);
3238
3380
CREATE TABLE t2 (a INT);
3239
3381
INSERT INTO t2 values (1);
3291
3433
FROM t1) t;
3292
3434
COUNT(*)
3293
3435
3000
3294
 
DROP TABLE t2,t1;
 
3436
DROP TABLE t1,t2;
3295
3437
CREATE TABLE t1 (id char(4) PRIMARY KEY, c int);
3296
3438
CREATE TABLE t2 (c int);
3297
3439
INSERT INTO t1 VALUES ('aa', 1);
3329
3471
DROP TABLE IF EXISTS t2;
3330
3472
DROP TABLE IF EXISTS t1xt2;
3331
3473
CREATE TABLE t1 (
3332
 
id_1 int NOT NULL,
 
3474
id_1 int(5) NOT NULL,
3333
3475
t varchar(4) DEFAULT NULL
3334
3476
);
3335
3477
CREATE TABLE t2 (
3336
 
id_2 int NOT NULL,
 
3478
id_2 int(5) NOT NULL,
3337
3479
t varchar(4) DEFAULT NULL
3338
3480
);
3339
3481
CREATE TABLE t1xt2 (
3340
 
id_1 int NOT NULL,
3341
 
id_2 int NOT NULL
 
3482
id_1 int(5) NOT NULL,
 
3483
id_2 int(5) NOT NULL
3342
3484
);
3343
3485
INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd');
3344
3486
INSERT INTO t2 VALUES (2, 'bb'), (3, 'cc'), (4, 'dd'), (12, 'aa');
3622
3764
1       PRIMARY <derived2>      ALL     NULL    NULL    NULL    NULL    2       100.00  
3623
3765
2       DERIVED t1      ALL     NULL    NULL    NULL    NULL    2       100.00  Using temporary; Using filesort
3624
3766
Warnings:
3625
 
Note    1003    select `res`.`count(*)` AS `count(*)` from (select count(0) AS `count(*)` from `test`.`t1` group by `test`.`t1`.`a`) `res`
 
3767
Note    1003    select "res"."count(*)" AS "count(*)" from (select count(0) AS "count(*)" from "test"."t1" group by "test"."t1"."a") "res"
3626
3768
DROP TABLE t1;
3627
3769
CREATE TABLE t1 (
3628
3770
a varchar(255) default NULL,
3629
3771
b timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
3630
3772
INDEX idx(a,b)
3631
3773
);
3632
 
Warnings:
3633
 
Warning 1071    Specified key was too long; max key length is 767 bytes
3634
3774
CREATE TABLE t2 (
3635
3775
a varchar(255) default NULL
3636
3776
);
3698
3838
0
3699
3839
0
3700
3840
DROP TABLE t1, t2;
 
3841
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
 
3842
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
 
3843
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
 
3844
s1      s2
 
3845
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
 
3846
s1      s2
 
3847
CREATE INDEX I1 ON t1 (s1);
 
3848
CREATE INDEX I2 ON t1 (s2);
 
3849
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
 
3850
s1      s2
 
3851
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
 
3852
s1      s2
 
3853
TRUNCATE t1;
 
3854
INSERT INTO t1 VALUES (0x41,0x41);
 
3855
SELECT * FROM t1 WHERE s1 = (SELECT s2 FROM t1);
 
3856
s1      s2
 
3857
DROP TABLE t1;
 
3858
CREATE TABLE t1 (a1 VARBINARY(2) NOT NULL DEFAULT '0', PRIMARY KEY (a1));
 
3859
CREATE TABLE t2 (a2 BINARY(2) default '0', INDEX (a2));
 
3860
CREATE TABLE t3 (a3 BINARY(2) default '0');
 
3861
INSERT INTO t1 VALUES (1),(2),(3),(4);
 
3862
INSERT INTO t2 VALUES (1),(2),(3);
 
3863
INSERT INTO t3 VALUES (1),(2),(3);
 
3864
SELECT LEFT(t2.a2, 1) FROM t2,t3 WHERE t3.a3=t2.a2;
 
3865
LEFT(t2.a2, 1)
 
3866
1
 
3867
2
 
3868
3
 
3869
SELECT t1.a1, t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2) FROM t1;
 
3870
a1      t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2)
 
3871
1       0
 
3872
2       0
 
3873
3       0
 
3874
4       0
 
3875
DROP TABLE t1,t2,t3;
 
3876
CREATE TABLE t1 (a1 BINARY(3) PRIMARY KEY, b1 VARBINARY(3));
 
3877
CREATE TABLE t2 (a2 VARBINARY(3) PRIMARY KEY);
 
3878
CREATE TABLE t3 (a3 VARBINARY(3) PRIMARY KEY);
 
3879
INSERT INTO t1 VALUES (1,10), (2,20), (3,30), (4,40);
 
3880
INSERT INTO t2 VALUES (2), (3), (4), (5);
 
3881
INSERT INTO t3 VALUES (10), (20), (30);
 
3882
SELECT LEFT(t1.a1,1) FROM t1,t3 WHERE t1.b1=t3.a3;
 
3883
LEFT(t1.a1,1)
 
3884
1
 
3885
2
 
3886
3
 
3887
SELECT a2 FROM t2 WHERE t2.a2 IN (SELECT t1.a1 FROM t1,t3 WHERE t1.b1=t3.a3);
 
3888
a2
 
3889
DROP TABLE t1, t2, t3;
3701
3890
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10));
3702
3891
INSERT INTO t1 VALUES ('a', 'aa');
3703
3892
INSERT INTO t1 VALUES ('a', 'aaa');
3707
3896
CREATE INDEX I2 ON t1 (b);
3708
3897
EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
3709
3898
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
3710
 
1       PRIMARY t1      index   I1      I1      7       NULL    2       Using index; LooseScan
3711
 
1       PRIMARY t1      ref     I2      I2      43      test.t1.a       1       Using index condition
 
3899
1       PRIMARY t1      index   I1      I1      2       NULL    2       Using index; LooseScan
 
3900
1       PRIMARY t1      ref     I2      I2      13      test.t1.a       2       Using index condition
3712
3901
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
3713
3902
a       b
3714
3903
CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10));
3717
3906
CREATE INDEX I2 ON t2 (b);
3718
3907
EXPLAIN SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
3719
3908
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
3720
 
1       PRIMARY t2      index   I1      I1      7       NULL    2       Using index; LooseScan
3721
 
1       PRIMARY t2      ref     I2      I2      43      test.t2.a       1       Using index condition
 
3909
1       PRIMARY t2      index   I1      I1      4       NULL    2       Using index; LooseScan
 
3910
1       PRIMARY t2      ref     I2      I2      13      test.t2.a       2       Using index condition
3722
3911
SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
3723
3912
a       b
3724
3913
EXPLAIN
3725
3914
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
3726
3915
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
3727
 
1       PRIMARY t1      index   I1      I1      7       NULL    2       Using where; Using index; LooseScan
3728
 
1       PRIMARY t1      ref     I2      I2      43      test.t1.a       1       Using index condition
 
3916
1       PRIMARY t1      index   I1      I1      2       NULL    2       Using where; Using index; LooseScan
 
3917
1       PRIMARY t1      ref     I2      I2      13      test.t1.a       2       Using index condition
3729
3918
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
3730
3919
a       b
3731
3920
DROP TABLE t1,t2;
3769
3958
2       DEPENDENT SUBQUERY      t2      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
3770
3959
Warnings:
3771
3960
Note    1276    Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
3772
 
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`))
 
3961
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"))
3773
3962
EXPLAIN EXTENDED
3774
3963
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION 
3775
3964
(SELECT 1 FROM t2 WHERE t1.a = t2.a));
3781
3970
Warnings:
3782
3971
Note    1276    Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
3783
3972
Note    1276    Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1
3784
 
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`)))
 
3973
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")))
3785
3974
DROP TABLE t1,t2;
3786
3975
CREATE TABLE t4 (
3787
3976
f7 varchar(32) collate utf8_bin NOT NULL default '',