~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
count(*)
149
149
12
150
150
drop table t1,t2;
151
 
CREATE TABLE t1 (UserId int DEFAULT '0' NOT NULL);
 
151
CREATE TABLE t1 (UserId int(11) DEFAULT '0' NOT NULL);
152
152
INSERT INTO t1 VALUES (20);
153
153
INSERT INTO t1 VALUES (27);
154
154
SELECT UserId FROM t1 WHERE Userid=22;
160
160
SELECT DISTINCT UserId FROM t1 WHERE UserId=22;
161
161
UserId
162
162
drop table t1;
163
 
CREATE TABLE t1 (a int not null primary key,b int);
 
163
CREATE TABLE t1 (a int(10) unsigned not null primary key,b int(10) unsigned);
164
164
INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1);
165
 
CREATE TABLE t2 (a int not null, key (A));
 
165
CREATE TABLE t2 (a int(10) unsigned not null, key (A));
166
166
INSERT INTO t2 VALUES (1),(2);
167
 
CREATE TABLE t3 (a int, key(A), b text);
 
167
CREATE TABLE t3 (a int(10) unsigned, key(A), b text);
168
168
INSERT INTO t3 VALUES (1,'1'),(2,'2');
169
169
SELECT DISTINCT t3.b FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
170
170
b
174
174
explain SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
175
175
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
176
176
1       SIMPLE  t1      ALL     PRIMARY NULL    NULL    NULL    4       Using temporary
177
 
1       SIMPLE  t2      ref     a       a       4       test.t1.a       1       Using index
178
 
1       SIMPLE  t3      ref     a       a       5       test.t1.b       1       Using index
 
177
1       SIMPLE  t3      ref     a       a       5       test.t1.b       2       Using index
 
178
1       SIMPLE  t2      index   a       a       4       NULL    5       Using where; Using index; Distinct; Using join buffer
179
179
SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
180
180
a
181
181
1
190
190
explain select distinct t1.a from t1,t3 where t1.a=t3.a;
191
191
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
192
192
1       SIMPLE  t1      index   PRIMARY PRIMARY 4       NULL    4       Using index; Using temporary
193
 
1       SIMPLE  t3      ref     a       a       5       test.t1.a       1       Using index; Distinct
 
193
1       SIMPLE  t3      ref     a       a       5       test.t1.a       11      Using index; Distinct
194
194
select distinct t1.a from t1,t3 where t1.a=t3.a;
195
195
a
196
196
1
212
212
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    1       Using index
213
213
explain SELECT distinct a from t3 order by a desc limit 2;
214
214
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
215
 
1       SIMPLE  t3      index   NULL    a       5       NULL    2       Using index
 
215
1       SIMPLE  t3      index   NULL    a       5       NULL    40      Using index
216
216
explain SELECT distinct a,b from t3 order by a+1;
217
217
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
218
218
1       SIMPLE  t3      ALL     NULL    NULL    NULL    NULL    204     Using temporary; Using filesort
219
219
explain SELECT distinct a,b from t3 order by a limit 2;
220
220
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
221
 
1       SIMPLE  t3      ALL     NULL    NULL    NULL    NULL    204     Using temporary; Using filesort
 
