~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/distinct.result

  • Committer: Monty Taylor
  • Date: 2008-11-16 05:36:13 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116053613-bld4rqxhlkb49c02
Split out cache_row and type_holder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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 where; Using index
 
178
1       SIMPLE  t3      ref     a       a       5       test.t1.b       1       Using index
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 where; Using index; Distinct
 
193
1       SIMPLE  t3      ref     a       a       5       test.t1.a       1       Using index; Distinct
194
194
select distinct t1.a from t1,t3 where t1.a=t3.a;
195
195
a
196
196
1
197
197
2
198
 
show status like 'Handler%';
199
 
Variable_name   Value
200
 
Handler_commit  #
201
 
Handler_delete  #
202
 
Handler_prepare #
203
 
Handler_read_first      #
204
 
Handler_read_key        #
205
 
Handler_read_next       #
206
 
Handler_read_prev       #
207
 
Handler_read_rnd        #
208
 
Handler_read_rnd_next   #
209
 
Handler_rollback        #
210
 
Handler_savepoint       #
211
 
Handler_savepoint_rollback      #
212
 
Handler_update  #
213
 
Handler_write   #
214
 
flush status;
215
198
select distinct 1 from t1,t3 where t1.a=t3.a;
216
199
1
217
200
1
218
 
show status like 'Handler%';
219
 
Variable_name   Value
220
 
Handler_commit  #
221
 
Handler_delete  #
222
 
Handler_prepare #
223
 
Handler_read_first      #
224
 
Handler_read_key        #
225
 
Handler_read_next       #
226
 
Handler_read_prev       #
227
 
Handler_read_rnd        #
228
 
Handler_read_rnd_next   #
229
 
Handler_rollback        #
230
 
Handler_savepoint       #
231
 
Handler_savepoint_rollback      #
232
 
Handler_update  #
233
 
Handler_write   #
234
201
explain SELECT distinct t1.a from t1;
235
202
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
236
203
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    4       Using index
359
326
id
360
327
2
361
328
drop table t1,t2,t3;
 
329
create table t1 (a int not null, b int not null, t time);
 
330
insert into t1 values (1,1,"00:06:15"),(1,2,"00:06:15"),(1,2,"00:30:15"),(1,3,"00:06:15"),(1,3,"00:30:15");
 
331
select a,sec_to_time(sum(time_to_sec(t))) from t1 group by a,b;
 
332
a       sec_to_time(sum(time_to_sec(t)))
 
333
1       00:06:15
 
334
1       00:36:30
 
335
1       00:36:30
 
336
select distinct a,sec_to_time(sum(time_to_sec(t))) from t1 group by a,b;
 
337
a       sec_to_time(sum(time_to_sec(t)))
 
338
1       00:06:15
 
339
1       00:36:30
 
340
create table t2 (a int not null primary key, b int);
 
341
insert into t2 values (1,1),(2,2),(3,3);
 
342
select t1.a,sec_to_time(sum(time_to_sec(t))) from t1 left join t2 on (t1.b=t2.a) group by t1.a,t2.b;
 
343
a       sec_to_time(sum(time_to_sec(t)))
 
344
1       00:06:15
 
345
1       00:36:30
 
346
1       00:36:30
 
347
select distinct t1.a,sec_to_time(sum(time_to_sec(t))) from t1 left join t2 on (t1.b=t2.a) group by t1.a,t2.b;
 
348
a       sec_to_time(sum(time_to_sec(t)))
 
349
1       00:06:15
 
350
1       00:36:30
 
351
drop table t1,t2;
362
352
create table t1 (a int not null,b char(5), c text);
363
353
insert into t1 (a) values (1),(2),(3),(4),(1),(2),(3),(4);
364
354
select distinct a from t1 group by b,a having a > 2 order by a desc;
370
360
4       NULL
371
361
3       NULL
372
362
drop table t1;
373
 
create table t1 (a char(1), key(a));
 
363
create table t1 (a char(1), key(a)) engine=myisam;
374
364
insert into t1 values('1'),('1');
375
365
select * from t1 where a >= '1';
376
366
a
397
387
SELECT DISTINCTROW email, shipcode FROM t1, t2 WHERE t1.infoID=t2.infoID;
398
388
email   shipcode
399
389
test1@testdomain.com    Z001
 
