~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/group_by.test

  • Committer: Monty Taylor
  • Date: 2008-10-10 23:04:21 UTC
  • mto: (509.1.1 codestyle)
  • mto: This revision was merged to the branch mainline in revision 511.
  • Revision ID: monty@inaugust.com-20081010230421-zohe1eppxievpw8d
RemovedĀ O_NOFOLLOW

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#
16
16
 
17
17
CREATE TABLE t1 (
18
 
  spID int,
19
 
  userID int,
20
 
  score int,
 
18
  spID int(10),
 
19
  userID int(10),
 
20
  score int(5),
21
21
  lsg char(40),
22
22
  date date
23
23
);
24
24
 
25
 
INSERT INTO t1 VALUES (1,1,1,'',NULL);
26
 
INSERT INTO t1 VALUES (2,2,2,'',NULL);
27
 
INSERT INTO t1 VALUES (2,1,1,'',NULL);
28
 
INSERT INTO t1 VALUES (3,3,3,'',NULL);
 
25
INSERT INTO t1 VALUES (1,1,1,'','0000-00-00');
 
26
INSERT INTO t1 VALUES (2,2,2,'','0000-00-00');
 
27
INSERT INTO t1 VALUES (2,1,1,'','0000-00-00');
 
28
INSERT INTO t1 VALUES (3,3,3,'','0000-00-00');
29
29
 
