15
15
INSERT INTO t1 VALUES (2,7,'60671569','Y');
16
16
INSERT INTO t1 VALUES (2,3,'dd','Y');
18
id int(6) NOT NULL auto_increment,
18
id int NOT NULL auto_increment,
19
19
description varchar(40) NOT NULL,
20
20
idform varchar(40),
21
ordre int(6) unsigned DEFAULT '0' NOT NULL,
21
ordre int DEFAULT '0' NOT NULL,
293
291
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');
294
292
explain select * from t1 where (a = 1 and b is null and c = 'b') or (a > 2) order by a desc;
295
293
id select_type table type possible_keys key key_len ref rows Extra
296
1 SIMPLE t1 index a a 22 NULL 11 Using where; Using index
294
1 SIMPLE t1 index a a 52 NULL 11 Using where; Using index
297
295
select * from t1 where (a = 1 and b is null and c = 'b') or (a > 2) order by a desc;
300
298
explain select * from t1 where a >= 1 and a < 3 order by a desc;
301
299
id select_type table type possible_keys key key_len ref rows Extra
302
1 SIMPLE t1 range a a 4 NULL 10 Using where; Using index
300
1 SIMPLE t1 range a a 4 NULL 5 Using where; Using index
303
301
select * from t1 where a >= 1 and a < 3 order by a desc;
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
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;
370
364
explain select * from t1 order by a, b, c;
371
365
id select_type table type possible_keys key key_len ref rows Extra
372
1 SIMPLE t1 index NULL a 20 NULL 11 Using index
366
1 SIMPLE t1 index NULL a 414 NULL 8 Using index
373
367
select * from t1 order by a, b, c;
402
390
explain select * from t1 where (a = 1 and b = 1 and c = 'b') or (a > 2) order by a desc;
403
391
id select_type table type possible_keys key key_len ref rows Extra
404
1 SIMPLE t1 range a a 20 NULL 3 Using where; Using index
392
1 SIMPLE t1 range a a 414 NULL 3 Using where; Using index
405
393
select * from t1 where (a = 1 and b = 1 and c = 'b') or (a > 2) order by a desc;
409
397
explain select * from t1 where a < 2 and b <= 1 order by a desc, b desc;
410
398
id select_type table type possible_keys key key_len ref rows Extra
411
1 SIMPLE t1 range a a 4 NULL 6 Using where; Using index
399
1 SIMPLE t1 range a a 4 NULL 3 Using where; Using index
412
400
select * from t1 where a < 2 and b <= 1 order by a desc, b desc;
419
404
select count(*) from t1 where a < 5 and b > 0;
422
407
select * from t1 where a < 5 and b > 0 order by a desc,b desc;
433
417
explain select * from t1 where a between 1 and 3 and b <= 1 order by a desc, b desc;
434
418
id select_type table type possible_keys key key_len ref rows Extra
435
1 SIMPLE t1 range a a 8 NULL 10 Using where; Using index
419
1 SIMPLE t1 range a a 12 NULL 4 Using where; Using index
436
420
select * from t1 where a between 1 and 3 and b <= 1 order by a desc, b desc;
445
426
explain select * from t1 where a between 0 and 1 order by a desc, b desc;
446
427
id select_type table type possible_keys key key_len ref rows Extra
447
1 SIMPLE t1 range a a 4 NULL 5 Using where; Using index
428
1 SIMPLE t1 range a a 4 NULL 3 Using where; Using index
448
429
select * from t1 where a between 0 and 1 order by a desc, b desc;
457
435
CREATE TABLE t1 (
458
gid int(10) unsigned NOT NULL auto_increment,
459
cid smallint(5) unsigned NOT NULL default '0',
436
gid int NOT NULL auto_increment,
437
cid int NOT NULL default '0',
460
438
PRIMARY KEY (gid),
461
439
KEY component_id (cid)
463
441
INSERT INTO t1 VALUES (103853,108),(103867,108),(103962,108),(104505,108),(104619,108),(104620,108);
464
ALTER TABLE t1 add skr int(10) not null;
442
ALTER TABLE t1 add skr int not null;
465
443
CREATE TABLE t2 (
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',
444
gid int NOT NULL default '0',
445
uid int NOT NULL default '1',
446
sid int NOT NULL default '1',
469
447
PRIMARY KEY (gid),
471
449
KEY status_id (sid)
473
451
INSERT INTO t2 VALUES (103853,250,5),(103867,27,5),(103962,27,5),(104505,117,5),(104619,75,5),(104620,15,5);
474
452
CREATE TABLE t3 (
475
uid smallint(6) NOT NULL auto_increment,
453
uid int NOT NULL auto_increment,
476
454
PRIMARY KEY (uid)
478
456
INSERT INTO t3 VALUES (1),(15),(27),(75),(117),(250);
479
ALTER TABLE t3 add skr int(10) not null;
457
ALTER TABLE t3 add skr int not null;
480
458
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;
496
474
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
475
id select_type table type possible_keys key key_len ref rows Extra
498
476
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
477
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.uid 1 Using index
500
478
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.gid 1 Using index
501
479
EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t1.gid,t3.skr;
502
480
id select_type table type possible_keys key key_len ref rows Extra
503
481
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
482
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t3.uid 1 Using index
505
483
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
484
id select_type table type possible_keys key key_len ref rows Extra
507
485
1 SIMPLE t2 ALL PRIMARY,uid NULL NULL NULL 6 Using temporary; Using filesort
508
486
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
487
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.uid 1 Using index
510
488
EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t3.skr,t1.gid;
511
489
id select_type table type possible_keys key key_len ref rows Extra
512
490
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
491
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t3.uid 1 Using index
514
492
EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.skr = t3.uid order by t1.gid,t3.skr;
515
493
id select_type table type possible_keys key key_len ref rows Extra
516
494
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
495
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.skr 1
518
496
drop table t1,t2,t3;
519
497
CREATE TABLE t1 (
520
498
`titre` char(80) NOT NULL default '',
521
`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
499
`numeropost` int NOT NULL auto_increment,
522
500
`date` datetime NOT NULL default '0000-00-00 00:00:00',
523
501
`auteur` char(35) NOT NULL default '',
524
`icone` tinyint(2) unsigned NOT NULL default '0',
502
`icone` int NOT NULL default '0',
525
503
`lastauteur` char(35) NOT NULL default '',
526
`nbrep` smallint(6) unsigned NOT NULL default '0',
504
`nbrep` int NOT NULL default '0',
527
505
`dest` char(35) NOT NULL default '',
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',
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',
532
510
PRIMARY KEY (`numeropost`),
533
511
KEY `date` (`date`),
534
512
KEY `dest` (`dest`,`ludest`),
585
563
create table t1(id int not null auto_increment primary key, t char(12));
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
564
select id,t from t1 force index (primary) order by id;
593
1567
CREATE TABLE t1 (
594
1568
FieldKey varchar(36) NOT NULL default '',
595
LongVal bigint(20) default NULL,
596
StringVal mediumtext,
1569
LongVal bigint default NULL,
597
1571
KEY FieldKey (FieldKey),
598
1572
KEY LongField (FieldKey,LongVal),
599
1573
KEY StringField (FieldKey,StringVal(32))
601
1575
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
1576
EXPLAIN SELECT * FROM t1 WHERE FieldKey = '1' ORDER BY LongVal;
603
1577
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
1578
1 SIMPLE t1 ref FieldKey,LongField,StringField LongField 146 const 3 Using where
605
1579
SELECT * FROM t1 WHERE FieldKey = '1' ORDER BY LongVal;
606
1580
FieldKey LongVal StringVal
638
1612
insert into t1 values (2, 1), (1, 1), (4, NULL), (3, NULL), (6, 2), (5, 2);
639
1613
explain select * from t1 where b=1 or b is null order by a;
640
1614
id select_type table type possible_keys key key_len ref rows Extra
641
1 SIMPLE t1 ref_or_null b b 5 const 3 Using filesort
1615
1 SIMPLE t1 ALL b NULL NULL NULL 6 Using where; Using filesort
642
1616
select * from t1 where b=1 or b is null order by a;
755
1729
set max_sort_length=20;
756
1730
select a from t1 order by a;
1732
xxxxxxxxxxxxxxxxxxxx
1733
xxxxxxxxxxxxxxxxxxxz
758
1734
xxxxxxxxxxxxxxxxxxxab
759
1735
xxxxxxxxxxxxxxxxxxxaa
763
1737
create table t1 (
764
1738
`sid` decimal(8,0) default null,
765
1739
`wnid` varchar(11) not null default '',
766
1740
key `wnid14` (`wnid`(4)),
767
1741
key `wnid` (`wnid`)
768
) engine=myisam default charset=latin1;
769
1743
insert into t1 (`sid`, `wnid`) values
770
1744
('10100','01019000000'),('37986','01019000000'),('37987','01019010000'),
771
1745
('39560','01019090000'),('37989','01019000000'),('37990','01019011000'),
1070
2044
INSERT INTO t2 VALUES (1,1),(1,2),(2,1),(2,2);
1071
2045
EXPLAIN SELECT 1 FROM t1,t2 WHERE t1.b=2 AND t1.a=t2.a ORDER BY t2.b;
1072
2046
id select_type table type possible_keys key key_len ref rows Extra
1073
1 SIMPLE t1 const PRIMARY,b b 5 const 1
2047
1 SIMPLE t1 const PRIMARY,b b 5 const 1 Using index
1074
2048
1 SIMPLE t2 ref a a 5 const 2 Using where; Using index
1075
2049
DROP TABLE t1,t2;
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;
1134
2050
CREATE TABLE t1 (
1415
2331
SELECT @tmp_tables_after = @tmp_tables_before;
1416
2332
@tmp_tables_after = @tmp_tables_before
1420
2336
# Bug#31590: Wrong error message on sort buffer being too small.
1422
create table t1(a int, b tinytext);
2338
create table t1(a int, b text);
1423
2339
insert into t1 values (1,2),(3,2);
1424
2340
set session sort_buffer_size= 30000;
1426
2342
Warning 1292 Truncated incorrect sort_buffer_size value: '30000'
1427
2343
set session max_sort_length= 2180;
1428
2344
select * from t1 order by b;
1429
ERROR HY001: Out of sort memory; increase server sort buffer size
1431
CREATE TABLE t2 (a varchar(32), b int(11), c float, d double,
2349
CREATE TABLE t2 (a varchar(32), b int, c float, d double,
1432
2350
UNIQUE KEY a (a,b,c), KEY b (b), KEY c (c));
1433
2351
CREATE TABLE t1 (a varchar(32), b char(3), UNIQUE KEY a (a,b), KEY b (b));
1434
2352
CREATE TABLE t3 (a varchar(32), b char(3), UNIQUE KEY a (a,b));
1438
2356
WHERE t2.b=14 AND t2.a=t1.a AND 5.1<t2.c AND t1.b='DE'
1439
2357
ORDER BY t2.c LIMIT 1;
1440
2358
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
2359
1 SIMPLE t1 ref a,b b 15 const 4 Using index condition; Using temporary; Using filesort
2360
1 SIMPLE t2 ref a,b,c a 136 test.t1.a,const 1 Using index condition
1443
2361
SELECT d FROM t1, t2
1444
2362
WHERE t2.b=14 AND t2.a=t1.a AND 5.1<t2.c AND t1.b='DE'
1445
2363
ORDER BY t2.c LIMIT 1;
1450
2368
WHERE t2.b=14 AND t2.a=t1.a AND 5.1<t2.c AND t1.b='DE'
1451
2369
ORDER BY t2.c LIMIT 1;
1452
2370
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
2371
1 SIMPLE t2 range a,b,c c 9 NULL 127 Using where; Using MRR
2372
1 SIMPLE t1 ref a a 146 test.t2.a,const 1 Using where; Using index
1455
2373
SELECT d FROM t3 AS t1, t2 AS t2
1456
2374
WHERE t2.b=14 AND t2.a=t1.a AND 5.1<t2.c AND t1.b='DE'
1457
2375
ORDER BY t2.c LIMIT 1;