221
1       SIMPLE  t3      index   NULL    a       5       NULL    2       Using temporary
222
222
explain SELECT a,b from t3 group by a,b order by a+1;
223
223
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
224
224
1       SIMPLE  t3      ALL     NULL    NULL    NULL    NULL    204     Using temporary; Using filesort
238
238
1
239
239
drop table t1;
240
240
CREATE TABLE t1 (
241
 
ID int NOT NULL auto_increment,
 
241
ID int(11) NOT NULL auto_increment,
242
242
NAME varchar(75) DEFAULT '' NOT NULL,
243
 
LINK_ID int DEFAULT '0' NOT NULL,
 
243
LINK_ID int(11) DEFAULT '0' NOT NULL,
244
244
PRIMARY KEY (ID),
245
245
KEY NAME (NAME),
246
246
KEY LINK_ID (LINK_ID)
247
247
);
248
248
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (1,'Mike',0),(2,'Jack',0),(3,'Bill',0);
249
249
CREATE TABLE t2 (
250
 
ID int NOT NULL auto_increment,
 
250
ID int(11) NOT NULL auto_increment,
251
251
NAME varchar(150) DEFAULT '' NOT NULL,
252
252
PRIMARY KEY (ID),
253
253
KEY NAME (NAME)
402
402
test2@testdomain.com    R002
403
403
test3@testdomain.com    Z001
404
404
drop table t1,t2;
405
 
CREATE TABLE t1 (privatemessageid int NOT NULL auto_increment,  folderid int NOT NULL default '0',  userid int NOT NULL default '0',  touserid int NOT NULL default '0',  fromuserid int NOT NULL default '0',  title varchar(250) NOT NULL default '',  message mediumtext NOT NULL,  dateline int NOT NULL default '0',  showsignature int NOT NULL default '0',  iconid int NOT NULL default '0',  messageread int NOT NULL default '0',  readtime int NOT NULL default '0',  receipt int NOT NULL default '0',  deleteprompt int NOT NULL default '0',  multiplerecipients int NOT NULL default '0',  PRIMARY KEY  (privatemessageid),  KEY userid (userid)) ENGINE=MyISAM;
 
405
CREATE TABLE t1 (privatemessageid int(10) unsigned NOT NULL auto_increment,  folderid smallint(6) NOT NULL default '0',  userid int(10) unsigned NOT NULL default '0',  touserid int(10) unsigned NOT NULL default '0',  fromuserid int(10) unsigned NOT NULL default '0',  title varchar(250) NOT NULL default '',  message mediumtext NOT NULL,  dateline int(10) unsigned NOT NULL default '0',  showsignature smallint(6) NOT NULL default '0',  iconid smallint(5) unsigned NOT NULL default '0',  messageread smallint(6) NOT NULL default '0',  readtime int(10) unsigned NOT NULL default '0',  receipt smallint(6) unsigned NOT NULL default '0',  deleteprompt smallint(6) unsigned NOT NULL default '0',  multiplerecipients smallint(6) unsigned NOT NULL default '0',  PRIMARY KEY  (privatemessageid),  KEY userid (userid)) ENGINE=MyISAM;
406
406
INSERT INTO t1 VALUES (128,0,33,33,8,':D','',996121863,1,0,2,996122850,2,0,0);
407
 
CREATE TABLE t2 (userid int NOT NULL auto_increment,  usergroupid int NOT NULL default '0',  username varchar(50) NOT NULL default '',  password varchar(50) NOT NULL default '',  email varchar(50) NOT NULL default '',  styleid int NOT NULL default '0',  parentemail varchar(50) NOT NULL default '',  coppauser int NOT NULL default '0',  homepage varchar(100) NOT NULL default '',  icq varchar(20) NOT NULL default '',  aim varchar(20) NOT NULL default '',  yahoo varchar(20) NOT NULL default '',  signature mediumtext NOT NULL,  adminemail int NOT NULL default '0',  showemail int NOT NULL default '0',  invisible int NOT NULL default '0',  usertitle varchar(250) NOT NULL default '',  customtitle int NOT NULL default '0',  joindate int NOT NULL default '0',  cookieuser int NOT NULL default '0',  daysprune int NOT NULL default '0',  lastvisit int NOT NULL default '0',  lastactivity int NOT NULL default '0',  lastpost int NOT NULL default '0',  posts int NOT NULL default '0',  timezoneoffset varchar(4) NOT NULL default '',  emailnotification int NOT NULL default '0',  buddylist mediumtext NOT NULL,  ignorelist mediumtext NOT NULL,  pmfolders mediumtext NOT NULL,  receivepm int NOT NULL default '0',  emailonpm int NOT NULL default '0',  pmpopup int NOT NULL default '0',  avatarid int NOT NULL default '0',  avatarrevision int NOT NULL default '0',  options int NOT NULL default '15',  birthday date NOT NULL default '0000-00-00',  maxposts int NOT NULL default '-1',  startofweek int NOT NULL default '1',  ipaddress varchar(20) NOT NULL default '',  referrerid int NOT NULL default '0',  nosessionhash int NOT NULL default '0',  autorefresh int NOT NULL default '-1',  messagepopup int NOT NULL default '0',  inforum int NOT NULL default '0',  ratenum int NOT NULL default '0',  ratetotal int NOT NULL default '0',  allowrate int NOT NULL default '1',  PRIMARY KEY  (userid),  KEY usergroupid (usergroupid),  KEY username (username),  KEY inforum (inforum)) ENGINE=MyISAM;
 
407
CREATE TABLE t2 (userid int(10) unsigned NOT NULL auto_increment,  usergroupid smallint(5) unsigned NOT NULL default '0',  username varchar(50) NOT NULL default '',  password varchar(50) NOT NULL default '',  email varchar(50) NOT NULL default '',  styleid smallint(5) unsigned NOT NULL default '0',  parentemail varchar(50) NOT NULL default '',  coppauser smallint(6) NOT NULL default '0',  homepage varchar(100) NOT NULL default '',  icq varchar(20) NOT NULL default '',  aim varchar(20) NOT NULL default '',  yahoo varchar(20) NOT NULL default '',  signature mediumtext NOT NULL,  adminemail smallint(6) NOT NULL default '0',  showemail smallint(6) NOT NULL default '0',  invisible smallint(6) NOT NULL default '0',  usertitle varchar(250) NOT NULL default '',  customtitle smallint(6) NOT NULL default '0',  joindate int(10) unsigned NOT NULL default '0',  cookieuser smallint(6) NOT NULL default '0',  daysprune smallint(6) NOT NULL default '0',  lastvisit int(10) unsigned NOT NULL default '0',  lastactivity int(10) unsigned NOT NULL default '0',  lastpost int(10) unsigned NOT NULL default '0',  posts smallint(5) unsigned NOT NULL default '0',  timezoneoffset varchar(4) NOT NULL default '',  emailnotification smallint(6) NOT NULL default '0',  buddylist mediumtext NOT NULL,  ignorelist mediumtext NOT NULL,  pmfolders mediumtext NOT NULL,  receivepm smallint(6) NOT NULL default '0',  emailonpm smallint(6) NOT NULL default '0',  pmpopup smallint(6) NOT NULL default '0',  avatarid smallint(6) NOT NULL default '0',  avatarrevision int(6) unsigned NOT NULL default '0',  options smallint(6) NOT NULL default '15',  birthday date NOT NULL default '0000-00-00',  maxposts smallint(6) NOT NULL default '-1',  startofweek smallint(6) NOT NULL default '1',  ipaddress varchar(20) NOT NULL default '',  referrerid int(10) unsigned NOT NULL default '0',  nosessionhash smallint(6) NOT NULL default '0',  autorefresh smallint(6) NOT NULL default '-1',  messagepopup tinyint(2) NOT NULL default '0',  inforum smallint(5) unsigned NOT NULL default '0',  ratenum smallint(5) unsigned NOT NULL default '0',  ratetotal smallint(5) unsigned NOT NULL default '0',  allowrate smallint(5) unsigned NOT NULL default '1',  PRIMARY KEY  (userid),  KEY usergroupid (usergroupid),  KEY username (username),  KEY inforum (inforum)) ENGINE=MyISAM;
408
408
INSERT INTO t2 VALUES (33,6,'Kevin','0','kevin@stileproject.com',1,'',0,'http://www.stileproject.com','','','','',1,1,0,'Administrator',0,996120694,1,-1,1030996168,1031027028,1030599436,36,'-6',0,'','','',1,0,1,0,0,15,'0000-00-00',-1,1,'64.0.0.0',0,1,-1,0,0,4,19,1);
409
409
SELECT DISTINCT t1.*, t2.* FROM t1 LEFT JOIN t2 ON (t2.userid = t1.touserid);
410
410
privatemessageid        folderid        userid  touserid        fromuserid      title   message dateline        showsignature   iconid  messageread     readtime        receipt deleteprompt    multiplerecipients      userid  usergroupid     username        password        email   styleid parentemail     coppauser       homepage        icq     aim     yahoo   signature       adminemail      showemail       invisible       usertitle       customtitle     joindate        cookieuser      daysprune       lastvisit       lastactivity    lastpost        posts   timezoneoffset  emailnotification       buddylist       ignorelist      pmfolders       receivepm       emailonpm       pmpopup avatarid        avatarrevision  options birthday        maxposts        startofweek     ipaddress       referrerid      nosessionhash   autorefresh     messagepopup    inforum ratenum ratetotal       allowrate
418
418
a       b
419
419
1       4
420
420
DROP TABLE t1,t2;
421
 
CREATE table t1 (  `id` int NOT NULL auto_increment,  `name` varchar(50) NOT NULL default '',  PRIMARY KEY  (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 ;
 
421
CREATE table t1 (  `id` int(11) NOT NULL auto_increment,  `name` varchar(50) NOT NULL default '',  PRIMARY KEY  (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 ;
422
422
INSERT INTO t1 VALUES (1, 'aaaaa');
423
423
INSERT INTO t1 VALUES (3, 'aaaaa');
424
424
INSERT INTO t1 VALUES (2, 'eeeeeee');
428
428
e
429
429
drop  table t1;
430
430
CREATE TABLE t1 (
431
 
ID int NOT NULL auto_increment,
 
431
ID int(11) NOT NULL auto_increment,
432
432
NAME varchar(75) DEFAULT '' NOT NULL,
433
 
LINK_ID int DEFAULT '0' NOT NULL,
 
433
LINK_ID int(11) DEFAULT '0' NOT NULL,
434
434
PRIMARY KEY (ID),
435
435
KEY NAME (NAME),
436
436
KEY LINK_ID (LINK_ID)
439
439
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (2,'Jack',0);
440
440
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (3,'Bill',0);
441
441
CREATE TABLE t2 (
442
 
ID int NOT NULL auto_increment,
 
442
ID int(11) NOT NULL auto_increment,
443
443
NAME varchar(150) DEFAULT '' NOT NULL,
444
444
PRIMARY KEY (ID),
445
445
KEY NAME (NAME)
456
456
drop table t1,t2;
457
457
CREATE TABLE t1 (
458
458
html varchar(5) default NULL,
459
 
rin int default '0',
460
 
rout int default '0'
 
459
rin int(11) default '0',
 
460
rout int(11) default '0'
461
461
) ENGINE=MyISAM;
462
462
INSERT INTO t1 VALUES ('1',1,0);
463
463
SELECT DISTINCT html,SUM(rout)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin;
519
519
EXPLAIN SELECT DISTINCT t1_1.a, t1_1.b FROM t1 t1_1, t1 t1_2
520
520
WHERE t1_1.a = t1_2.a;
521
521
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
522
 
1       SIMPLE  t1_2    index   PRIMARY PRIMARY 4       NULL    3       Using index; Using temporary
523
 
1       SIMPLE  t1_1    ALL     PRIMARY NULL    NULL    NULL    3       Using where; Using join buffer
 
522
1       SIMPLE  t1_1    ALL     PRIMARY NULL    NULL    NULL    3       Using temporary
 
523
1       SIMPLE  t1_2    eq_ref  PRIMARY PRIMARY 4       test.t1_1.a     1       Using index; Distinct
524
524
EXPLAIN SELECT a FROM t1 GROUP BY a;
525
525
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
526
526
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    3       Using index
576
576
2       3
577
577
DROP TABLE t1;
578
578
CREATE TABLE t1 (
579
 
ID int NOT NULL auto_increment,
 
579
ID int(11) NOT NULL auto_increment,
580
580
x varchar(20) default NULL,
581
581
y decimal(10,0) default NULL,
582
582
PRIMARY KEY  (ID),
583
583
KEY (y)
584
 
) ENGINE=MyISAM;
 
584
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
585
585
INSERT INTO t1 VALUES
586
586
(1,'ba','-1'),
587
587
(2,'ba','1150'),
608
608
SELECT DISTINCT a,a FROM t1 WHERE b < 12 ORDER BY a;
609
609
a       a
610
610
DROP TABLE t1;
 
611
CREATE TABLE t1 (a CHAR(1));
 
612
INSERT INTO t1 VALUES('A'), (0);
 
613
SELECT a FROM t1 WHERE a=0;
 
614
a
 
615
A
 
616
0
 
617
Warnings:
 
618
Warning 1292    Truncated incorrect DOUBLE value: 'A'
 
619
SELECT DISTINCT a FROM t1 WHERE a=0;
 
620
a
 
621
A
 
622
0
 
623
Warnings:
 
624
Warning 1292    Truncated incorrect DOUBLE value: 'A'
 
625
DROP TABLE t1;
 
626
CREATE TABLE t1 (a DATE);
 
627
INSERT INTO t1 VALUES ('1972-07-29'), ('1972-02-06');
 
628
EXPLAIN SELECT (SELECT DISTINCT a FROM t1 WHERE a = '2002-08-03');
 
629
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
630
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
631
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    2       Using where
 
632
EXPLAIN SELECT (SELECT DISTINCT ADDDATE(a,1) FROM t1
 
633
WHERE ADDDATE(a,1) = '2002-08-03');
 
634
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
635
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
 
636
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    2       Using where
 
637
CREATE TABLE t2 (a CHAR(5) CHARACTER SET latin1 COLLATE latin1_general_ci);
 
638
INSERT INTO t2 VALUES (0xf6);
 
639
INSERT INTO t2 VALUES ('oe');
 
640
SELECT COUNT(*) FROM (SELECT DISTINCT a FROM t2) dt;
 
641
COUNT(*)
 
642
2
 
643
SELECT COUNT(*) FROM 
 
644
(SELECT DISTINCT a FROM t2 WHERE a='oe' COLLATE latin1_german2_ci) dt;
 
645
COUNT(*)
 
646
2
 
647
DROP TABLE t1, t2;
611
648
CREATE TABLE t1 (a INT, UNIQUE (a));
612
649
INSERT INTO t1 VALUES (4),(null),(2),(1),(null),(3);
613
650
EXPLAIN SELECT DISTINCT a FROM t1;