summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/storage_engine/type_date_time_indexes.result
blob: f259aea2cc4acce5c0f0d2dd6749924c4dd51d44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (d DATE <CUSTOM_COL_OPTIONS>,
dt DATETIME <CUSTOM_COL_OPTIONS>,
ts TIMESTAMP <CUSTOM_COL_OPTIONS>,
t TIME <CUSTOM_COL_OPTIONS>,
y YEAR <CUSTOM_COL_OPTIONS>,
<CUSTOM_INDEX> d (d)
) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW INDEX IN t1;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t1	1	#	1	d	#	#	NULL	NULL	#	#		
SET @tm = '2012-04-09 05:27:00';
INSERT INTO t1 (d,dt,ts,t,y) VALUES
('2012-01-12', '2010-11-22 12:33:54', '2011-11-14 21:45:55', '00:12:33', '2000'),
('2012-01-22', '2010-11-22 11:43:14', '2011-11-14 21:45:55', '00:12:32', '2001'),
('2012-03-31', '2011-08-28 21:33:56', '1999-04-30 19:11:08', '12:00:00', '1999'),
('2012-03-13', '2011-08-27 21:33:56', '1999-03-30 19:11:08', '12:10:00', '1998'),
('2011-03-31', '2011-08-28 20:33:56', '1997-01-31 11:54:01', '22:04:10', '1994'),
(DATE(@tm),@tm,TIMESTAMP(@tm),TIME(@tm),YEAR(@tm));
SELECT d FROM t1 ORDER BY d LIMIT 3;
d
2011-03-31
2012-01-12
2012-01-22
DROP TABLE t1;
CREATE TABLE t1 (d DATE <CUSTOM_COL_OPTIONS>,
dt DATETIME <CUSTOM_COL_OPTIONS>,
ts TIMESTAMP <CUSTOM_COL_OPTIONS>,
t TIME <CUSTOM_COL_OPTIONS>,
y YEAR <CUSTOM_COL_OPTIONS>,
<CUSTOM_INDEX> dt (dt)
) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW INDEX IN t1;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t1	1	#	1	dt	#	#	NULL	NULL	#	#		
SET @tm = '2012-04-09 05:27:00';
INSERT INTO t1 (d,dt,ts,t,y) VALUES
('2012-01-12', '2010-11-22 12:33:54', '2011-11-14 21:45:55', '00:12:33', '2000'),
('2012-01-12', '2010-11-22 11:43:14', '2011-11-14 21:45:55', '00:12:32', '2001'),
('2012-03-31', '2011-08-28 21:33:56', '1999-04-30 19:11:08', '12:00:00', '1999'),
('2012-03-13', '2011-08-27 21:33:56', '1999-03-30 19:11:08', '12:10:00', '1998'),
('2011-03-31', '2011-08-28 20:33:56', '1997-01-31 11:54:01', '22:04:10', '1994'),
(DATE(@tm),@tm,TIMESTAMP(@tm),TIME(@tm),YEAR(@tm));
SELECT dt FROM t1 ORDER BY dt LIMIT 3;
dt
2010-11-22 11:43:14
2010-11-22 12:33:54
2011-08-27 21:33:56
DROP TABLE t1;
CREATE TABLE t1 (d DATE <CUSTOM_COL_OPTIONS>,
dt DATETIME <CUSTOM_COL_OPTIONS>,
ts TIMESTAMP <CUSTOM_COL_OPTIONS>,
t TIME <CUSTOM_COL_OPTIONS>,
y YEAR <CUSTOM_COL_OPTIONS>,
<CUSTOM_INDEX> ts (ts)
) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW INDEX IN t1;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t1	1	#	1	ts	#	#	NULL	NULL	#	#		
SET @tm = '2012-04-09 05:27:00';
INSERT INTO t1 (d,dt,ts,t,y) VALUES
('2012-01-12', '2010-11-22 12:33:54', '2011-11-14 21:45:25', '00:12:33', '2000'),
('2012-01-12', '2010-11-22 11:43:14', '2011-11-14 21:45:55', '00:12:32', '2001'),
('2012-03-31', '2011-08-28 21:33:56', '1999-04-30 19:11:08', '12:00:00', '1999'),
('2012-03-13', '2011-08-27 21:33:56', '1999-03-30 19:11:08', '12:10:00', '1998'),
('2011-03-31', '2011-08-28 20:33:56', '1997-01-31 11:54:01', '22:04:10', '1994'),
(DATE(@tm),@tm,TIMESTAMP(@tm),TIME(@tm),YEAR(@tm));
SELECT ts FROM t1 ORDER BY ts LIMIT 3;
ts
1997-01-31 11:54:01
1999-03-30 19:11:08
1999-04-30 19:11:08
DROP TABLE t1;
CREATE TABLE t1 (d DATE <CUSTOM_COL_OPTIONS>,
dt DATETIME <CUSTOM_COL_OPTIONS>,
ts TIMESTAMP <CUSTOM_COL_OPTIONS>,
t TIME <CUSTOM_COL_OPTIONS>,
y YEAR <CUSTOM_COL_OPTIONS>,
<CUSTOM_INDEX> t (t)
) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW INDEX IN t1;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t1	1	#	1	t	#	#	NULL	NULL	#	#		
SET @tm = '2012-04-09 05:27:00';
INSERT INTO t1 (d,dt,ts,t,y) VALUES
('2012-01-12', '2010-11-22 12:33:54', '2011-11-14 21:45:25', '00:12:33', '2000'),
('2012-01-12', '2010-11-22 11:43:14', '2011-11-14 21:45:55', '00:12:32', '2001'),
('2012-03-31', '2011-08-28 21:33:56', '1999-04-30 19:11:08', '12:00:00', '1999'),
('2012-03-13', '2011-08-27 21:33:56', '1999-03-30 19:11:08', '12:10:00', '1998'),
('2011-03-31', '2011-08-28 20:33:56', '1997-01-31 11:54:01', '22:04:10', '1994'),
(DATE(@tm),@tm,TIMESTAMP(@tm),TIME(@tm),YEAR(@tm));
SELECT t FROM t1 ORDER BY t LIMIT 3;
t
00:12:32
00:12:33
05:27:00
DROP TABLE t1;
CREATE TABLE t1 (d DATE <CUSTOM_COL_OPTIONS>,
dt DATETIME <CUSTOM_COL_OPTIONS>,
ts TIMESTAMP <CUSTOM_COL_OPTIONS>,
t TIME <CUSTOM_COL_OPTIONS>,
y YEAR <CUSTOM_COL_OPTIONS>,
<CUSTOM_INDEX> y (y)
) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW INDEX IN t1;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t1	1	#	1	y	#	#	NULL	NULL	#	#		
SET @tm = '2012-04-09 05:27:00';
INSERT INTO t1 (d,dt,ts,t,y) VALUES
('2012-01-12', '2010-11-22 12:33:54', '2011-11-14 21:45:25', '00:12:33', '2000'),
('2012-01-12', '2010-11-22 11:43:14', '2011-11-14 21:45:55', '00:12:32', '2001'),
('2012-03-31', '2011-08-28 21:33:56', '1999-04-30 19:11:08', '12:00:00', '1999'),
('2012-03-13', '2011-08-27 21:33:56', '1999-03-30 19:11:08', '12:10:00', '1998'),
('2011-03-31', '2011-08-28 20:33:56', '1997-01-31 11:54:01', '22:04:10', '1994'),
(DATE(@tm),@tm,TIMESTAMP(@tm),TIME(@tm),YEAR(@tm));
SELECT y FROM t1 ORDER BY y LIMIT 3;
y
1994
1998
1999
DROP TABLE t1;
CREATE TABLE t1 (d DATE <CUSTOM_COL_OPTIONS>,
dt DATETIME <CUSTOM_COL_OPTIONS> PRIMARY KEY,
ts TIMESTAMP <CUSTOM_COL_OPTIONS>,
t TIME <CUSTOM_COL_OPTIONS>,
y YEAR <CUSTOM_COL_OPTIONS>
) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW INDEX IN t1;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t1	0	PRIMARY	1	dt	#	#	NULL	NULL	#	#		
SET @tm = '2012-04-09 05:27:00';
INSERT INTO t1 (d,dt,ts,t,y) VALUES
('2012-01-12', '2010-11-22 12:33:54', '2011-11-14 21:45:55', '00:12:33', '2000'),
('2012-01-12', '2010-11-22 11:43:14', '2011-11-14 21:45:55', '00:12:32', '2001'),
('2012-03-31', '2011-08-28 21:33:56', '1999-04-30 19:11:08', '12:00:00', '1999'),
('2012-03-13', '2011-08-27 21:33:56', '1999-03-30 19:11:08', '12:10:00', '1998'),
('2011-03-31', '2011-08-28 20:33:56', '1997-01-31 11:54:01', '22:04:10', '1994'),
(DATE(@tm),@tm,TIMESTAMP(@tm),TIME(@tm),YEAR(@tm));
EXPLAIN SELECT dt FROM t1 ORDER BY dt LIMIT 3;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
#	#	#	#	#	PRIMARY	#	#	#	#
SELECT dt FROM t1 ORDER BY dt LIMIT 3;
dt
2010-11-22 11:43:14
2010-11-22 12:33:54
2011-08-27 21:33:56
EXPLAIN SELECT dt FROM t1 FORCE INDEX FOR ORDER BY (PRIMARY) ORDER BY dt LIMIT 3;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
#	#	#	#	#	PRIMARY	#	#	#	#
SELECT dt FROM t1 FORCE INDEX FOR ORDER BY (PRIMARY) ORDER BY dt LIMIT 3;
dt
2010-11-22 11:43:14
2010-11-22 12:33:54
2011-08-27 21:33:56
INSERT INTO t1 (d,dt,ts,t,y) VALUES
('2012-01-11', '2010-11-22 12:33:54', '2011-11-14 21:45:55', '00:12:33', '2000');
ERROR 23000: Duplicate entry '2010-11-22 12:33:54' for key 'PRIMARY'
# Statement ended with one of expected results (ER_DUP_ENTRY,ER_DUP_KEY). 
# If you got a difference in error message, just add it to rdiff file
DROP TABLE t1;
CREATE TABLE t1 (d DATE <CUSTOM_COL_OPTIONS>,
dt DATETIME <CUSTOM_COL_OPTIONS>,
ts TIMESTAMP <CUSTOM_COL_OPTIONS>,
t TIME <CUSTOM_COL_OPTIONS>,
y YEAR <CUSTOM_COL_OPTIONS>,
INDEX (ts)
) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW INDEX IN t1;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t1	1	ts	1	ts	#	#	NULL	NULL	#	#		
SET @tm = '2012-04-09 05:27:00';
INSERT INTO t1 (d,dt,ts,t,y) VALUES
('2012-01-12', '2010-11-22 12:33:54', '2011-11-14 21:45:55', '00:12:33', '2000'),
('2012-01-12', '2010-11-22 11:43:14', '2011-11-14 21:45:55', '00:12:32', '2001'),
('2012-03-31', '2011-08-28 21:33:56', '1999-04-30 19:11:08', '12:00:00', '1999'),
('2012-03-13', '2011-08-27 21:33:56', '1999-03-30 19:11:08', '12:10:00', '1998'),
('2011-03-31', '2011-08-28 20:33:56', '1997-01-31 11:54:01', '22:04:10', '1994'),
(DATE(@tm),@tm,TIMESTAMP(@tm),TIME(@tm),YEAR(@tm));
EXPLAIN SELECT ts FROM t1 WHERE ts > NOW();
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
#	#	#	#	#	ts	#	#	#	#
SELECT ts FROM t1 WHERE ts > NOW();
ts
EXPLAIN SELECT ts FROM t1 USE INDEX () WHERE ts > NOW();
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
#	#	#	#	#	NULL	#	#	#	#
SELECT ts FROM t1 USE INDEX () WHERE ts > NOW();
ts
DROP TABLE t1;
CREATE TABLE t1 (d DATE <CUSTOM_COL_OPTIONS>,
dt DATETIME <CUSTOM_COL_OPTIONS>,
ts TIMESTAMP <CUSTOM_COL_OPTIONS>,
t TIME <CUSTOM_COL_OPTIONS>,
y YEAR <CUSTOM_COL_OPTIONS>,
UNIQUE INDEX d_t (d,t)
) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW INDEX IN t1;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t1	0	d_t	1	d	#	#	NULL	NULL	#	#		
t1	0	d_t	2	t	#	#	NULL	NULL	#	#		
SET @tm = '2012-04-09 05:27:00';
INSERT INTO t1 (d,dt,ts,t,y) VALUES
('2012-01-12', '2010-11-22 12:33:54', '2011-11-14 21:45:55', '00:12:33', '2000'),
('2012-01-12', '2010-11-22 11:43:14', '2011-11-14 21:45:55', '00:12:32', '2001'),
('2012-03-31', '2011-08-28 21:33:56', '1999-04-30 19:11:08', '12:00:00', '1999'),
('2012-03-13', '2011-08-27 21:33:56', '1999-03-30 19:11:08', '12:10:00', '1998'),
('2011-03-31', '2011-08-28 20:33:56', '1997-01-31 11:54:01', '22:04:10', '1994'),
(DATE(@tm),@tm,TIMESTAMP(@tm),TIME(@tm),YEAR(@tm));
EXPLAIN SELECT d, t FROM t1 WHERE CONCAT(d,' ',t) != CURRENT_DATE();
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
#	#	#	#	#	d_t	#	#	#	#
SELECT d, t FROM t1 WHERE CONCAT(d,' ',t) != CURRENT_DATE();
d	t
2011-03-31	22:04:10
2012-01-12	00:12:32
2012-01-12	00:12:33
2012-03-13	12:10:00
2012-03-31	12:00:00
2012-04-09	05:27:00
EXPLAIN SELECT d, t FROM t1 IGNORE INDEX (d_t) WHERE CONCAT(d,' ',t) != CURRENT_DATE();
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
#	#	#	#	#	NULL	#	#	#	#
SELECT d, t FROM t1 IGNORE INDEX (d_t) WHERE CONCAT(d,' ',t) != CURRENT_DATE();
d	t
2011-03-31	22:04:10
2012-01-12	00:12:32
2012-01-12	00:12:33
2012-03-13	12:10:00
2012-03-31	12:00:00
2012-04-09	05:27:00
INSERT INTO t1 (d,dt,ts,t,y) VALUES
('2012-01-12', '2010-11-22 12:33:53', '2011-11-14 21:45:55', '00:12:33', '2000');
ERROR 23000: Duplicate entry '2012-01-12-00:12:33' for key 'd_t'
# Statement ended with one of expected results (ER_DUP_ENTRY,ER_DUP_KEY). 
# If you got a difference in error message, just add it to rdiff file
DROP TABLE t1;
CREATE TABLE t1 (d DATE <CUSTOM_COL_OPTIONS>,
dt DATETIME <CUSTOM_COL_OPTIONS>,
ts TIMESTAMP <CUSTOM_COL_OPTIONS>,
t TIME <CUSTOM_COL_OPTIONS>,
y YEAR <CUSTOM_COL_OPTIONS>,
INDEX (y,t)
) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW INDEX IN t1;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t1	1	y	1	y	#	#	NULL	NULL	#	#		
t1	1	y	2	t	#	#	NULL	NULL	#	#		
SET @tm = '2012-04-09 05:27:00';
INSERT INTO t1 (d,dt,ts,t,y) VALUES
('2012-01-12', '2010-11-22 12:33:54', '2011-11-14 21:45:55', '00:12:33', '2000'),
('2012-01-12', '2010-11-22 11:43:14', '2011-11-14 21:45:55', '00:12:32', '2001'),
('2012-03-31', '2011-08-28 21:33:56', '1999-04-30 19:11:08', '12:00:00', '1999'),
('2012-03-13', '2011-08-27 21:33:56', '1999-03-30 19:11:08', '12:10:00', '1998'),
('2011-03-31', '2011-08-28 20:33:56', '1997-01-31 11:54:01', '22:04:10', '1994'),
(DATE(@tm),@tm,TIMESTAMP(@tm),TIME(@tm),YEAR(@tm));
EXPLAIN SELECT y, COUNT(*) FROM t1 GROUP BY y;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
#	#	#	#	#	y	#	#	#	#
SELECT y, COUNT(*) FROM t1 GROUP BY y;
y	COUNT(*)
1994	1
1998	1
1999	1
2000	1
2001	1
2012	1
EXPLAIN SELECT y, COUNT(*) FROM t1 USE INDEX FOR GROUP BY () GROUP BY y;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
#	#	#	#	#	y	#	#	#	#
SELECT y, COUNT(*) FROM t1 USE INDEX FOR GROUP BY () GROUP BY y;
y	COUNT(*)
1994	1
1998	1
1999	1
2000	1
2001	1
2012	1
DROP TABLE t1;