~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/distinct.test

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