~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/distinct.test

  • Committer: Daniel Nichter
  • Date: 2011-10-23 16:01:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2448.
  • Revision ID: daniel@percona.com-20111023160137-7ac3blgz8z4tf8za
Add Administration Getting Started and Logging.  Capitalize SQL clause keywords.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
explain select distinct t1.a from t1,t3 where t1.a=t3.a;
87
87
#flush status;
88
88
select distinct t1.a from t1,t3 where t1.a=t3.a;
89
 
#show status like 'Handler%';
90
 
#flush status;
 
89
--replace_column 2 #
 
90
show status like 'Handler%';
 
91
flush status;
91
92
select distinct 1 from t1,t3 where t1.a=t3.a;
92
 
#show status like 'Handler%';
 
93
--replace_column 2 #
 
94
show status like 'Handler%';
93
95
 
94
96
explain SELECT distinct t1.a from t1;
95
97
explain SELECT distinct t1.a from t1 order by a desc;
196
198
drop table t1,t2,t3;
197
199
 
198
200
#
199
 
# Test using DISTINCT on a function that contains a group function
200
 
# This also test the case when one doesn't use all fields in GROUP BY.
201
 
#
202
 
 
203
 
create table t1 (a int not null, b int not null, t time);
204
 
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");
205
 
select a,sec_to_time(sum(time_to_sec(t))) from t1 group by a,b;
206
 
select distinct a,sec_to_time(sum(time_to_sec(t))) from t1 group by a,b;
207
 
create table t2 (a int not null primary key, b int);
208
 
insert into t2 values (1,1),(2,2),(3,3);
209
 
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;
210
 
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;
211
 
drop table t1,t2;
212
 
 
213
 
#
214
201
# Test problem with DISTINCT and HAVING
215
202
#
216
203
create table t1 (a int not null,b char(5), c text);
223
210
# Test problem with DISTINCT and ORDER BY DESC
224
211
#
225
212
 
226
 
create table t1 (a char(1), key(a)) engine=myisam;
 
213
create table t1 (a char(1), key(a));
227
214
insert into t1 values('1'),('1');
228
215
select * from t1 where a >= '1'; 
229
216
select distinct a from t1 order by a desc;
248
235
      (1, 'Z001'),
249
236
      (2, 'R002');
250
237
 
 
238
--sorted_result
251
239
SELECT DISTINCTROW email, shipcode FROM t1, t2 WHERE t1.infoID=t2.infoID;
252
240
SELECT DISTINCTROW email FROM t1 ORDER BY dateentered DESC;
253
241
SELECT DISTINCTROW email, shipcode FROM t1, t2 WHERE t1.infoID=t2.infoID ORDER BY dateentered DESC;
257
245
# test with table.* in DISTINCT
258
246
#
259
247
 
260
 
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;
 
248
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));
261
249
INSERT INTO t1 VALUES (128,0,33,33,8,':D','',996121863,1,0,2,996122850,2,0,0);
262
 
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;
263
 
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);
 
250
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));
 
251
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);
264
252
SELECT DISTINCT t1.*, t2.* FROM t1 LEFT JOIN t2 ON (t2.userid = t1.touserid);
265
253
DROP TABLE t1,t2;
266
254
 
279
267
# Test of LEFT() with distinct
280
268
#
281
269
 
282
 
CREATE table t1 (  `id` int NOT NULL auto_increment,  `name` varchar(50) NOT NULL default '',  PRIMARY KEY  (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 ;
 
270
CREATE table t1 (  `id` int NOT NULL auto_increment,  `name` varchar(50) NOT NULL default '',  PRIMARY KEY  (`id`)) AUTO_INCREMENT=3 ;
283
271
INSERT INTO t1 VALUES (1, 'aaaaa');
284
272
INSERT INTO t1 VALUES (3, 'aaaaa');
285
273
INSERT INTO t1 VALUES (2, 'eeeeeee');
327
315
  html varchar(5) default NULL,
328
316
  rin int default '0',
329
317
  rout int default '0'
330
 
) ENGINE=MyISAM;
 
318
);
331
319
 
332
320
INSERT INTO t1 VALUES ('1',1,0);
333
321
SELECT DISTINCT html,SUM(rout)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin;
357
345
INSERT INTO t1 VALUES (1,1), (2,1), (3,1);
358
346
EXPLAIN SELECT DISTINCT a FROM t1;
359
347
EXPLAIN SELECT DISTINCT a,b FROM t1;
 
348
--error ER_CARTESIAN_JOIN_ATTEMPTED
360
349
EXPLAIN SELECT DISTINCT t1_1.a, t1_1.b FROM t1 t1_1, t1 t1_2;
 
350
--sorted_result
361
351
EXPLAIN SELECT DISTINCT t1_1.a, t1_1.b FROM t1 t1_1, t1 t1_2
362
352
  WHERE t1_1.a = t1_2.a;
363
353
EXPLAIN SELECT a FROM t1 GROUP BY a;
409
399
  y decimal(10,0) default NULL,
410
400
  PRIMARY KEY  (ID),
411
401
  KEY (y)
412
 
) ENGINE=MyISAM;
 
402
);
413
403
 
414
404
INSERT INTO t1 VALUES
415
405
(1,'ba','-1'),
469
459
#
470
460
# Bug #34928: Confusion by having Primary Key and Index
471
461
#
472
 
CREATE TABLE t1(a INT, b INT, c INT, d INT, e INT,
 
462
CREATE TABLE t1(a INT, b INT, c INT, d INT DEFAULT 0, e INT DEFAULT 0,
473
463
                PRIMARY KEY(a,b,c,d,e),
474
464
                KEY(a,b,d,c)
475
465
);