30
30
CREATE TABLE t2 (
31
 
  userID int NOT NULL auto_increment,
 
31
  userID int(10) NOT NULL auto_increment,
32
32
  niName char(15),
33
33
  passwd char(8),
34
34
  mail char(50),
61
61
#
62
62
 
63
63
CREATE TABLE t1 (
64
 
  PID int NOT NULL auto_increment,
65
 
  payDate date,
66
 
  recDate datetime,
67
 
  URID int DEFAULT '0' NOT NULL,
68
 
  CRID int DEFAULT '0' NOT NULL,
69
 
  amount int DEFAULT '0' NOT NULL,
70
 
  operator int,
 
64
  PID int(10) NOT NULL auto_increment,
 
65
  payDate date DEFAULT '0000-00-00' NOT NULL,
 
66
  recDate datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
 
67
  URID int(10) DEFAULT '0' NOT NULL,
 
68
  CRID int(10) DEFAULT '0' NOT NULL,
 
69
  amount int(10) DEFAULT '0' NOT NULL,
 
70
  operator int(10),
71
71
  method enum('unknown','cash','dealer','check','card','lazy','delayed','test') DEFAULT 'unknown' NOT NULL,
72
 
  DIID int,
73
 
  reason char(1) DEFAULT '' NOT NULL,
74
 
  code_id int,
75
 
  qty int DEFAULT '0' NOT NULL,
 
72
  DIID int(10),
 
73
  reason char(1) binary DEFAULT '' NOT NULL,
 
74
  code_id int(10),
 
75
  qty mediumint(8) DEFAULT '0' NOT NULL,
76
76
  PRIMARY KEY (PID),
77
77
  KEY URID (URID),
78
78
  KEY reason (reason),
82
82
 
83
83
INSERT INTO t1 VALUES (1,'1970-01-01','1997-10-17 00:00:00',2529,1,21000,11886,'check',0,'F',16200,6);
84
84
 
85
 
--error ER_WRONG_GROUP_FIELD
 
85
--error 1056
86
86
SELECT COUNT(P.URID),SUM(P.amount),P.method, MIN(PP.recdate+0) > 19980501000000   AS IsNew FROM t1 AS P JOIN t1 as PP WHERE P.URID = PP.URID GROUP BY method,IsNew;
87
87
 
88
88
drop table t1;
90
90
#
91
91
# Problem with GROUP BY + ORDER BY when no match
92
92
# Tested with locking
93
 
#  NOTE: LOCK TABLE was removed, so now just testing normal syntax.
94
93
#
95
94
 
96
95
CREATE TABLE t1 (
97
 
  cid int NOT NULL auto_increment,
 
96
  cid mediumint(9) NOT NULL auto_increment,
98
97
  firstname varchar(32) DEFAULT '' NOT NULL,
99
98
  surname varchar(32) DEFAULT '' NOT NULL,
100
99
  PRIMARY KEY (cid)
103
102
INSERT INTO t1 VALUES (2,'Another','Gent');
104
103
 
105
104
CREATE TABLE t2 (
106
 
  call_id int NOT NULL auto_increment,
107
 
  contact_id int DEFAULT '0' NOT NULL,
 
105
  call_id mediumint(8) NOT NULL auto_increment,
 
106
  contact_id mediumint(8) DEFAULT '0' NOT NULL,
108
107
  PRIMARY KEY (call_id),
109
108
  KEY contact_id (contact_id)
110
109
);
111
110
 
 
111
lock tables t1 read,t2 write;
 
112
 
112
113
INSERT INTO t2 VALUES (10,2);
113
114
INSERT INTO t2 VALUES (18,2);
114
115
INSERT INTO t2 VALUES (62,2);
117
118
 
118
119
SELECT cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 ON cid=contact_id WHERE firstname like '%foo%' GROUP BY cid;
119
120
SELECT cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 ON cid=contact_id WHERE firstname like '%foo%' GROUP BY cid ORDER BY NULL;
120
 
SELECT cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 ON cid=contact_id WHERE firstname like '%foo%' GROUP BY cid ORDER BY surname, firstname;
 
121
SELECT HIGH_PRIORITY cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 ON cid=contact_id WHERE firstname like '%foo%' GROUP BY cid ORDER BY surname, firstname;
121
122
 
122
123
drop table t2;
 
124
unlock tables;
123
125
drop table t1;
124
126
 
125
 
# Test needs to be rewritten
126
 
##
127
 
## Test of group by bug in bugzilla
128
 
##
129
 
#
130
 
#CREATE TABLE t1 (
131
 
#  bug_id int NOT NULL auto_increment,
132
 
#  groupset bigint DEFAULT '0' NOT NULL,
133
 
#  assigned_to int DEFAULT '0' NOT NULL,
134
 
#  bug_file_loc text,
135
 
#  bug_severity enum('blocker','critical','major','normal','minor','trivial','enhancement') DEFAULT 'blocker' NOT NULL,
136
 
#  bug_status enum('','NEW','ASSIGNED','REOPENED','RESOLVED','VERIFIED','CLOSED') DEFAULT 'NEW' NOT NULL,
137
 
#  creation_ts datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
138
 
#  delta_ts timestamp,
139
 
#  short_desc mediumtext,
140
 
#  long_desc mediumtext,
141
 
#  op_sys enum('All','Windows 3.1','Windows 95','Windows 98','Windows NT','Windows 2000','Linux','other') DEFAULT 'All' NOT NULL,
142
 
#  priority enum('P1','P2','P3','P4','P5') DEFAULT 'P1' NOT NULL,
143
 
#  product varchar(64) DEFAULT '' NOT NULL,
144
 
#  rep_platform enum('All','PC','VTD-8','Other'),
145
 
#  reporter int DEFAULT '0' NOT NULL,
146
 
#  version varchar(16) DEFAULT '' NOT NULL,
147
 
#  component varchar(50) DEFAULT '' NOT NULL,
148
 
#  resolution enum('','FIXED','INVALID','WONTFIX','LATER','REMIND','DUPLICATE','WORKSFORME') DEFAULT '' NOT NULL,
149
 
#  target_milestone varchar(20) DEFAULT '' NOT NULL,
150
 
#  qa_contact int DEFAULT '0' NOT NULL,
151
 
#  status_whiteboard mediumtext NOT NULL,
152
 
#  votes int DEFAULT '0' NOT NULL,
153
 
#  PRIMARY KEY (bug_id),
154
 
#  KEY assigned_to (assigned_to),
155
 
#  KEY creation_ts (creation_ts),
156
 
#  KEY delta_ts (delta_ts),
157
 
#  KEY bug_severity (bug_severity),
158
 
#  KEY bug_status (bug_status),
159
 
#  KEY op_sys (op_sys),
160
 
#  KEY priority (priority),
161
 
#  KEY product (product),
162
 
#  KEY reporter (reporter),
163
 
#  KEY version (version),
164
 
#  KEY component (component),
165
 
#  KEY resolution (resolution),
166
 
#  KEY target_milestone (target_milestone),
167
 
#  KEY qa_contact (qa_contact),
168
 
#  KEY votes (votes)
169
 
#);
170
 
#
171
 
#--error ER_WARN_DATA_TRUNCATED
172
 
#INSERT INTO t1 VALUES (1,0,0,'','normal','','2000-02-10 09:25:12',20000321114747,'','','Linux','P1','TestProduct','PC',3,'other','TestComponent','','M1',0,'',0);
173
 
#INSERT INTO t1 VALUES (9,0,0,'','enhancement','','2000-03-10 11:49:36',20000321114747,'','','All','P5','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - conversion','','',0,'',0);
174
 
#INSERT INTO t1 VALUES (10,0,0,'','enhancement','','2000-03-10 18:10:16',20000321114747,'','','All','P4','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - conversion','','',0,'',0);
175
 
#INSERT INTO t1 VALUES (7,0,0,'','critical','','2000-03-09 10:50:21',20000321114747,'','','All','P1','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - generic','','',0,'',0);
176
 
#INSERT INTO t1 VALUES (6,0,0,'','normal','','2000-03-09 10:42:44',20000321114747,'','','All','P2','AAAAA','PC',3,'2.00 CD - Pre','kkkkkkkkkkk lllllllllll','','',0,'',0);
177
 
#INSERT INTO t1 VALUES (8,0,0,'','major','','2000-03-09 11:32:14',20000321114747,'','','All','P3','AAAAA','PC',3,'2.00 CD - Pre','kkkkkkkkkkk lllllllllll','','',0,'',0);
178
 
#INSERT INTO t1 VALUES (5,0,0,'','enhancement','','2000-03-09 10:38:59',20000321114747,'','','All','P5','CCC/CCCCCC','PC',5,'7.00','Administration','','',0,'',0);
179
 
#INSERT INTO t1 VALUES (4,0,0,'','normal','','2000-03-08 18:32:14',20000321114747,'','','other','P2','TestProduct','Other',3,'other','TestComponent2','','',0,'',0);
180
 
#INSERT INTO t1 VALUES (3,0,0,'','normal','','2000-03-08 18:30:52',20000321114747,'','','other','P2','TestProduct','Other',3,'other','TestComponent','','',0,'',0);
181
 
#INSERT INTO t1 VALUES (2,0,0,'','enhancement','','2000-03-08 18:24:51',20000321114747,'','','All','P2','TestProduct','Other',4,'other','TestComponent2','','',0,'',0);
182
 
#INSERT INTO t1 VALUES (11,0,0,'','blocker','','2000-03-13 09:43:41',20000321114747,'','','All','P2','CCC/CCCCCC','PC',5,'7.00','DDDDDDDDD','','',0,'',0);
183
 
#INSERT INTO t1 VALUES (12,0,0,'','normal','','2000-03-13 16:14:31',20000321114747,'','','All','P2','AAAAA','PC',3,'2.00 CD - Pre','kkkkkkkkkkk lllllllllll','','',0,'',0);
184
 
#INSERT INTO t1 VALUES (13,0,0,'','normal','','2000-03-15 16:20:44',20000321114747,'','','other','P2','TestProduct','Other',3,'other','TestComponent','','',0,'',0);
185
 
#INSERT INTO t1 VALUES (14,0,0,'','blocker','','2000-03-15 18:13:47',20000321114747,'','','All','P1','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - generic','','',0,'',0);
186
 
#INSERT INTO t1 VALUES (15,0,0,'','minor','','2000-03-16 18:03:28',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','DDDDDDDDD','','',0,'',0);
187
 
#INSERT INTO t1 VALUES (16,0,0,'','normal','','2000-03-16 18:33:41',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
188
 
#INSERT INTO t1 VALUES (17,0,0,'','normal','','2000-03-16 18:34:18',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
189
 
#INSERT INTO t1 VALUES (18,0,0,'','normal','','2000-03-16 18:34:56',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
190
 
#INSERT INTO t1 VALUES (19,0,0,'','enhancement','','2000-03-16 18:35:34',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
191
 
#INSERT INTO t1 VALUES (20,0,0,'','enhancement','','2000-03-16 18:36:23',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
192
 
#INSERT INTO t1 VALUES (21,0,0,'','enhancement','','2000-03-16 18:37:23',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
193
 
#INSERT INTO t1 VALUES (22,0,0,'','enhancement','','2000-03-16 18:38:16',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
194
 
#INSERT INTO t1 VALUES (23,0,0,'','normal','','2000-03-16 18:58:12',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','DDDDDDDDD','','',0,'',0);
195
 
#INSERT INTO t1 VALUES (24,0,0,'','normal','','2000-03-17 11:08:10',20000321114747,'','','All','P2','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0);
196
 
#INSERT INTO t1 VALUES (25,0,0,'','normal','','2000-03-17 11:10:45',20000321114747,'','','All','P2','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0);
197
 
#INSERT INTO t1 VALUES (26,0,0,'','normal','','2000-03-17 11:15:47',20000321114747,'','','All','P2','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0);
198
 
#INSERT INTO t1 VALUES (27,0,0,'','normal','','2000-03-17 17:45:41',20000321114747,'','','All','P2','CCC/CCCCCC','PC',5,'7.00','DDDDDDDDD','','',0,'',0);
199
 
#INSERT INTO t1 VALUES (28,0,0,'','normal','','2000-03-20 09:51:45',20000321114747,'','','Windows NT','P2','TestProduct','PC',8,'other','TestComponent','','',0,'',0);
200
 
#INSERT INTO t1 VALUES (29,0,0,'','normal','','2000-03-20 11:15:09',20000321114747,'','','All','P5','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0);
201
 
#CREATE TABLE t2 (
202
 
#  value text,
203
 
#  program varchar(64),
204
 
#  initialowner text NOT NULL,
205
 
#  initialqacontact text NOT NULL,
206
 
#  description text NOT NULL
207
 
#);
208
 
#
209
 
#INSERT INTO t2 VALUES ('TestComponent','TestProduct','id0001','','');
210
 
#INSERT INTO t2 VALUES ('BBBBBBBBBBBBB - conversion','AAAAA','id0001','','');
211
 
#INSERT INTO t2 VALUES ('BBBBBBBBBBBBB - generic','AAAAA','id0001','','');
212
 
#INSERT INTO t2 VALUES ('TestComponent2','TestProduct','id0001','','');
213
 
#INSERT INTO t2 VALUES ('BBBBBBBBBBBBB - eeeeeeeee','AAAAA','id0001','','');
214
 
#INSERT INTO t2 VALUES ('kkkkkkkkkkk lllllllllll','AAAAA','id0001','','');
215
 
#INSERT INTO t2 VALUES ('Test Procedures','AAAAA','id0001','','');
216
 
#INSERT INTO t2 VALUES ('Documentation','AAAAA','id0003','','');
217
 
#INSERT INTO t2 VALUES ('DDDDDDDDD','CCC/CCCCCC','id0002','','');
218
 
#INSERT INTO t2 VALUES ('Eeeeeeee Lite','CCC/CCCCCC','id0002','','');
219
 
#INSERT INTO t2 VALUES ('Eeeeeeee Full','CCC/CCCCCC','id0002','','');
220
 
#INSERT INTO t2 VALUES ('Administration','CCC/CCCCCC','id0002','','');
221
 
#INSERT INTO t2 VALUES ('Distribution','CCC/CCCCCC','id0002','','');
222
 
#INSERT INTO t2 VALUES ('Setup','CCC/CCCCCC','id0002','','');
223
 
#INSERT INTO t2 VALUES ('Unspecified','CCC/CCCCCC','id0002','','');
224
 
#INSERT INTO t2 VALUES ('Web Interface','AAAAAAAA-AAA','id0001','','');
225
 
#INSERT INTO t2 VALUES ('Host communication','AAAAA','id0001','','');
226
 
#select value,description,bug_id from t2 left join t1 on t2.program=t1.product and t2.value=t1.component where program="AAAAA";
227
 
#select value,description,COUNT(bug_id) from t2 left join t1 on t2.program=t1.product and t2.value=t1.component where program="AAAAA" group by value;
228
 
#select value,description,COUNT(bug_id) from t2 left join t1 on t2.program=t1.product and t2.value=t1.component where program="AAAAA" group by value having COUNT(bug_id) IN (0,2);
229
 
#
230
 
#drop table t1,t2;
 
127
#
 
128
# Test of group by bug in bugzilla
 
129
#
 
130
 
 
131
CREATE TABLE t1 (
 
132
  bug_id mediumint(9) NOT NULL auto_increment,
 
133
  groupset bigint(20) DEFAULT '0' NOT NULL,
 
134
  assigned_to mediumint(9) DEFAULT '0' NOT NULL,
 
135
  bug_file_loc text,
 
136
  bug_severity enum('blocker','critical','major','normal','minor','trivial','enhancement') DEFAULT 'blocker' NOT NULL,
 
137
  bug_status enum('','NEW','ASSIGNED','REOPENED','RESOLVED','VERIFIED','CLOSED') DEFAULT 'NEW' NOT NULL,
 
138
  creation_ts datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
 
139
  delta_ts timestamp,
 
140
  short_desc mediumtext,
 
141
  long_desc mediumtext,
 
142
  op_sys enum('All','Windows 3.1','Windows 95','Windows 98','Windows NT','Windows 2000','Linux','other') DEFAULT 'All' NOT NULL,
 
143
  priority enum('P1','P2','P3','P4','P5') DEFAULT 'P1' NOT NULL,
 
144
  product varchar(64) DEFAULT '' NOT NULL,
 
145
  rep_platform enum('All','PC','VTD-8','Other'),
 
146
  reporter mediumint(9) DEFAULT '0' NOT NULL,
 
147
  version varchar(16) DEFAULT '' NOT NULL,
 
148
  component varchar(50) DEFAULT '' NOT NULL,
 
149
  resolution enum('','FIXED','INVALID','WONTFIX','LATER','REMIND','DUPLICATE','WORKSFORME') DEFAULT '' NOT NULL,
 
150
  target_milestone varchar(20) DEFAULT '' NOT NULL,
 
151
  qa_contact mediumint(9) DEFAULT '0' NOT NULL,
 
152
  status_whiteboard mediumtext NOT NULL,
 
153
  votes mediumint(9) DEFAULT '0' NOT NULL,
 
154
  PRIMARY KEY (bug_id),
 
155
  KEY assigned_to (assigned_to),
 
156
  KEY creation_ts (creation_ts),
 
157
  KEY delta_ts (delta_ts),
 
158
  KEY bug_severity (bug_severity),
 
159
  KEY bug_status (bug_status),
 
160
  KEY op_sys (op_sys),
 
161
  KEY priority (priority),
 
162
  KEY product (product),
 
163
  KEY reporter (reporter),
 
164
  KEY version (version),
 
165
  KEY component (component),
 
166
  KEY resolution (resolution),
 
167
  KEY target_milestone (target_milestone),
 
168
  KEY qa_contact (qa_contact),
 
169
  KEY votes (votes)
 
170
);
 
171
 
 
172
INSERT INTO t1 VALUES (1,0,0,'','normal','','2000-02-10 09:25:12',20000321114747,'','','Linux','P1','TestProduct','PC',3,'other','TestComponent','','M1',0,'',0);
 
173
INSERT INTO t1 VALUES (9,0,0,'','enhancement','','2000-03-10 11:49:36',20000321114747,'','','All','P5','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - conversion','','',0,'',0);
 
174
INSERT INTO t1 VALUES (10,0,0,'','enhancement','','2000-03-10 18:10:16',20000321114747,'','','All','P4','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - conversion','','',0,'',0);
 
175
INSERT INTO t1 VALUES (7,0,0,'','critical','','2000-03-09 10:50:21',20000321114747,'','','All','P1','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - generic','','',0,'',0);
 
176
INSERT INTO t1 VALUES (6,0,0,'','normal','','2000-03-09 10:42:44',20000321114747,'','','All','P2','AAAAA','PC',3,'2.00 CD - Pre','kkkkkkkkkkk lllllllllll','','',0,'',0);
 
177
INSERT INTO t1 VALUES (8,0,0,'','major','','2000-03-09 11:32:14',20000321114747,'','','All','P3','AAAAA','PC',3,'2.00 CD - Pre','kkkkkkkkkkk lllllllllll','','',0,'',0);
 
178
INSERT INTO t1 VALUES (5,0,0,'','enhancement','','2000-03-09 10:38:59',20000321114747,'','','All','P5','CCC/CCCCCC','PC',5,'7.00','Administration','','',0,'',0);
 
179
INSERT INTO t1 VALUES (4,0,0,'','normal','','2000-03-08 18:32:14',20000321114747,'','','other','P2','TestProduct','Other',3,'other','TestComponent2','','',0,'',0);
 
180
INSERT INTO t1 VALUES (3,0,0,'','normal','','2000-03-08 18:30:52',20000321114747,'','','other','P2','TestProduct','Other',3,'other','TestComponent','','',0,'',0);
 
181
INSERT INTO t1 VALUES (2,0,0,'','enhancement','','2000-03-08 18:24:51',20000321114747,'','','All','P2','TestProduct','Other',4,'other','TestComponent2','','',0,'',0);
 
182
INSERT INTO t1 VALUES (11,0,0,'','blocker','','2000-03-13 09:43:41',20000321114747,'','','All','P2','CCC/CCCCCC','PC',5,'7.00','DDDDDDDDD','','',0,'',0);
 
183
INSERT INTO t1 VALUES (12,0,0,'','normal','','2000-03-13 16:14:31',20000321114747,'','','All','P2','AAAAA','PC',3,'2.00 CD - Pre','kkkkkkkkkkk lllllllllll','','',0,'',0);
 
184
INSERT INTO t1 VALUES (13,0,0,'','normal','','2000-03-15 16:20:44',20000321114747,'','','other','P2','TestProduct','Other',3,'other','TestComponent','','',0,'',0);
 
185
INSERT INTO t1 VALUES (14,0,0,'','blocker','','2000-03-15 18:13:47',20000321114747,'','','All','P1','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - generic','','',0,'',0);
 
186
INSERT INTO t1 VALUES (15,0,0,'','minor','','2000-03-16 18:03:28',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','DDDDDDDDD','','',0,'',0);
 
187
INSERT INTO t1 VALUES (16,0,0,'','normal','','2000-03-16 18:33:41',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
 
188
INSERT INTO t1 VALUES (17,0,0,'','normal','','2000-03-16 18:34:18',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
 
189
INSERT INTO t1 VALUES (18,0,0,'','normal','','2000-03-16 18:34:56',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
 
190
INSERT INTO t1 VALUES (19,0,0,'','enhancement','','2000-03-16 18:35:34',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
 
191
INSERT INTO t1 VALUES (20,0,0,'','enhancement','','2000-03-16 18:36:23',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
 
192
INSERT INTO t1 VALUES (21,0,0,'','enhancement','','2000-03-16 18:37:23',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
 
193
INSERT INTO t1 VALUES (22,0,0,'','enhancement','','2000-03-16 18:38:16',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
 
194
INSERT INTO t1 VALUES (23,0,0,'','normal','','2000-03-16 18:58:12',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','DDDDDDDDD','','',0,'',0);
 
195
INSERT INTO t1 VALUES (24,0,0,'','normal','','2000-03-17 11:08:10',20000321114747,'','','All','P2','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0);
 
196
INSERT INTO t1 VALUES (25,0,0,'','normal','','2000-03-17 11:10:45',20000321114747,'','','All','P2','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0);
 
197
INSERT INTO t1 VALUES (26,0,0,'','normal','','2000-03-17 11:15:47',20000321114747,'','','All','P2','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0);
 
198
INSERT INTO t1 VALUES (27,0,0,'','normal','','2000-03-17 17:45:41',20000321114747,'','','All','P2','CCC/CCCCCC','PC',5,'7.00','DDDDDDDDD','','',0,'',0);
 
199
INSERT INTO t1 VALUES (28,0,0,'','normal','','2000-03-20 09:51:45',20000321114747,'','','Windows NT','P2','TestProduct','PC',8,'other','TestComponent','','',0,'',0);
 
200
INSERT INTO t1 VALUES (29,0,0,'','normal','','2000-03-20 11:15:09',20000321114747,'','','All','P5','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0);
 
201
CREATE TABLE t2 (
 
202
  value tinytext,
 
203
  program varchar(64),
 
204
  initialowner tinytext NOT NULL,
 
205
  initialqacontact tinytext NOT NULL,
 
206
  description mediumtext NOT NULL
 
207
);
 
208
 
 
209
INSERT INTO t2 VALUES ('TestComponent','TestProduct','id0001','','');
 
210
INSERT INTO t2 VALUES ('BBBBBBBBBBBBB - conversion','AAAAA','id0001','','');
 
211
INSERT INTO t2 VALUES ('BBBBBBBBBBBBB - generic','AAAAA','id0001','','');
 
212
INSERT INTO t2 VALUES ('TestComponent2','TestProduct','id0001','','');
 
213
INSERT INTO t2 VALUES ('BBBBBBBBBBBBB - eeeeeeeee','AAAAA','id0001','','');
 
214
INSERT INTO t2 VALUES ('kkkkkkkkkkk lllllllllll','AAAAA','id0001','','');
 
215
INSERT INTO t2 VALUES ('Test Procedures','AAAAA','id0001','','');
 
216
INSERT INTO t2 VALUES ('Documentation','AAAAA','id0003','','');
 
217
INSERT INTO t2 VALUES ('DDDDDDDDD','CCC/CCCCCC','id0002','','');
 
218
INSERT INTO t2 VALUES ('Eeeeeeee Lite','CCC/CCCCCC','id0002','','');
 
219
INSERT INTO t2 VALUES ('Eeeeeeee Full','CCC/CCCCCC','id0002','','');
 
220
INSERT INTO t2 VALUES ('Administration','CCC/CCCCCC','id0002','','');
 
221
INSERT INTO t2 VALUES ('Distribution','CCC/CCCCCC','id0002','','');
 
222
INSERT INTO t2 VALUES ('Setup','CCC/CCCCCC','id0002','','');
 
223
INSERT INTO t2 VALUES ('Unspecified','CCC/CCCCCC','id0002','','');
 
224
INSERT INTO t2 VALUES ('Web Interface','AAAAAAAA-AAA','id0001','','');
 
225
INSERT INTO t2 VALUES ('Host communication','AAAAA','id0001','','');
 
226
select value,description,bug_id from t2 left join t1 on t2.program=t1.product and t2.value=t1.component where program="AAAAA";
 
227
select value,description,COUNT(bug_id) from t2 left join t1 on t2.program=t1.product and t2.value=t1.component where program="AAAAA" group by value;
 
228
select value,description,COUNT(bug_id) from t2 left join t1 on t2.program=t1.product and t2.value=t1.component where program="AAAAA" group by value having COUNT(bug_id) IN (0,2);
 
229
 
 
230
drop table t1,t2;
231
231
 
232
232
#
233
233
# Problem with functions and group functions when no matching rows
244
244
# Test GROUP BY DESC
245
245
 
246
246
CREATE TABLE t1 (
247
 
  spID int,
248
 
  userID int,
249
 
  score int,
 
247
  spID int(10),
 
248
  userID int(10),
 
249
  score int(5),
250
250
  key (spid),
251
251
  key (score)
252
252
);
283
283
INSERT INTO t1 VALUES ('A'),('B'),('A'),('B'),('A'),('B'),(NULL),('a'),('b'),(NULL),('A'),('B'),(NULL);
284
284
SELECT a FROM t1 GROUP BY a;
285
285
SELECT a,count(*) FROM t1 GROUP BY a;
286
 
SELECT a FROM t1 GROUP BY a;
287
 
SELECT a,count(*) FROM t1 GROUP BY a;
288
 
SELECT a FROM t1 GROUP BY 1;
289
 
SELECT a,count(*) FROM t1 GROUP BY 1;
 
286
SELECT a FROM t1 GROUP BY binary a;
 
287
SELECT a,count(*) FROM t1 GROUP BY binary a;
 
288
SELECT binary a FROM t1 GROUP BY 1;
 
289
SELECT binary a,count(*) FROM t1 GROUP BY 1;
290
290
# Do the same tests with MyISAM temporary tables
291
 
SELECT a FROM t1 GROUP BY a;
292
 
SELECT a,count(*) FROM t1 GROUP BY a;
293
 
SELECT a FROM t1 GROUP BY a;
294
 
SELECT a,count(*) FROM t1 GROUP BY a;
295
 
SELECT a FROM t1 GROUP BY 1;
296
 
SELECT a,count(*) FROM t1 GROUP BY 1;
 
291
SET SQL_BIG_TABLES=1;
 
292
SELECT a FROM t1 GROUP BY a;
 
293
SELECT a,count(*) FROM t1 GROUP BY a;
 
294
SELECT a FROM t1 GROUP BY binary a;
 
295
SELECT a,count(*) FROM t1 GROUP BY binary a;
 
296
SELECT binary a FROM t1 GROUP BY 1;
 
297
SELECT binary a,count(*) FROM t1 GROUP BY 1;
 
298
SET SQL_BIG_TABLES=0;
297
299
drop table t1;
298
300
 
299
301
#
345
347
# Problem with MAX and LEFT JOIN
346
348
#
347
349
 
348
 
CREATE TEMPORARY TABLE t1 (
349
 
  pid int NOT NULL default '0',
350
 
  c1id int default NULL,
351
 
  c2id int default NULL,
352
 
  value int NOT NULL default '0',
 
350
CREATE TABLE t1 (
 
351
  pid int(11) NOT NULL default '0',
 
352
  c1id int(11) default NULL,
 
353
  c2id int(11) default NULL,
 
354
  value int(11) NOT NULL default '0',
353
355
  UNIQUE KEY pid2 (pid,c1id,c2id),
354
356
  UNIQUE KEY pid (pid,value)
355
357
) ENGINE=MyISAM;
356
358
 
357
359
INSERT INTO t1 VALUES (1, 1, NULL, 1),(1, 2, NULL, 2),(1, NULL, 3, 3),(1, 4, NULL, 4),(1, 5, NULL, 5);
358
360
 
359
 
CREATE TEMPORARY TABLE t2 (
360
 
  id int NOT NULL default '0',
 
361
CREATE TABLE t2 (
 
362
  id int(11) NOT NULL default '0',
361
363
  active enum('Yes','No') NOT NULL default 'Yes',
362
364
  PRIMARY KEY  (id)
363
365
) ENGINE=MyISAM;
365
367
INSERT INTO t2 VALUES (1, 'Yes'),(2, 'No'),(4, 'Yes'),(5, 'No');
366
368
 
367
369
CREATE TABLE t3 (
368
 
  id int NOT NULL default '0',
 
370
  id int(11) NOT NULL default '0',
369
371
  active enum('Yes','No') NOT NULL default 'Yes',
370
372
  PRIMARY KEY  (id)
371
373
);
387
389
create table t1 (a blob null);
388
390
insert into t1 values (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(""),(""),(""),("b");
389
391
select a,count(*) from t1 group by a;
 
392
set option sql_big_tables=1;
390
393
select a,count(*) from t1 group by a;
391
394
drop table t1;
392
395
 
400
403
insert into t2 values (1,3),(3,1),(2,2),(1,1);
401
404
select t1.a,t2.b from t1,t2 where t1.a=t2.a group by t1.a,t2.b;
402
405
select t1.a,t2.b from t1,t2 where t1.a=t2.a group by t1.a,t2.b ORDER BY NULL;
403
 
--sorted_result
404
406
explain select t1.a,t2.b from t1,t2 where t1.a=t2.a group by t1.a,t2.b;
405
 
--sorted_result
406
407
explain select t1.a,t2.b from t1,t2 where t1.a=t2.a group by t1.a,t2.b ORDER BY NULL;
407
408
drop table t1,t2;
408
409
 
438
439
# NULL is used.
439
440
#
440
441
CREATE TABLE t1 (
441
 
  userid int,
442
 
  score int,
 
442
  userid int(10),
 
443
  score int(5),
443
444
  key (score)
444
445
);
445
446
INSERT INTO t1 VALUES (1,1),(2,2),(1,1),(3,3),(3,3),(3,3),(3,3),(3,3);
450
451
EXPLAIN SELECT userid,count(*) FROM t1 GROUP BY userid DESC;
451
452
DROP TABLE t1;
452
453
CREATE TABLE t1 (
453
 
  i int default NULL,
454
 
  j int default NULL
 
454
  i int(11) default NULL,
 
455
  j int(11) default NULL
455
456
);
456
457
INSERT INTO t1 VALUES (1,2),(2,3),(4,5),(3,5),(1,5),(23,5);
457
458
SELECT i, COUNT(DISTINCT(i)) FROM t1 GROUP BY j ORDER BY NULL;
501
502
  d varchar(100) NOT NULL,
502
503
  primary key (a,b(132),c,d),
503
504
  key a (a,b)
504
 
);
 
505
) charset=utf8;
505
506
 
506
507
insert into t2 select 
507
508
   x3.a,  -- 3
512
513
 
513
514
delete from t2  where a = 2 and b = 'val-2' order by a,b,c,d limit 30;
514
515
 
515
 
--replace_column 4 # 7 # 9 # 10 #
516
516
explain select c from t2 where a = 2 and b = 'val-2' group by c;
517
517
select c from t2 where a = 2 and b = 'val-2' group by c;
518
518
drop table t1,t2;
520
520
# Test for BUG#9298 "Wrong handling of int4 columns in GROUP functions"
521
521
# (the actual problem was with protocol code, not GROUP BY)
522
522
create table t1 (b int4 not null);
523
 
insert into t1 values(300000);
 
523
insert into t1 values(3000000000);
524
524
select * from t1;
525
525
select min(b) from t1;
526
526
drop table t1;
637
637
# returns empty
638
638
639
639
CREATE TABLE t1 (
640
 
    f1 int NOT NULL auto_increment primary key,
 
640
    f1 int(10) NOT NULL auto_increment primary key,
641
641
    f2 varchar(100) NOT NULL default ''
642
642
);
643
643
CREATE TABLE t2 (
956
956
EXPLAIN SELECT 1 FROM t2 WHERE a IN
957
957
  (SELECT a FROM t1 USE INDEX (i2) IGNORE INDEX (i2));
958
958
 
 
959
SHOW VARIABLES LIKE 'old';  
 
960
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
 
961
SET @@old = off;  
 
962
 
959
963
DROP TABLE t1, t2;
960
964
 
961
965
#
1000
1004
EXPLAIN SELECT b from t2 GROUP BY b;
1001
1005
SELECT b from t2 GROUP BY b;
1002
1006
 
1003
 
DROP TABLE t1,t2;
 
1007
DROP TABLE t1;
1004
1008
 
1005
1009
#
1006
1010
# Bug #31797: error while parsing subqueries -- WHERE is parsed as HAVING