~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Removed DBUG symbols and fixed TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
--enable_warnings
8
8
 
9
9
CREATE TABLE t1 (
10
 
  id int DEFAULT '0' NOT NULL,
11
 
  idservice int,
12
 
  clee varchar(20) NOT NULL,
13
 
  flag varchar(1),
 
10
  id int(6) DEFAULT '0' NOT NULL,
 
11
  idservice int(5),
 
12
  clee char(20) NOT NULL,
 
13
  flag char(1),
14
14
  KEY id (id),
15
15
  PRIMARY KEY (clee)
16
16
);
25
25
INSERT INTO t1 VALUES (2,3,'dd','Y');
26
26
 
27
27
CREATE TABLE t2 (
28
 
  id int NOT NULL auto_increment,
 
28
  id int(6) NOT NULL auto_increment,
29
29
  description varchar(40) NOT NULL,
30
30
  idform varchar(40),
31
 
  ordre int DEFAULT '0' NOT NULL,
 
31
  ordre int(6) unsigned DEFAULT '0' NOT NULL,
32
32
  image varchar(60),
33
33
  PRIMARY KEY (id),
34
34
  KEY id (id,ordre)
120
120
 
121
121
CREATE TABLE t1
122
122
(
123
 
  a          int       NOT NULL,
124
 
  b          int       NOT NULL,
125
 
  c          int       NOT NULL,
 
123
  a          int unsigned       NOT NULL,
 
124
  b          int unsigned       NOT NULL,
 
125
  c          int unsigned       NOT NULL,
126
126
  UNIQUE(a),
127
127
  INDEX(b),
128
128
  INDEX(c)
130
130
 
131
131
CREATE TABLE t2
132
132
(
133
 
  c          int       NOT NULL,
134
 
  i          int       NOT NULL,
 
133
  c          int unsigned       NOT NULL,
 
134
  i          int unsigned       NOT NULL,
135
135
  INDEX(c)
136
136
);
137
137
 
138
138
CREATE TABLE t3
139
139
(
140
 
  c          int       NOT NULL,
 
140
  c          int unsigned       NOT NULL,
141
141
  v          varchar(64),
142
142
  INDEX(c)
143
143
);
192
192
#bug reported by Wouter de Jong
193
193
 
194
194
CREATE TABLE t1 (
195
 
  member_id int NOT NULL auto_increment,
 
195
  member_id int(11) NOT NULL auto_increment,
196
196
  inschrijf_datum varchar(20) NOT NULL default '',
197
197
  lastchange_datum varchar(20) NOT NULL default '',
198
198
  nickname varchar(20) NOT NULL default '',
255
255
# Test things when we don't have NULL keys
256
256
#
257
257
 
258
 
delete from t1 WHERE b IS NULL OR c IS NULL;
259
 
alter table t1 modify b bigint not null, modify c varchar(100) not null;
 
258
alter table t1 modify b int not null, modify c varchar(10) not null;
260
259
explain select * from t1 order by a, b, c;
261
260
select * from t1 order by a, b, c;
262
261
explain select * from t1 order by a desc, b desc, c desc;
279
278
 
280
279
 
281
280
CREATE TABLE t1 (
282
 
  gid int NOT NULL auto_increment,
283
 
  cid int NOT NULL default '0',
 
281
  gid int(10) unsigned NOT NULL auto_increment,
 
282
  cid smallint(5) unsigned NOT NULL default '0',
284
283
  PRIMARY KEY  (gid),
285
284
  KEY component_id (cid)
286
285
) ENGINE=MyISAM;
287
286
INSERT INTO t1 VALUES (103853,108),(103867,108),(103962,108),(104505,108),(104619,108),(104620,108);
288
 
ALTER TABLE t1 add skr int not null;
 
287
ALTER TABLE t1 add skr int(10) not null;
289
288
 
290
289
CREATE TABLE t2 (
291
 
  gid int NOT NULL default '0',
292
 
  uid int NOT NULL default '1',
293
 
  sid int NOT NULL default '1',
 
290
  gid int(10) unsigned NOT NULL default '0',
 
291
  uid smallint(5) unsigned NOT NULL default '1',
 
292
  sid tinyint(3) unsigned NOT NULL default '1',
294
293
  PRIMARY KEY  (gid),
295
294
  KEY uid (uid),
296
295
  KEY status_id (sid)
298
297
INSERT INTO t2 VALUES (103853,250,5),(103867,27,5),(103962,27,5),(104505,117,5),(104619,75,5),(104620,15,5);
299
298
 
300
299
CREATE TABLE t3 (
301
 
  uid int NOT NULL auto_increment,
 
300
  uid smallint(6) NOT NULL auto_increment,
302
301
  PRIMARY KEY  (uid)
303
302
) ENGINE=MyISAM;
304
303
INSERT INTO t3 VALUES (1),(15),(27),(75),(117),(250);
305
 
ALTER TABLE t3 add skr int not null;
 
304
ALTER TABLE t3 add skr int(10) not null;
306
305
 
307
306
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;
308
307
select t1.gid, t2.sid, t3.uid from t3, t2, t1 where t2.gid = t1.gid and t2.uid = t3.uid order by t3.uid, t1.gid;
309
308
 
310
309
# The following ORDER BY can be optimimized
311
 
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;
312
 
SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t1.gid,t3.skr;
 
310
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;
 
311
EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t1.gid,t3.skr;
313
312
 
314
313
# The following ORDER BY can't be optimimized
315
 
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;
316
 
SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t3.skr,t1.gid;
317
 
SELECT t1.gid, t3.uid from t1, t3 where t1.skr = t3.uid order by t1.gid,t3.skr;
 
314
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;
 
315
EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t3.skr,t1.gid;
 
316
EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.skr = t3.uid order by t1.gid,t3.skr;
318
317
drop table t1,t2,t3;
319
318
 
320
319
#
323
322
 
324
323
CREATE TABLE t1 (
325
324
  `titre` char(80) NOT NULL default '',
326
 
  `numeropost` int NOT NULL auto_increment,
 
325
  `numeropost` mediumint(8) unsigned NOT NULL auto_increment,
327
326
  `date` datetime NOT NULL default '0000-00-00 00:00:00',
328
327
  `auteur` char(35) NOT NULL default '',
329
 
  `icone` int NOT NULL default '0',
 
328
  `icone` tinyint(2) unsigned NOT NULL default '0',
330
329
  `lastauteur` char(35) NOT NULL default '',
331
 
  `nbrep` int NOT NULL default '0',
 
330
  `nbrep` smallint(6) unsigned NOT NULL default '0',
332
331
  `dest` char(35) NOT NULL default '',
333
 
  `lu` int NOT NULL default '0',
334
 
  `vue` int NOT NULL default '0',
335
 
  `ludest` int NOT NULL default '0',
336
 
  `ouvert` int NOT NULL default '1',
 
332
  `lu` tinyint(1) unsigned NOT NULL default '0',
 
333
  `vue` mediumint(8) unsigned NOT NULL default '0',
 
334
  `ludest` tinyint(1) unsigned NOT NULL default '0',
 
335
  `ouvert` tinyint(1) unsigned NOT NULL default '1',
337
336
  PRIMARY KEY  (`numeropost`),
338
337
  KEY `date` (`date`),
339
338
  KEY `dest` (`dest`,`ludest`),
343
342
) CHECKSUM=1;
344
343
 
345
344
CREATE TABLE t2 (
346
 
  `numeropost` int NOT NULL default '0',
 
345
  `numeropost` mediumint(8) unsigned NOT NULL default '0',
347
346
  `pseudo` char(35) NOT NULL default '',
348
347
  PRIMARY KEY  (`numeropost`,`pseudo`),
349
348
  KEY `pseudo` (`pseudo`)
383
382
  dec $1;
384
383
 }
385
384
enable_query_log;
386
 
select id,t from t1 force index (primary) order by id;
 
385
explain select id,t from t1 order by id;
 
386
explain select id,t from t1 force index (primary) order by id;
387
387
drop table t1;
388
388
 
389
389
#
391
391
#
392
392
CREATE TABLE t1 (
393
393
  FieldKey varchar(36) NOT NULL default '',
394
 
  LongVal bigint default NULL,
395
 
  StringVal text,
 
394
  LongVal bigint(20) default NULL,
 
395
  StringVal mediumtext,
396
396
  KEY FieldKey (FieldKey),
397
397
  KEY LongField (FieldKey,LongVal),
398
398
  KEY StringField (FieldKey,StringVal(32))
399
399
);
400
400
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');
 
401
EXPLAIN SELECT * FROM t1 WHERE FieldKey = '1' ORDER BY LongVal;
401
402
SELECT * FROM t1 WHERE FieldKey = '1' ORDER BY LongVal;
 
403
EXPLAIN SELECT * FROM t1 ignore index (FieldKey, LongField) WHERE FieldKey > '2' ORDER BY LongVal;
402
404
SELECT * FROM t1 WHERE FieldKey > '2' ORDER BY LongVal;
 
405
EXPLAIN SELECT * FROM t1 WHERE FieldKey > '2' ORDER BY FieldKey, LongVal;
403
406
SELECT * FROM t1 WHERE FieldKey > '2' ORDER BY FieldKey, LongVal;
404
407
DROP TABLE t1;
405
408
#
414
417
# Bug when doing an order by on a 1 byte string (Bug #2147)
415
418
#
416
419
 
417
 
CREATE TABLE t1 (  id int NOT NULL default '0',  menu int NOT NULL default '0',  KEY id (id),  KEY menu (menu)) ENGINE=MyISAM;
 
420
CREATE TABLE t1 (  id smallint(6) unsigned NOT NULL default '0',  menu tinyint(4) NOT NULL default '0',  KEY id (id),  KEY menu (menu)) ENGINE=MyISAM;
418
421
INSERT INTO t1 VALUES (11384, 2),(11392, 2);
419
422
SELECT id FROM t1 WHERE id <11984 AND menu =2 ORDER BY id DESC LIMIT 1 ;
420
423
drop table t1;
520
523
  `wnid` varchar(11) not null default '',
521
524
  key `wnid14` (`wnid`(4)),
522
525
  key `wnid` (`wnid`)
523
 
) engine=myisam;
 
526
) engine=myisam default charset=latin1;
524
527
 
525
528
insert into t1 (`sid`, `wnid`) values
526
529
('10100','01019000000'),('37986','01019000000'),('37987','01019010000'),
590
593
#       crashes server
591
594
#
592
595
CREATE TABLE bug25126 (
593
 
  val int NOT NULL AUTO_INCREMENT PRIMARY KEY
 
596
  val int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY
594
597
);
595
598
--error 1054
596
599
UPDATE bug25126 SET MissingCol = MissingCol;
712
715
#
713
716
# Bug#26672: Incorrect SEC_TO_TIME() casting in ORDER BY
714
717
#
715
 
CREATE TABLE t1 (a INT NOT NULL, b TIME);
 
718
CREATE TABLE t1 (a INT UNSIGNED NOT NULL, b TIME);
716
719
INSERT INTO t1 (a) VALUES (100000), (0), (100), (1000000),(10000), (1000), (10);
717
720
UPDATE t1 SET b = SEC_TO_TIME(a);
718
721
 
733
736
CREATE TABLE t2 (a INT, b INT, KEY a (a,b));
734
737
INSERT INTO t2 VALUES (1,1),(1,2),(2,1),(2,2);
735
738
 
736
 
SELECT 1 FROM t1,t2 WHERE t1.b=2 AND t1.a=t2.a ORDER BY t2.b;
 
739
EXPLAIN SELECT 1 FROM t1,t2 WHERE t1.b=2 AND t1.a=t2.a ORDER BY t2.b;
737
740
 
738
741
DROP TABLE t1,t2;
739
742
 
740
743
# End of 5.0
741
744
 
 
745
#
 
746
# Bug #28404: query with ORDER BY and ref access
 
747
#
 
748
 
 
749
CREATE TABLE t1(
 
750
  id int auto_increment PRIMARY KEY, c2 int, c3 int, INDEX k2(c2), INDEX k3(c3));
 
751
 
 
752
INSERT INTO t1 (c2,c3) VALUES
 
753
 (31,34),(35,38),(34,31),(32,35),(31,39),
 
754
 (11,14),(15,18),(14,11),(12,15),(11,19);
 
755
 
 
756
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
 
757
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
 
758
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
 
759
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
 
760
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
 
761
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
 
762
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
 
763
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
 
764
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
 
765
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
 
766
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
 
767
INSERT INTO t1 (c2,c3) SELECT c2,c3 FROM t1;
 
768
UPDATE t1 SET c2=20 WHERE id%100 = 0;
 
769
SELECT COUNT(*) FROM t1;
 
770
 
 
771
CREATE TABLE t2 LIKE t1;
 
772
INSERT INTO t2 SELECT * FROM t1 ORDER BY id;
 
773
 
 
774
EXPLAIN SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 20;
 
775
EXPLAIN SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 4000;
 
776
EXPLAIN SELECT id,c3 FROM t2 WHERE c2 BETWEEN 10 AND 12 ORDER BY c3 LIMIT 20;
 
777
EXPLAIN SELECT id,c3 FROM t2 WHERE c2 BETWEEN 20 AND 30 ORDER BY c3 LIMIT 4000;
 
778
 
 
779
SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 20;
 
780
 
 
781
DROP TABLE t1,t2;
 
782
 
742
783
743
784
# Bug #30665: Inconsistent optimization of IGNORE INDEX FOR {ORDER BY|GROUP BY}
744
785
#
755
796
INSERT INTO t1 SELECT a +32, b +32 FROM t1;
756
797
INSERT INTO t1 SELECT a +64, b +64 FROM t1;
757
798
 
 
799
EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR GROUP BY (a, ab) GROUP BY a;
 
800
 
 
801
--disable_query_log
 
802
--let $q = `show status like 'Created_tmp_tables';`
 
803
eval set @tmp_tables_before = 
 
804
  CAST(REPLACE('$q', 'Created_tmp_tables', '') AS UNSIGNED);
 
805
--enable_query_log
 
806
 
758
807
SELECT a FROM t1 IGNORE INDEX FOR GROUP BY (a, ab) GROUP BY a;
759
808
 
 
809
# this query creates one temporary table in itself, which we are not
 
810
# interested in.
 
811
 
 
812
--disable_query_log
 
813
--let $q = `show status like 'Created_tmp_tables';`
 
814
eval set @tmp_tables_after = 
 
815
  CAST(REPLACE('$q', 'Created_tmp_tables', '') AS UNSIGNED);
 
816
--enable_query_log
 
817
 
760
818
SELECT @tmp_tables_after = @tmp_tables_before ;
761
819
 
 
820
EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (a, ab) ORDER BY a;
 
821
 
 
822
--disable_query_log
 
823
--let $q = `show status like 'Created_tmp_tables';`
 
824
eval set @tmp_tables_before = 
 
825
  CAST(REPLACE('$q', 'Created_tmp_tables', '') AS UNSIGNED);
 
826
--enable_query_log
 
827
 
762
828
SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (a, ab) ORDER BY a;
763
829
 
 
830
--disable_query_log
 
831
--let $q = `show status like 'Created_tmp_tables';`
 
832
eval set @tmp_tables_after = 
 
833
  CAST(REPLACE('$q', 'Created_tmp_tables', '') AS UNSIGNED);
 
834
--enable_query_log
 
835
 
764
836
SELECT @tmp_tables_after = @tmp_tables_before;
765
837
 
766
838
DROP TABLE t1;
767
839
--echo #
768
840
--echo # Bug#31590: Wrong error message on sort buffer being too small.
769
841
--echo #
770
 
create table t1(a int, b text);
 
842
create table t1(a int, b tinytext);
771
843
insert into t1 values (1,2),(3,2);
772
844
set session sort_buffer_size= 30000;
773
845
set session max_sort_length= 2180;
 
846
--error 1038
774
847
select * from t1 order by b;
775
848
drop table t1;
776
849
 
778
851
# Bug #35206: select query result different if the key is indexed or not
779
852
#
780
853
 
781
 
CREATE TABLE t2 (a varchar(32), b int, c float, d double, 
 
854
CREATE TABLE t2 (a varchar(32), b int(11), c float, d double, 
782
855
  UNIQUE KEY a (a,b,c), KEY b (b), KEY c (c));
783
856
 
784
857
CREATE TABLE t1 (a varchar(32), b char(3), UNIQUE KEY a (a,b), KEY b (b));
1219
1292
 
1220
1293
INSERT INTO t3 SELECT * FROM t1;
1221
1294
 
 
1295
EXPLAIN
 
1296
SELECT d FROM t1, t2
 
1297
WHERE t2.b=14 AND t2.a=t1.a AND 5.1<t2.c AND t1.b='DE'
 
1298
ORDER BY t2.c LIMIT 1;
1222
1299
SELECT d FROM t1, t2
1223
1300
WHERE t2.b=14 AND t2.a=t1.a AND 5.1<t2.c AND t1.b='DE'
1224
1301
ORDER BY t2.c LIMIT 1;
1225
1302
 
 
1303
EXPLAIN
 
1304
SELECT d FROM t3 AS t1, t2 AS t2 
 
1305
WHERE t2.b=14 AND t2.a=t1.a AND 5.1<t2.c AND t1.b='DE'
 
1306
ORDER BY t2.c LIMIT 1;
1226
1307
SELECT d FROM t3 AS t1, t2 AS t2 
1227
1308
WHERE t2.b=14 AND t2.a=t1.a AND 5.1<t2.c AND t1.b='DE'
1228
1309
ORDER BY t2.c LIMIT 1;