390
test2@testdomain.com    Z001
400
391
test2@testdomain.com    R002
401
 
test2@testdomain.com    Z001
402
392
test3@testdomain.com    Z001
403
393
SELECT DISTINCTROW email FROM t1 ORDER BY dateentered DESC;
404
394
email
412
402
test2@testdomain.com    R002
413
403
test3@testdomain.com    Z001
414
404
drop table t1,t2;
415
 
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));
 
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;
416
406
INSERT INTO t1 VALUES (128,0,33,33,8,':D','',996121863,1,0,2,996122850,2,0,0);
417
 
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 NULL,  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));
418
 
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,NULL,-1,1,'64.0.0.0',0,1,-1,0,0,4,19,1);
 
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;
 
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);
419
409
SELECT DISTINCT t1.*, t2.* FROM t1 LEFT JOIN t2 ON (t2.userid = t1.touserid);
420
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
421
 
128     0       33      33      8       :D              996121863       1       0       2       996122850       2       0       0       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      NULL    -1      1       64.0.0.0        0       1       -1      0       0       4       19      1
 
411
128     0       33      33      8       :D              996121863       1       0       2       996122850       2       0       0       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
422
412
DROP TABLE t1,t2;
423
413
CREATE TABLE t1 (a int primary key, b int, c int);
424
414
INSERT t1 VALUES (1,2,3);
428
418
a       b
429
419
1       4
430
420
DROP TABLE t1,t2;
431
 
CREATE table t1 (  `id` int NOT NULL auto_increment,  `name` varchar(50) NOT NULL default '',  PRIMARY KEY  (`id`)) AUTO_INCREMENT=3 ;
 
421
CREATE table t1 (  `id` int NOT NULL auto_increment,  `name` varchar(50) NOT NULL default '',  PRIMARY KEY  (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 ;
432
422
INSERT INTO t1 VALUES (1, 'aaaaa');
433
423
INSERT INTO t1 VALUES (3, 'aaaaa');
434
424
INSERT INTO t1 VALUES (2, 'eeeeeee');
468
458
html varchar(5) default NULL,
469
459
rin int default '0',
470
460
rout int default '0'
471
 
);
 
461
) ENGINE=MyISAM;
472
462
INSERT INTO t1 VALUES ('1',1,0);
473
463
SELECT DISTINCT html,SUM(rout)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin;
474
464
html    prod
523
513
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
524
514
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    3       
525
515
EXPLAIN SELECT DISTINCT t1_1.a, t1_1.b FROM t1 t1_1, t1 t1_2;
526
 
ERROR HY000: Implicit cartesian join attempted.
 
516
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
517
1       SIMPLE  t1_1    ALL     NULL    NULL    NULL    NULL    3       Using temporary
 
518
1       SIMPLE  t1_2    index   NULL    PRIMARY 4       NULL    3       Using index; Distinct; Using join buffer
527
519
EXPLAIN SELECT DISTINCT t1_1.a, t1_1.b FROM t1 t1_1, t1 t1_2
528
520
WHERE t1_1.a = t1_2.a;
529
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
530
523
1       SIMPLE  t1_1    ALL     PRIMARY NULL    NULL    NULL    3       Using where; Using join buffer
531
 
1       SIMPLE  t1_2    index   PRIMARY PRIMARY 4       NULL    3       Using index; Using temporary
532
524
EXPLAIN SELECT a FROM t1 GROUP BY a;
533
525
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
534
526
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    3       Using index
589
581
y decimal(10,0) default NULL,
590
582
PRIMARY KEY  (ID),
591
583
KEY (y)
592
 
);
 
584
) ENGINE=MyISAM;
593
585
INSERT INTO t1 VALUES
594
586
(1,'ba','-1'),
595
587
(2,'ba','1150'),
653
645
1       1       3
654
646
DROP TABLE t1;
655
647
End of 5.0 tests
656
 
CREATE TABLE t1(a INT, b INT, c INT, d INT DEFAULT 0, e INT DEFAULT 0,
 
648
CREATE TABLE t1(a INT, b INT, c INT, d INT, e INT,
657
649
PRIMARY KEY(a,b,c,d,e),
658
650
KEY(a,b,d,c)
659
651
);