1source include/have_tokudb.inc; 2set default_storage_engine='tokudb'; 3# 4# testing of the TIME column type 5# 6 7--disable_warnings 8drop table if exists t1; 9--enable_warnings 10 11create table t1 (t time); 12insert into t1 values ("10:22:33"); 13insert into t1 values ("12:34:56.78"); 14insert into t1 values (10); 15insert into t1 values (1234); 16insert into t1 values (123456.78); 17insert into t1 values (1234559.99); 18insert into t1 values ("1"); 19insert into t1 values ("1:23"); 20insert into t1 values ("1:23:45"); 21insert into t1 values ("10.22"); 22insert into t1 values ("-10 1:22:33.45"); 23insert into t1 values ("20 10:22:33"); 24insert into t1 values ("1999-02-03 20:33:34"); 25insert into t1 values (30); 26insert into t1 values (1230); 27insert into t1 values ("1230"); 28insert into t1 values ("12:30"); 29insert into t1 values ("12:30:35"); 30insert into t1 values ("1 12:30:31.32"); 31--error 1292 32insert into t1 values ("10.22.22"); 33--error 1292 34insert into t1 values (1234567); 35--error 1292 36insert into t1 values (123456789); 37--error 1292 38insert into t1 values (123456789.10); 39insert into t1 values ("10 22:22"); 40--error 1292 41insert into t1 values ("12.45a"); 42select * from t1; 43drop table t1; 44 45create table t1 (t time); 46insert into t1 values ('09:00:00'),('13:00:00'),('19:38:34'), ('13:00:00'),('09:00:00'),('09:00:00'),('13:00:00'),('13:00:00'),('13:00:00'),('09:00:00'); 47select t, time_to_sec(t),sec_to_time(time_to_sec(t)) from t1; 48select sec_to_time(time_to_sec(t)) from t1; 49drop table t1; 50 51CREATE TABLE t1 (t TIME); 52INSERT INTO t1 VALUES (+10), (+10.0), (+10e0); 53INSERT INTO t1 VALUES (-10), (-10.0), (-10e0); 54SELECT * FROM t1; 55DROP TABLE t1; 56 57# 58# BUG #12440: Incorrect processing of time values containing 59# long fraction part and/or large exponent part. 60# 61SELECT CAST(235959.123456 AS TIME); 62SELECT CAST(0.235959123456e+6 AS TIME); 63SELECT CAST(235959123456e-6 AS TIME); 64 65# These must cut fraction part 66SELECT CAST(235959.1234567 AS TIME); 67SELECT CAST(0.2359591234567e6 AS TIME); 68 69# This must return NULL and produce warning: 70SELECT CAST(0.2359591234567e+30 AS TIME); 71########################################################### 72 73--echo End of 4.1 tests 74 75# 76# Bug#29555: Comparing time values as strings may lead to a wrong result. 77# 78select cast('100:55:50' as time) < cast('24:00:00' as time); 79select cast('100:55:50' as time) < cast('024:00:00' as time); 80select cast('300:55:50' as time) < cast('240:00:00' as time); 81select cast('100:55:50' as time) > cast('24:00:00' as time); 82select cast('100:55:50' as time) > cast('024:00:00' as time); 83select cast('300:55:50' as time) > cast('240:00:00' as time); 84create table t1 (f1 time); 85insert into t1 values ('24:00:00'); 86select cast('24:00:00' as time) = (select f1 from t1); 87drop table t1; 88 89# 90# Bug#29739: Incorrect time comparison in BETWEEN. 91# 92create table t1(f1 time, f2 time); 93insert into t1 values('20:00:00','150:00:00'); 94select 1 from t1 where cast('100:00:00' as time) between f1 and f2; 95drop table t1; 96 97# 98# Bug#29729: Wrong conversion error led to an empty result set. 99# 100CREATE TABLE t1 ( 101 f2 date NOT NULL, 102 f3 int(11) unsigned NOT NULL default '0', 103 PRIMARY KEY (f3, f2) 104); 105insert into t1 values('2007-07-01', 1); 106insert into t1 values('2007-07-01', 2); 107insert into t1 values('2007-07-02', 1); 108insert into t1 values('2007-07-02', 2); 109SELECT sum(f3) FROM t1 where f2='2007-07-01 00:00:00' group by f2; 110drop table t1; 111 112 113--echo # 114--echo # Bug #44792: valgrind warning when casting from time to time 115--echo # 116 117CREATE TABLE t1 (c TIME); 118INSERT INTO t1 VALUES ('0:00:00'); 119SELECT CAST(c AS TIME) FROM t1; 120DROP TABLE t1; 121 122--echo End of 5.0 tests 123 124--echo # 125--echo # Bug#53942 valgrind warnings with timestamp() function and incomplete datetime values 126--echo # 127SET @@timestamp=UNIX_TIMESTAMP('2001-01-01 01:00:00'); 128CREATE TABLE t1(f1 TIME); 129INSERT INTO t1 VALUES ('23:38:57'); 130SELECT TIMESTAMP(f1,'1') FROM t1; 131DROP TABLE t1; 132SET @@timestamp=default; 133 134--echo End of 5.1 tests 135 136# 137# Bug#42664 - Sign ignored for TIME types when not comparing as longlong 138# 139 140CREATE TABLE t1 (f1 TIME); 141INSERT INTO t1 VALUES ('24:00:00'); 142SELECT '24:00:00' = (SELECT f1 FROM t1); 143SELECT CAST('24:00:00' AS TIME) = (SELECT f1 FROM t1); 144SELECT CAST('-24:00:00' AS TIME) = (SELECT f1 FROM t1); 145TRUNCATE t1; 146INSERT INTO t1 VALUES ('-24:00:00'); 147SELECT CAST('24:00:00' AS TIME) = (SELECT f1 FROM t1); 148SELECT CAST('-24:00:00' AS TIME) = (SELECT f1 FROM t1); 149SELECT '-24:00:00' = (SELECT f1 FROM t1); 150DROP TABLE t1; 151 152--echo # 153--echo # Start of 5.6 tests 154--echo # 155 156--echo # 157--echo # WL#946 Testing <=> operator with TIME 158--echo # 159CREATE TABLE t1 (a TIME); 160INSERT INTO t1 VALUES ('20:00:00'),('19:20:30'); 161SELECT * FROM t1 WHERE a<=>'19:20:30'; 162SELECT * FROM t1 WHERE a<=>TIME'19:20:30'; 163SELECT * FROM t1 WHERE a<=>192030; 164DROP TABLE t1; 165 166 167--echo # 168--echo # WL#946: Testing rounding 169--echo # 170CREATE TABLE t1 (a TIME); 171INSERT INTO t1 VALUES ('10:10:10.9999994'), ('10:10:10.9999995'); 172INSERT INTO t1 VALUES (101010.9999994), (101010.9999995); 173SELECT * FROM t1; 174DROP TABLE t1; 175 176--echo # 177--echo # Before WL#946 TIME did not reject too big negative minutes/seconds 178--echo # 179CREATE TABLE t1 (a TIME); 180--error 1292 181INSERT INTO t1 VALUES ('-10:60:59'); 182--error 1292 183INSERT INTO t1 VALUES ('-10:59:60'); 184--error 1292 185INSERT INTO t1 VALUES (-106059); 186--error 1292 187INSERT INTO t1 VALUES (-105960); 188SELECT * FROM t1; 189DROP TABLE t1; 190 191--echo # 192--echo # WL#946 Make sure case from number to TIME properly handles 193--echo # too big negative minutes/secons 194--echo # 195CREATE TABLE t1 (a INT); 196INSERT INTO t1 VALUES (-106059), (-105960); 197SELECT CAST(a AS TIME) FROM t1; 198DROP TABLE t1; 199 200--echo # 201--echo # WL#946 Checking function TIME() 202--echo # 203SELECT TIME('1000009:10:10'); 204SELECT TIME('1000009:10:10.1999999999999'); 205SELECT TIME('10000090:10:10'); 206SELECT TIME('10000090:10:10.1999999999999'); 207SELECT TIME('100000900:10:10'); 208SELECT TIME('100000900:10:10.1999999999999'); 209SELECT TIME('1000009000:10:10'); 210SELECT TIME('1000009000:10:10.1999999999999'); 211SELECT TIME('10000090000:10:10'); 212SELECT TIME('10000090000:10:10.1999999999999'); 213 214--echo # 215--echo # Checking Item_func_if::val_str with TIME arguments 216--echo # 217SELECT CAST(IF(1, TIME'00:00:00',TIME'00:00:00') AS CHAR); 218 219--echo # 220--echo # Checking Item_func_case::val_str with TIME arguments 221--echo # 222SELECT CAST(CASE WHEN 1 THEN TIME'00:00:00' ELSE TIME'00:00:00' END AS CHAR); 223 224--echo # 225--echo # Testing CASE with TIME type without a found item 226--echo # 227SELECT CAST(CASE WHEN 0 THEN '01:01:01' END AS TIME); 228SELECT CAST(CASE WHEN 0 THEN TIME'01:01:01' END AS TIME); 229 230--echo # 231--echo # Testing COALESCE with TIME type without a found item 232--echo # 233SELECT COALESCE(TIME(NULL)); 234 235--echo # 236--echo # Testing TIME field with NULL value with NOT IN 237--echo # 238CREATE TABLE t1 (a TIME); 239INSERT INTO t1 VALUES (NULL); 240SELECT * FROM t1 WHERE a NOT IN (TIME'20:20:20',TIME'10:10:10'); 241DROP TABLE t1; 242 243--echo # 244--echo # Testing Item_func_numhybrid::val_int when TIME type 245--echo # 246CREATE TABLE t1 (a TIME); 247INSERT INTO t1 VALUES ('10:10:10'); 248SELECT CAST(COALESCE(a,a) AS SIGNED) FROM t1; 249DROP TABLE t1; 250 251--echo # 252--echo # Testing Item_func_numhybrid::val_decimal when TIME type 253--echo # 254CREATE TABLE t1 (a TIME); 255INSERT INTO t1 VALUES ('10:10:10'); 256SELECT CAST(COALESCE(a,a) AS DECIMAL(23,6)) FROM t1; 257DROP TABLE t1; 258 259--echo # 260--echo # Testing Item_func_numhybrid::get_time when non-temporal type 261--echo # 262SELECT CAST(COALESCE(10,20) AS TIME); 263 264--echo # 265--echo # Testing Item_func_min_max::get_time when DATE type and NULL 266--echo # 267SELECT CAST(LEAST(DATE(NULL), DATE(NULL)) AS TIME); 268 269--echo # 270--echo # Testing Item_func_min_max::get_time with non-temporal arguments 271--echo # 272SELECT CAST(LEAST(111111,222222) AS TIME); 273 274 275--echo # 276--echo # Item::get_time_from_numeric 277--echo # 278SELECT CAST(SUM(0) AS TIME); 279SELECT CAST(SUM(0 + 0e0) AS TIME); 280SET timestamp=1322115328; 281SELECT CAST(UNIX_TIMESTAMP() AS TIME); 282SET timestamp=default; 283 284--echo # 285--echo # Item::get_time_from_non_temporal 286--echo # 287SELECT TIME(154559.616 + 0e0); 288 289--echo # 290--echo # Item_name_const::get_time 291--echo # 292SELECT TIME(NAME_CONST('a', 0)); 293 294--echo # 295--echo # Item_cache_datetime::get_time 296--echo # 297CREATE TABLE t1 (a DATE); 298--error 1292 299INSERT INTO t1 VALUES (0); 300SELECT TIME(MIN(a)) FROM t1; 301DROP TABLE t1; 302 303--echo # 304--echo # Bug#13623473 "MISSING ROWS ON SELECT AND JOIN WITH 305--echo # TIME/DATETIME COMPARE" 306--echo # 307 308--echo # Systematic testing of ref access and range scan 309 310SET TIMESTAMP=UNIX_TIMESTAMP('2012-01-31 10:14:35'); 311 312CREATE TABLE t1 (col_time_key TIME, KEY(col_time_key)) ENGINE=InnoDB; 313INSERT INTO t1 VALUES ('00:00:00'),('-24:00:00'),('-48:00:00'),('24:00:00'),('48:00:00'); 314CREATE TABLE t2 (col_datetime_key DATETIME, KEY(col_datetime_key)) ENGINE=InnoDB; 315INSERT INTO t2 SELECT * FROM t1; 316 317-- disable_result_log 318ANALYZE TABLE t1; 319ANALYZE TABLE t2; 320-- enable_result_log 321 322let $cnt_0=5; 323let $operator= =; 324# For operator in =, >=, >, <=, < 325while ($cnt_0) 326{ 327 let $cnt_1=2; 328 let $first_table=t1; 329 # for table in t1,t2 330 while ($cnt_1) 331 { 332 if ($first_table==t1) 333 { 334 let $first_index=col_time_key; 335 let $second_table=t2; 336 let $second_index=col_datetime_key; 337 } 338 if ($first_table==t2) 339 { 340 let $first_index=col_datetime_key; 341 let $second_table=t1; 342 let $second_index=col_time_key; 343 } 344 let $cnt_2=2; 345 let $first_index_hint=ignore; 346 # for first_index_hint in ignore,force 347 while ($cnt_2) 348 { 349 let $cnt_3=2; 350 let $second_index_hint=ignore; 351 # for second_index_hint in ignore, force 352 while ($cnt_3) 353 { 354 let $cnt_4=2; 355 let $first_operand=col_time_key; 356 # for first_operand in col_time_key, col_datetime_key 357 while ($cnt_4) 358 { 359 if ($first_operand==col_time_key) 360 { 361 let $second_operand=col_datetime_key; 362 } 363 if ($first_operand==col_datetime_key) 364 { 365 let $second_operand=col_time_key; 366 } 367 368 eval EXPLAIN EXTENDED SELECT * FROM 369 $first_table $first_index_hint INDEX ($first_index) 370 STRAIGHT_JOIN 371 $second_table $second_index_hint INDEX ($second_index) 372 WHERE $first_operand $operator $second_operand; 373 --sorted_result 374 eval SELECT * FROM 375 $first_table $first_index_hint INDEX ($first_index) 376 STRAIGHT_JOIN 377 $second_table $second_index_hint INDEX ($second_index) 378 WHERE $first_operand $operator $second_operand; 379 380 let $first_operand=col_datetime_key; 381 dec $cnt_4; 382 } 383 let $second_index_hint=force; 384 dec $cnt_3; 385 } 386 let $first_index_hint=force; 387 dec $cnt_2; 388 } 389 let $first_table=t2; 390 dec $cnt_1; 391 } 392 if ($cnt_0==5) 393 { 394 let $operator= >=; 395 } 396 if ($cnt_0==4) 397 { 398 let $operator= >; 399 } 400 if ($cnt_0==3) 401 { 402 let $operator= <=; 403 } 404 if ($cnt_0==2) 405 { 406 let $operator= <; 407 } 408 dec $cnt_0; 409} 410 411DROP TABLE t1,t2; 412 413--echo 414--echo # Original test of the bug report 415--echo 416 417CREATE TABLE t1 ( 418 pk INT NOT NULL AUTO_INCREMENT, 419 col_int_nokey INT, 420 col_int_key INT NOT NULL, 421 PRIMARY KEY (pk), 422 KEY col_int_key (col_int_key) 423) ENGINE=InnoDB; 424 425INSERT INTO t1 VALUES (10,1,7), (11,7,0), (12,4,9), (13,7,3), 426(14,0,4), (15,2,2), (16,9,5), (17,4,3), (18,0,1), (19,9,3), (20,1,6), 427(21,3,7), (22,8,5), (23,8,1), (24,18,204), (25,84,224), (26,6,9), 428(27,3,5), (28,6,0), (29,6,3); 429 430CREATE TABLE t2 ( 431 col_int_nokey INT NOT NULL, 432 col_datetime_key DATETIME NOT NULL, 433 col_varchar_key VARCHAR(1) NOT NULL, 434 KEY col_datetime_key (col_datetime_key), 435 KEY col_varchar_key (col_varchar_key) 436) ENGINE=InnoDB; 437 438INSERT INTO t2 VALUES (1,'2001-11-04 19:07:55','k'); 439 440CREATE TABLE t3 ( 441 col_time_key TIME, 442 KEY col_time_key (col_time_key) 443) ENGINE=InnoDB; 444 445INSERT INTO t3 VALUES ('21:22:34'), ('10:50:38'), ('00:21:38'), 446('04:08:02'), ('16:25:11'), ('10:14:58'), ('19:47:59'), ('11:14:24'), 447('00:00:00'), ('00:00:00'), ('15:57:25'), ('07:05:51'), ('19:22:21'), 448('03:53:16'), ('09:16:38'), ('15:37:26'), ('00:00:00'), ('05:03:03'), 449('02:59:24'), ('00:01:58'); 450 451-- disable_result_log 452ANALYZE TABLE t1; 453ANALYZE TABLE t2; 454ANALYZE TABLE t3; 455-- enable_result_log 456 457let $query=SELECT * FROM t2 STRAIGHT_JOIN t3 FORCE INDEX (col_time_key) 458 ON t3.col_time_key > t2.col_datetime_key; 459eval EXPLAIN EXTENDED $query; 460--sorted_result 461eval $query; 462 463let $query=SELECT * FROM t2 STRAIGHT_JOIN t3 IGNORE INDEX (col_time_key) 464 ON t3.col_time_key > t2.col_datetime_key; 465eval EXPLAIN EXTENDED $query; 466--sorted_result 467eval $query; 468 469DROP TABLE t1,t2,t3; 470SET TIMESTAMP = DEFAULT; 471 472--echo # 473--echo # End of 5.6 tests 474--echo # 475