291
293
insert into t1 values (1, NULL, NULL), (1, NULL, 'b'), (1, 1, NULL), (1, 1, 'b'), (1, 1, 'b'), (2, 1, 'a'), (2, 1, 'b'), (2, 2, 'a'), (2, 2, 'b'), (2, 3, 'c'),(1,3,'b');
292
294
explain select * from t1 where (a = 1 and b is null and c = 'b') or (a > 2) order by a desc;
293
295
id select_type table type possible_keys key key_len ref rows Extra
294
1 SIMPLE t1 index a a 52 NULL 11 Using where; Using index
296
1 SIMPLE t1 index a a 22 NULL 11 Using where; Using index
295
297
select * from t1 where (a = 1 and b is null and c = 'b') or (a > 2) order by a desc;
298
300
explain select * from t1 where a >= 1 and a < 3 order by a desc;
299
301
id select_type table type possible_keys key key_len ref rows Extra
300
1 SIMPLE t1 range a a 4 NULL 5 Using where; Using index
302
1 SIMPLE t1 range a a 4 NULL 10 Using where; Using index
301
303
select * from t1 where a >= 1 and a < 3 order by a desc;
362
delete from t1 WHERE b IS NULL OR c IS NULL;
363
alter table t1 modify b bigint not null, modify c varchar(100) not null;
364
alter table t1 modify b int not null, modify c varchar(10) not null;
366
Warning 1265 Data truncated for column 'b' at row 1
367
Warning 1265 Data truncated for column 'c' at row 1
368
Warning 1265 Data truncated for column 'b' at row 2
369
Warning 1265 Data truncated for column 'c' at row 3
364
370
explain select * from t1 order by a, b, c;
365
371
id select_type table type possible_keys key key_len ref rows Extra
366
1 SIMPLE t1 index NULL a 414 NULL 8 Using index
372
1 SIMPLE t1 index NULL a 20 NULL 11 Using index
367
373
select * from t1 order by a, b, c;
417
433
explain select * from t1 where a between 1 and 3 and b <= 1 order by a desc, b desc;
418
434
id select_type table type possible_keys key key_len ref rows Extra
419
1 SIMPLE t1 range a a 12 NULL 4 Using where; Using index
435
1 SIMPLE t1 range a a 8 NULL 10 Using where; Using index
420
436
select * from t1 where a between 1 and 3 and b <= 1 order by a desc, b desc;
426
445
explain select * from t1 where a between 0 and 1 order by a desc, b desc;
427
446
id select_type table type possible_keys key key_len ref rows Extra
428
1 SIMPLE t1 range a a 4 NULL 3 Using where; Using index
447
1 SIMPLE t1 range a a 4 NULL 5 Using where; Using index
429
448
select * from t1 where a between 0 and 1 order by a desc, b desc;
435
CREATE TEMPORARY TABLE t1 (
436
gid int NOT NULL auto_increment,
437
cid int NOT NULL default '0',
458
gid int(10) unsigned NOT NULL auto_increment,
459
cid smallint(5) unsigned NOT NULL default '0',
438
460
PRIMARY KEY (gid),
439
461
KEY component_id (cid)
441
463
INSERT INTO t1 VALUES (103853,108),(103867,108),(103962,108),(104505,108),(104619,108),(104620,108);
442
ALTER TABLE t1 add skr int not null;
443
CREATE TEMPORARY TABLE t2 (
444
gid int NOT NULL default '0',
445
uid int NOT NULL default '1',
446
sid int NOT NULL default '1',
464
ALTER TABLE t1 add skr int(10) not null;
466
gid int(10) unsigned NOT NULL default '0',
467
uid smallint(5) unsigned NOT NULL default '1',
468
sid tinyint(3) unsigned NOT NULL default '1',
447
469
PRIMARY KEY (gid),
449
471
KEY status_id (sid)
451
473
INSERT INTO t2 VALUES (103853,250,5),(103867,27,5),(103962,27,5),(104505,117,5),(104619,75,5),(104620,15,5);
452
CREATE TEMPORARY TABLE t3 (
453
uid int NOT NULL auto_increment,
475
uid smallint(6) NOT NULL auto_increment,
454
476
PRIMARY KEY (uid)
456
478
INSERT INTO t3 VALUES (1),(15),(27),(75),(117),(250);
457
ALTER TABLE t3 add skr int not null;
479
ALTER TABLE t3 add skr int(10) not null;
458
480
select t1.gid, t2.sid, t3.uid from t2, t1, t3 where t2.gid = t1.gid and t2.uid = t3.uid order by t3.uid, t1.gid;
474
select t1.gid, t2.sid, t3.uid from t3, t2, t1 where t2.gid = t1.gid and t2.uid = t3.uid order by t1.gid, t3.uid;
482
SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t1.gid,t3.skr;
484
SELECT t1.gid, t2.sid, t3.uid from t2, t1, t3 where t2.gid = t1.gid and t2.uid = t3.uid order by t3.uid, t1.gid;
492
SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t3.skr,t1.gid;
494
SELECT t1.gid, t3.uid from t1, t3 where t1.skr = t3.uid order by t1.gid,t3.skr;
496
EXPLAIN select t1.gid, t2.sid, t3.uid from t3, t2, t1 where t2.gid = t1.gid and t2.uid = t3.uid order by t1.gid, t3.uid;
497
id select_type table type possible_keys key key_len ref rows Extra
498
1 SIMPLE t2 ALL PRIMARY,uid NULL NULL NULL 6 Using temporary; Using filesort
499
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 2 test.t2.uid 1 Using where; Using index
500
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.gid 1 Using index
501
EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t1.gid,t3.skr;
502
id select_type table type possible_keys key key_len ref rows Extra
503
1 SIMPLE t3 ALL PRIMARY NULL NULL NULL 6 Using temporary; Using filesort
504
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t3.uid 1 Using where; Using index
505
EXPLAIN SELECT t1.gid, t2.sid, t3.uid from t2, t1, t3 where t2.gid = t1.gid and t2.uid = t3.uid order by t3.uid, t1.gid;
506
id select_type table type possible_keys key key_len ref rows Extra
507
1 SIMPLE t2 ALL PRIMARY,uid NULL NULL NULL 6 Using temporary; Using filesort
508
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.gid 1 Using index
509
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 2 test.t2.uid 1 Using where; Using index
510
EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t3.skr,t1.gid;
511
id select_type table type possible_keys key key_len ref rows Extra
512
1 SIMPLE t3 ALL PRIMARY NULL NULL NULL 6 Using temporary; Using filesort
513
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t3.uid 1 Using where; Using index
514
EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.skr = t3.uid order by t1.gid,t3.skr;
515
id select_type table type possible_keys key key_len ref rows Extra
516
1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort
517
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 2 test.t1.skr 1 Using index condition
496
518
drop table t1,t2,t3;
497
519
CREATE TABLE t1 (
498
520
`titre` char(80) NOT NULL default '',
499
`numeropost` int NOT NULL auto_increment,
521
`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
522
`date` datetime NOT NULL default '0000-00-00 00:00:00',
501
523
`auteur` char(35) NOT NULL default '',
502
`icone` int NOT NULL default '0',
524
`icone` tinyint(2) unsigned NOT NULL default '0',
503
525
`lastauteur` char(35) NOT NULL default '',
504
`nbrep` int NOT NULL default '0',
526
`nbrep` smallint(6) unsigned NOT NULL default '0',
505
527
`dest` char(35) NOT NULL default '',
506
`lu` int NOT NULL default '0',
507
`vue` int NOT NULL default '0',
508
`ludest` int NOT NULL default '0',
509
`ouvert` int NOT NULL default '1',
528
`lu` tinyint(1) unsigned NOT NULL default '0',
529
`vue` mediumint(8) unsigned NOT NULL default '0',
530
`ludest` tinyint(1) unsigned NOT NULL default '0',
531
`ouvert` tinyint(1) unsigned NOT NULL default '1',
510
532
PRIMARY KEY (`numeropost`),
511
533
KEY `date` (`date`),
512
534
KEY `dest` (`dest`,`ludest`),
513
535
KEY `auteur` (`auteur`,`lu`),
514
536
KEY `auteur_2` (`auteur`,`date`),
515
537
KEY `dest_2` (`dest`,`date`)
517
539
CREATE TABLE t2 (
518
`numeropost` int NOT NULL default '0',
540
`numeropost` mediumint(8) unsigned NOT NULL default '0',
519
541
`pseudo` char(35) NOT NULL default '',
520
542
PRIMARY KEY (`numeropost`,`pseudo`),
521
543
KEY `pseudo` (`pseudo`)
524
546
INSERT INTO t2 (numeropost,pseudo) VALUES (1,'joce'),(1,'bug');
525
547
SELECT titre,t1.numeropost,auteur,icone,nbrep,0,date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30;
526
548
titre numeropost auteur icone nbrep 0 date vue ouvert lastauteur dest
527
test 1 joce 0 0 0 NULL 0 1 bug
549
test 1 joce 0 0 0 0000-00-00 00:00:00 0 1 bug
528
550
SELECT titre,numeropost,auteur,icone,nbrep,0,date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30;
529
551
titre numeropost auteur icone nbrep 0 date vue ouvert lastauteur dest
530
test 1 joce 0 0 0 NULL 0 1 bug
552
test 1 joce 0 0 0 0000-00-00 00:00:00 0 1 bug
531
553
SELECT titre,t1.numeropost,auteur,icone,nbrep,'0',date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30;
532
554
titre numeropost auteur icone nbrep 0 date vue ouvert lastauteur dest
533
test 1 joce 0 0 0 NULL 0 1 bug
555
test 1 joce 0 0 0 0000-00-00 00:00:00 0 1 bug
534
556
SELECT titre,numeropost,auteur,icone,nbrep,'0',date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30;
535
557
titre numeropost auteur icone nbrep 0 date vue ouvert lastauteur dest
536
test 1 joce 0 0 0 NULL 0 1 bug
558
test 1 joce 0 0 0 0000-00-00 00:00:00 0 1 bug
537
559
drop table t1,t2;
538
560
CREATE TABLE t1 (a int, b int);
539
561
INSERT INTO t1 VALUES (1, 2);
563
585
create table t1(id int not null auto_increment primary key, t char(12));
564
select id,t from t1 force index (primary) order by id;
586
explain select id,t from t1 order by id;
587
id select_type table type possible_keys key key_len ref rows Extra
588
1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 Using filesort
589
explain select id,t from t1 force index (primary) order by id;
590
id select_type table type possible_keys key key_len ref rows Extra
591
1 SIMPLE t1 index NULL PRIMARY 4 NULL 1000
1567
593
CREATE TABLE t1 (
1568
594
FieldKey varchar(36) NOT NULL default '',
1569
LongVal bigint default NULL,
595
LongVal bigint(20) default NULL,
596
StringVal mediumtext,
1571
597
KEY FieldKey (FieldKey),
1572
598
KEY LongField (FieldKey,LongVal),
1573
599
KEY StringField (FieldKey,StringVal(32))
1575
601
INSERT INTO t1 VALUES ('0',3,'0'),('0',2,'1'),('0',1,'2'),('1',2,'1'),('1',1,'3'), ('1',0,'2'),('2',3,'0'),('2',2,'1'),('2',1,'2'),('2',3,'0'),('2',2,'1'),('2',1,'2'),('3',2,'1'),('3',1,'2'),('3','3','3');
602
EXPLAIN SELECT * FROM t1 WHERE FieldKey = '1' ORDER BY LongVal;
603
id select_type table type possible_keys key key_len ref rows Extra
604
1 SIMPLE t1 ref FieldKey,LongField,StringField LongField 38 const 3 Using where
1576
605
SELECT * FROM t1 WHERE FieldKey = '1' ORDER BY LongVal;
1577
606
FieldKey LongVal StringVal
610
EXPLAIN SELECT * FROM t1 ignore index (FieldKey, LongField) WHERE FieldKey > '2' ORDER BY LongVal;
611
id select_type table type possible_keys key key_len ref rows Extra
612
1 SIMPLE t1 range StringField StringField 38 NULL 4 Using where; Using filesort
1581
613
SELECT * FROM t1 WHERE FieldKey > '2' ORDER BY LongVal;
1582
614
FieldKey LongVal StringVal
618
EXPLAIN SELECT * FROM t1 WHERE FieldKey > '2' ORDER BY FieldKey, LongVal;
619
id select_type table type possible_keys key key_len ref rows Extra
620
1 SIMPLE t1 range FieldKey,LongField,StringField LongField 38 NULL 4 Using where
1586
621
SELECT * FROM t1 WHERE FieldKey > '2' ORDER BY FieldKey, LongVal;
1587
622
FieldKey LongVal StringVal
1718
755
set max_sort_length=20;
1719
756
select a from t1 order by a;
758
xxxxxxxxxxxxxxxxxxxab
759
xxxxxxxxxxxxxxxxxxxaa
1721
760
xxxxxxxxxxxxxxxxxxxx
1722
761
xxxxxxxxxxxxxxxxxxxz
1723
xxxxxxxxxxxxxxxxxxxab
1724
xxxxxxxxxxxxxxxxxxxaa
1726
create temporary table t1 (
1727
764
`sid` decimal(8,0) default null,
1728
765
`wnid` varchar(11) not null default '',
1729
766
key `wnid14` (`wnid`(4)),
1730
767
key `wnid` (`wnid`)
768
) engine=myisam default charset=latin1;
1732
769
insert into t1 (`sid`, `wnid`) values
1733
770
('10100','01019000000'),('37986','01019000000'),('37987','01019010000'),
1734
771
('39560','01019090000'),('37989','01019000000'),('37990','01019011000'),
1045
CREATE TABLE t1 (a INT UNSIGNED NOT NULL, b TIME);
1046
INSERT INTO t1 (a) VALUES (100000), (0), (100), (1000000),(10000), (1000), (10);
1047
UPDATE t1 SET b = SEC_TO_TIME(a);
1048
SELECT a, b FROM t1 ORDER BY b DESC;
1057
SELECT a, b FROM t1 ORDER BY SEC_TO_TIME(a) DESC;
2008
1067
CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), UNIQUE KEY b (b));
2009
1068
INSERT INTO t1 VALUES (1,1),(2,2);
2010
1069
CREATE TABLE t2 (a INT, b INT, KEY a (a,b));
2011
1070
INSERT INTO t2 VALUES (1,1),(1,2),(2,1),(2,2);
2012
SELECT 1 FROM t1,t2 WHERE t1.b=2 AND t1.a=t2.a ORDER BY t2.b;
1071
EXPLAIN SELECT 1 FROM t1,t2 WHERE t1.b=2 AND t1.a=t2.a ORDER BY t2.b;
1072
id select_type table type possible_keys key key_len ref rows Extra
1073
1 SIMPLE t1 const PRIMARY,b b 5 const 1
1074
1 SIMPLE t2 ref a a 5 const 2 Using where; Using index
1077
id int auto_increment PRIMARY KEY, c2 int, c3 int, INDEX k2(c2), INDEX k3(c3));
1078
INSERT INTO t1 (c2,c3) VALUES
1079
(31,34),(35,38),(34,31),(32,35),(31,39),
1080
(11,14),(15,18),(14,11),(12,15),(11,19);
1081
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
1082
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
1083
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
1084
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
1085
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
1086
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
1087
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
1088
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
1089
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
1090
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
1091
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
1092
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
1093
UPDATE t1 SET c2=20 WHERE id%100 = 0;
1094
SELECT COUNT(*) FROM t1;
1097
CREATE TABLE t2 LIKE t1;
1098
INSERT INTO t2 SELECT * FROM t1 ORDER BY id;
1099
EXPLAIN SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 20;
1100
id select_type table type possible_keys key key_len ref rows Extra
1101
1 SIMPLE t2 index k2 k3 5 NULL 111 Using where
1102
EXPLAIN SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 4000;
1103
id select_type table type possible_keys key key_len ref rows Extra
1104
1 SIMPLE t2 ref k2 k2 5 const 7341 Using where; Using filesort
1105
EXPLAIN SELECT id,c3 FROM t2 WHERE c2 BETWEEN 10 AND 12 ORDER BY c3 LIMIT 20;
1106
id select_type table type possible_keys key key_len ref rows Extra
1107
1 SIMPLE t2 index k2 k3 5 NULL 73 Using where
1108
EXPLAIN SELECT id,c3 FROM t2 WHERE c2 BETWEEN 20 AND 30 ORDER BY c3 LIMIT 4000;
1109
id select_type table type possible_keys key key_len ref rows Extra
1110
1 SIMPLE t2 range k2 k2 5 NULL 386 Using index condition; Using where; Using MRR; Using filesort
1111
SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 20;
2016
1133
DROP TABLE t1,t2;
2017
1134
CREATE TABLE t1 (
2296
1415
SELECT @tmp_tables_after = @tmp_tables_before;
2297
1416
@tmp_tables_after = @tmp_tables_before
2301
1420
# Bug#31590: Wrong error message on sort buffer being too small.
2303
create table t1(a int, b text);
1422
create table t1(a int, b tinytext);
2304
1423
insert into t1 values (1,2),(3,2);
2305
1424
set session sort_buffer_size= 30000;
2307
Error 1292 Truncated incorrect sort_buffer_size value: '30000'
1426
Warning 1292 Truncated incorrect sort_buffer_size value: '30000'
2308
1427
set session max_sort_length= 2180;
2309
1428
select * from t1 order by b;
1429
ERROR HY001: Out of sort memory; increase server sort buffer size
2314
CREATE TABLE t2 (a varchar(32), b int, c float, d double,
1431
CREATE TABLE t2 (a varchar(32), b int(11), c float, d double,
2315
1432
UNIQUE KEY a (a,b,c), KEY b (b), KEY c (c));
2316
1433
CREATE TABLE t1 (a varchar(32), b char(3), UNIQUE KEY a (a,b), KEY b (b));
2317
1434
CREATE TABLE t3 (a varchar(32), b char(3), UNIQUE KEY a (a,b));
2318
1435
INSERT INTO t3 SELECT * FROM t1;
1437
SELECT d FROM t1, t2
1438
WHERE t2.b=14 AND t2.a=t1.a AND 5.1<t2.c AND t1.b='DE'
1439
ORDER BY t2.c LIMIT 1;
1440
id select_type table type possible_keys key key_len ref rows Extra
1441
1 SIMPLE t1 ref a,b b 4 const 4 Using index condition; Using temporary; Using filesort
1442
1 SIMPLE t2 ref a,b,c a 40 test.t1.a,const 11 Using index condition
2319
1443
SELECT d FROM t1, t2
2320
1444
WHERE t2.b=14 AND t2.a=t1.a AND 5.1<t2.c AND t1.b='DE'
2321
1445
ORDER BY t2.c LIMIT 1;
1449
SELECT d FROM t3 AS t1, t2 AS t2
1450
WHERE t2.b=14 AND t2.a=t1.a AND 5.1<t2.c AND t1.b='DE'
1451
ORDER BY t2.c LIMIT 1;
1452
id select_type table type possible_keys key key_len ref rows Extra
1453
1 SIMPLE t2 range a,b,c c 5 NULL 420 Using where; Using MRR
1454
1 SIMPLE t1 ref a a 39 test.t2.a,const 10 Using where; Using index
2324
1455
SELECT d FROM t3 AS t1, t2 AS t2
2325
1456
WHERE t2.b=14 AND t2.a=t1.a AND 5.1<t2.c AND t1.b='DE'
2326
1457
ORDER BY t2.c LIMIT 1;