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 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
|
#
# testing different DATETIME ranges
#
--disable_warnings
drop table if exists t1;
--enable_warnings
create table t1 (t datetime) ENGINE=InnoDB;
insert ignore into t1 values (101),(691231),(700101),(991231),(10000101),(99991231),(101000000),(691231000000),(700101000000),(991231235959),(10000101000000),(99991231235959),(20030100000000),(20030000000000);
select * from t1;
delete from t1 where t > 0;
optimize table t1;
check table t1;
delete from t1;
insert ignore into t1 values("000101"),("691231"),("700101"),("991231"),("00000101"),("00010101"),("99991231"),("00101000000"),("691231000000"),("700101000000"),("991231235959"),("10000101000000"),("99991231235959"),("20030100000000"),("20030000000000");
# Strange dates
insert into t1 values ("2003-003-03");
# Bug #7308: ISO-8601 date format not handled correctly
insert into t1 values ("20030102T131415"),("2001-01-01T01:01:01"), ("2001-1-1T1:01:01");
select * from t1;
# Test some wrong dates
truncate table t1;
insert ignore into t1 values("2003-0303 12:13:14");
select * from t1;
drop table t1;
#
# Test insert of now() and curtime()
#
SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
CREATE TABLE t1 (a timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, b date, c time, d datetime);
insert into t1 (b,c,d) values(now(),curtime(),now());
select date_format(a,"%Y-%m-%d")=b,right(a+0,6)=c+0,a=d+0 from t1;
drop table t1;
SET sql_mode = default;
#
# Test of datetime and not null
#
CREATE TABLE t1 (a datetime not null);
insert ignore into t1 values (0);
select * from t1 where a is null;
drop table t1;
#
# Test with bug when propagating DATETIME to integer and WHERE optimization
#
create table t1 (id int, dt datetime);
insert into t1 values (1,"2001-08-14 00:00:00"),(2,"2001-08-15 00:00:00"),(3,"2001-08-16 00:00:00"),(4,"2003-09-15 01:20:30");
select * from t1 where dt='2001-08-14 00:00:00' and dt = if(id=1,'2001-08-14 00:00:00','1999-08-15');
create index dt on t1 (dt);
select * from t1 where dt > 20021020;
select * from t1 ignore index (dt) where dt > 20021020;
drop table t1;
#
# Let us check if we properly treat wrong datetimes and produce proper
# warnings (for both strings and numbers)
#
SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
create table t1 (t datetime);
insert into t1 values (20030102030460),(20030102036301),(20030102240401),
(20030132030401),(20031302030401),(100001202030401);
select * from t1;
delete from t1;
insert into t1 values
("2003-01-02 03:04:60"),("2003-01-02 03:63:01"),("2003-01-02 24:04:01"),
("2003-01-32 03:04:01"),("2003-13-02 03:04:01"), ("10000-12-02 03:04:00");
select * from t1;
delete from t1;
insert into t1 values ("0000-00-00 00:00:00 some trailer"),("2003-01-01 00:00:00 some trailer");
select * from t1 order by t;
drop table t1;
#
# Test for bug #7297 "Two digit year should be interpreted correctly even
# with zero month and day"
#
create table t1 (dt datetime);
# These dates should be treated as dates in 21st century
insert into t1 values ("12-00-00"), ("00-00-00 01:00:00");
# Zero dates are still special :/
insert into t1 values ("00-00-00"), ("00-00-00 00:00:00");
select * from t1;
drop table t1;
SET sql_mode = default;
#
# Bug #16546 DATETIME+0 not always coerced the same way
#
select cast('2006-12-05 22:10:10' as datetime) + 0;
# End of 4.1 tests
#
# Bug#21475: Wrongly applied constant propagation leads to a false comparison.
#
CREATE TABLE t1(a DATETIME NOT NULL);
INSERT INTO t1 VALUES ('20060606155555');
SELECT a FROM t1 WHERE a=(SELECT MAX(a) FROM t1) AND (a="20060606155555");
PREPARE s FROM 'SELECT a FROM t1 WHERE a=(SELECT MAX(a) FROM t1) AND (a="20060606155555")';
EXECUTE s;
DROP PREPARE s;
DROP TABLE t1;
#
# Bug 19491 (CAST DATE AS DECIMAL returns incorrect result
#
SELECT CAST(CAST('2006-08-10' AS DATE) AS DECIMAL(20,6));
SELECT CAST(CAST('2006-08-10 10:11:12' AS DATETIME) AS DECIMAL(20,6));
SELECT CAST(CAST('2006-08-10 10:11:12' AS DATETIME) + INTERVAL 14 MICROSECOND AS DECIMAL(20,6));
SELECT CAST(CAST('10:11:12.098700' AS TIME) AS DECIMAL(20,6));
#
# Test of storing datetime into date fields
#
set @org_mode=@@sql_mode;
create table t1 (da date default '1962-03-03 23:33:34', dt datetime default '1962-03-03');
show create table t1;
insert into t1 values ();
insert into t1 values ('2007-03-23 13:49:38','2007-03-23 13:49:38');
set @@sql_mode='ansi,traditional';
insert into t1 values ('2007-03-23 13:49:38','2007-03-23 13:49:38');
insert into t1 set dt='2007-03-23 13:49:38',da=dt;
# Test error handling
--error ER_TRUNCATED_WRONG_VALUE
insert into t1 values ('2007-03-32','2007-03-23 13:49:38');
select * from t1;
drop table t1;
--error ER_INVALID_DEFAULT
create table t1 (da date default '1962-03-32 23:33:34', dt datetime default '1962-03-03');
--error ER_INVALID_DEFAULT
create table t1 (t time default '916:00:00 a');
set @@sql_mode= @org_mode;
#
# Bug#27590: Wrong DATE/DATETIME comparison.
#
## The following sub test will fail (difference to expected result) if the
## select curdate() < now(), f1 < now(), cast(f1 as date) < now() from t1;
## runs exact at midnight ('00:00:00').
## ( Bug#29290 type_datetime.test failure in 5.1 )
## Therefore we sleep a bit if we are too close to midnight.
## The complete test itself needs around 1 second.
## Therefore a time_distance to midnight of 5 seconds should be sufficient.
if (`SELECT CURTIME() > SEC_TO_TIME(24 * 3600 - 5)`)
{
# We are here when CURTIME() is between '23:59:56' and '23:59:59'.
# So a sleep time of 5 seconds brings us between '00:00:01' and '00:00:04'.
--sleep 5
}
create table t1 (f1 date, f2 datetime, f3 timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
insert into t1(f1) values(curdate());
select curdate() < now(), f1 < now(), cast(f1 as date) < now() from t1;
delete from t1;
insert into t1 values('2001-01-01','2001-01-01 01:01:01','2001-01-01 01:01:01');
insert into t1 values('2001-02-05','2001-02-05 00:00:00','2001-02-05 01:01:01');
insert into t1 values('2001-03-10','2001-03-09 01:01:01','2001-03-10 01:01:01');
insert into t1 values('2001-04-15','2001-04-15 00:00:00','2001-04-15 00:00:00');
insert into t1 values('2001-05-20','2001-05-20 01:01:01','2001-05-20 01:01:01');
select f1, f3 from t1 where f1 >= '2001-02-05 00:00:00' and f3 <= '2001-04-15';
select f1, f3 from t1 where f1 >= '2001-2-5 0:0:0' and f2 <= '2001-4-15';
select f1, f2 from t1 where if(1, f1, 0) >= f2;
select 1 from dual where cast('2001-1-1 2:3:4' as date) = cast('2001-01-01' as datetime);
select f1, f2, f1 > f2, f1 = f2, f1 < f2 from t1;
drop table t1;
#
# Bug#16377: Wrong DATE/DATETIME comparison in BETWEEN function.
#
create table t1 (f1 date, f2 datetime, f3 timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
insert into t1 values('2001-01-01','2001-01-01 01:01:01','2001-01-01 01:01:01');
insert into t1 values('2001-02-05','2001-02-05 00:00:00','2001-02-05 01:01:01');
insert into t1 values('2001-03-10','2001-03-09 01:01:01','2001-03-10 01:01:01');
insert into t1 values('2001-04-15','2001-04-15 00:00:00','2001-04-15 00:00:00');
insert into t1 values('2001-05-20','2001-05-20 01:01:01','2001-05-20 01:01:01');
select f2 from t1 where f2 between '2001-2-5' and '01-04-14';
select f1, f2, f3 from t1 where f1 between f2 and f3;
select f1, f2, f3 from t1 where cast(f1 as datetime) between f2 and
cast(f3 as date);
select f2 from t1 where '2001-04-10 12:34:56' between f2 and '01-05-01';
select f2, f3 from t1 where '01-03-10' between f2 and f3;
select f2 from t1 where DATE(f2) between "2001-4-15" AND "01-4-15";
SELECT 1 from dual where NOW() BETWEEN CURRENT_DATE() - INTERVAL 1 DAY AND CURRENT_DATE();
drop table t1;
#
# Bug#28133: Wrong DATE/DATETIME comparison in IN() function.
#
create table t1 (f1 date);
insert into t1 values('01-01-01'),('01-01-02'),('01-01-03');
--sorted_result
select * from t1 where f1 in ('01-01-01','2001-01-02','2001-01-03 00:00:00');
create table t2(f2 datetime);
insert into t2 values('01-01-01 00:00:00'),('01-02-03 12:34:56'),('02-04-06 11:22:33');
--sorted_result
select * from t2 where f2 in ('01-01-01','01-02-03 12:34:56','01-02-03');
--sorted_result
select * from t1,t2 where '01-01-02' in (f1, cast(f2 as date));
--sorted_result
select * from t1,t2 where '01-01-01' in (f1, '01-02-03');
--sorted_result
select * from t1,t2 where if(1,'01-02-03 12:34:56','') in (f1, f2);
create table t3(f3 varchar(20));
insert into t3 select * from t2;
--sorted_result
select * from t2,t3 where f2 in (f3,'03-04-05');
--sorted_result
select f1,f2,f3 from t1,t2,t3 where (f1,'1') in ((f2,'1'),(f3,'1')) order by f1,f2,f3;
--sorted_result
select f1 from t1 where ('1',f1) in (('1','01-01-01'),('1','2001-1-1 0:0:0'),('1','02-02-02'));
drop table t1,t2,t3;
#
# Bug#27759: Wrong DATE/DATETIME comparison in LEAST()/GREATEST() functions.
#
select least(cast('01-01-01' as date), '01-01-02');
select greatest(cast('01-01-01' as date), '01-01-02');
select least(cast('01-01-01' as date), '01-01-02') + 0;
select greatest(cast('01-01-01' as date), '01-01-02') + 0;
select least(cast('01-01-01' as datetime), '01-01-02') + 0;
select cast(least(cast('01-01-01' as datetime), '01-01-02') as signed);
select cast(least(cast('01-01-01' as datetime), '01-01-02') as decimal(16,2));
--disable_warnings
DROP PROCEDURE IF EXISTS test27759 ;
--enable_warnings
DELIMITER |;
CREATE PROCEDURE test27759()
BEGIN
declare v_a date default '2007-4-10';
declare v_b date default '2007-4-11';
declare v_c datetime default '2004-4-9 0:0:0';
select v_a as a,v_b as b,
least( v_a, v_b ) as a_then_b,
least( v_b, v_a ) as b_then_a,
least( v_c, v_a ) as c_then_a;
END;|
DELIMITER ;|
call test27759();
drop procedure test27759;
#
# Bug#28208: Wrong result of a non-const STRING function with a const
# DATETIME function.
#
create table t1 (f1 date);
insert into t1 values (curdate());
select left(f1,10) = curdate() from t1;
drop table t1;
#
# Bug#28261: Wrong DATETIME comparison result when the GET_USER_VAR function
# is involved.
#
create table t1(f1 date);
insert into t1 values('01-01-01'),('02-02-02'),('01-01-01'),('02-02-02');
--disable_ps_protocol # See bug #27245598.
set @bug28261='';
--skip_if_hypergraph # Different warnings.
select if(@bug28261 = f1, '', @bug28261:= f1) from t1;
--skip_if_hypergraph # Different warnings.
select if(@bug28261 = f1, '', @bug28261:= f1) from t1;
--skip_if_hypergraph # Different warnings.
select if(@bug28261 = f1, '', @bug28261:= f1) from t1;
--enable_ps_protocol
drop table t1;
#
# Bug#28778: Wrong result of BETWEEN when comparing a DATETIME field with an
# integer constants.
#
create table t1(f1 datetime);
insert into t1 values('2001-01-01'),('2002-02-02');
select * from t1 where f1 between 20020101 and 20070101000000;
select * from t1 where f1 between 2002010 and 20070101000000;
select * from t1 where f1 between 20020101 and 2007010100000;
drop table t1;
--echo #
--echo # Bug#27216: functions with parameters of different date types may
--echo # return wrong type of the result.
--echo #
create table t1 (f1 date, f2 datetime, f3 varchar(20));
create table t2 as select coalesce(f1,f1) as f4 from t1;
desc t2;
create table t3 as select coalesce(f1,f2) as f4 from t1;
desc t3;
create table t4 as select coalesce(f2,f2) as f4 from t1;
desc t4;
create table t5 as select coalesce(f1,f3) as f4 from t1;
desc t5;
create table t6 as select coalesce(f2,f3) as f4 from t1;
desc t6;
create table t7 as select coalesce(makedate(1997,1),f2) as f4 from t1;
desc t7;
create table t8 as select coalesce(cast('01-01-01' as datetime),f2) as f4
from t1;
desc t8;
create table t9 as select case when 1 then cast('01-01-01' as date)
when 0 then cast('01-01-01' as date) end as f4 from t1;
desc t9;
create table t10 as select case when 1 then cast('01-01-01' as datetime)
when 0 then cast('01-01-01' as datetime) end as f4 from t1;
desc t10;
create table t11 as select if(1, cast('01-01-01' as datetime),
cast('01-01-01' as date)) as f4 from t1;
desc t11;
create table t12 as select least(cast('01-01-01' as datetime),
cast('01-01-01' as date)) as f4 from t1;
desc t12;
create table t13 as select ifnull(cast('01-01-01' as datetime),
cast('01-01-01' as date)) as f4 from t1;
desc t13;
drop tables t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13;
--echo ###################################################################
#
# Bug #31253: crash comparing datetime to double
# Should return 1st row only. Crashes if NULL propagation fails.
#
create table t1 (f1 time);
insert into t1 set f1 = '45:44:44';
insert into t1 set f1 = '15:44:44';
select * from t1 where (convert(f1,datetime)) != 1;
drop table t1;
#
# Bug #31249: problem with convert(..., datetime)
#
create table t1 (a tinyint);
insert into t1 values (), (), ();
select sum(a) from t1 group by convert(a, datetime);
drop table t1;
#
# Bug #32694: NOT NULL table field in a subquery produces invalid results
#
create table t1 (id int(10) not null, cur_date datetime not null);
create table t2 (id int(10) not null, cur_date date not null);
insert into t1 (id, cur_date) values (1, '2007-04-25 18:30:22');
insert into t2 (id, cur_date) values (1, '2007-04-25');
analyze table t1;
--disable_query_log
if (`select locate('semijoin', @@optimizer_switch) > 0`)
{
set optimizer_switch='semijoin=off';
}
--enable_query_log
explain
select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null));
select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null));
explain
select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null));
select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null));
insert into t1 (id, cur_date) values (2, '2007-04-26 18:30:22');
insert into t2 (id, cur_date) values (2, '2007-04-26');
explain
select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null));
select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null));
explain
select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null));
select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null));
set @@optimizer_switch=default;
drop table t1,t2;
#
# Bug #37526: asymertic operator <=> in trigger
#
SELECT
CAST('NULL' AS DATE) <=> CAST('2008-01-01' AS DATE) n1,
CAST('2008-01-01' AS DATE) <=> CAST('NULL' AS DATE) n2,
CAST('NULL' AS DATE) <=> CAST('NULL' AS DATE) n3,
CAST('NULL' AS DATE) <> CAST('2008-01-01' AS DATE) n4,
CAST('2008-01-01' AS DATE) <> CAST('NULL' AS DATE) n5,
CAST('NULL' AS DATE) <> CAST('NULL' AS DATE) n6,
CAST('NULL' AS DATE) < CAST('2008-01-01' AS DATE) n7,
CAST('2008-01-01' AS DATE) < CAST('NULL' AS DATE) n8,
CAST('NULL' AS DATE) < CAST('NULL' AS DATE) n9;
--echo End of 5.0 tests
#
# Test of storing datetime into date fields
#
set @org_mode=@@sql_mode;
create table t1 (da date default '1962-03-03 23:33:34', dt datetime default '1962-03-03');
show create table t1;
insert into t1 values ();
insert into t1 values ('2007-03-23 13:49:38','2007-03-23 13:49:38');
set @@sql_mode='ansi,traditional';
insert into t1 values ('2007-03-23 13:49:38','2007-03-23 13:49:38');
insert into t1 set dt='2007-03-23 13:49:38',da=dt;
# Test error handling
--error 1292
insert into t1 values ('2007-03-32','2007-03-23 13:49:38');
select * from t1;
drop table t1;
--error 1067
create table t1 (da date default '1962-03-32 23:33:34', dt datetime default '1962-03-03');
--error 1067
create table t1 (t time default '916:00:00 a');
set @@sql_mode= @org_mode;
#
# Bug #42146 - DATETIME fractional seconds parse error
#
# show we trucate microseconds from the right -- special case: leftmost is 0
SELECT CAST(CAST('2006-08-10 10:11:12.0123450' AS DATETIME) AS DECIMAL(30,7));
# show that we ignore leading zeroes for all other fields
SELECT CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.0123450' AS DATETIME) AS DECIMAL(30,7));
# once more with feeling (but no warnings)
SELECT CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.012345' AS DATETIME) AS DECIMAL(30,7));
#
# Bug #38435 - LONG Microseconds cause MySQL to fail a CAST to DATETIME or DATE
#
# show we truncate microseconds from the right
SELECT CAST(CAST('2008-07-29T10:42:51.1234567' AS DateTime) AS DECIMAL(30,7));
--echo #
--echo # Bug#59173: Failure to handle DATE(TIME) values where Year, Month or
--echo # Day is ZERO
--echo #
CREATE TABLE t1 (dt1 DATETIME);
INSERT IGNORE INTO t1 (dt1) VALUES ('0000-00-01 00:00:01');
--error ER_WRONG_VALUE
DELETE IGNORE FROM t1 WHERE dt1 = '0000-00-01 00:00:01';
--echo # Should be empty
SELECT * FROM t1;
DROP TABLE t1;
--echo End of 5.1 tests
--echo #
--echo # Start of 5.5 tests
--echo #
--echo #
--echo # Bug#52849 datetime index not work
--echo #
CREATE TABLE t1 (Id INT, AtTime DATETIME, KEY AtTime (AtTime));
SET NAMES CP850;
INSERT INTO t1 VALUES (1,'2010-04-12 22:30:12'), (2,'2010-04-12 22:30:12'), (3,'2010-04-12 22:30:12');
EXPLAIN SELECT * FROM t1 FORCE INDEX(attime) WHERE AtTime = '2010-02-22 18:40:07';
DROP TABLE t1;
SET NAMES latin1;
--echo #
--echo # Bug#56271: Wrong comparison result with STR_TO_DATE function
--echo #
CREATE TABLE t1 (
`year` int(4) NOT NULL,
`month` int(2) NOT NULL
);
INSERT INTO t1 VALUES (2010,3),(2010,4),(2009,8),(2008,9);
SELECT *
FROM t1
WHERE STR_TO_DATE(CONCAT_WS('/01/',`month`,`year`), '%m/%d/%Y') >=
STR_TO_DATE('1/1/2010', '%m/%d/%Y');
create table t2(f1 datetime primary key);
insert into t2 select STR_TO_DATE(CONCAT_WS('/01/',`month`,`year`), '%m/%d/%Y') from t1;
analyze table t1;
select * from t2 where f1=STR_TO_DATE('4/1/2010', '%m/%d/%Y');
--echo t2 should be const
explain select * from t2 where f1=STR_TO_DATE('4/1/2010', '%m/%d/%Y');
DROP TABLE t1,t2;
--echo #
--echo # Bug#57095: Wrongly chosen expression cache type led to a wrong
--echo # result.
--echo #
CREATE TABLE t1 (`b` datetime );
INSERT INTO t1 VALUES ('2010-01-01 00:00:00'), ('2010-01-01 00:00:00');
SELECT * FROM t1 WHERE b <= coalesce(NULL, now());
DROP TABLE t1;
--echo #
--echo #
--echo # BUG#12561818: RERUN OF STORED FUNCTION GIVES ERROR 1172:
--echo # RESULT CONSISTED OF MORE THAN ONE ROW
--echo #
CREATE TABLE t1 (a DATE NOT NULL, b INT);
INSERT IGNORE INTO t1 VALUES ('0000-00-00',1), ('1999-05-10',2);
CREATE TABLE t2 (a DATETIME NOT NULL, b INT);
INSERT IGNORE INTO t2 VALUES ('0000-00-00 00:00:00',1), ('1999-05-10 00:00:00',2);
--echo
SELECT * FROM t1 WHERE a IS NULL;
SELECT * FROM t2 WHERE a IS NULL;
SELECT * FROM t1 LEFT JOIN t1 AS t1_2 ON 1 WHERE t1_2.a IS NULL;
SELECT * FROM t2 LEFT JOIN t2 AS t2_2 ON 1 WHERE t2_2.a IS NULL;
SELECT * FROM t1 JOIN t1 AS t1_2 ON 1 WHERE t1_2.a IS NULL;
SELECT * FROM t2 JOIN t2 AS t2_2 ON 1 WHERE t2_2.a IS NULL;
--echo
PREPARE stmt1 FROM
'SELECT *
FROM t1 LEFT JOIN t1 AS t1_2 ON 1
WHERE t1_2.a IS NULL AND t1_2.b < 2';
EXECUTE stmt1;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
DROP TABLE t1,t2;
--echo #
--echo # End of 5.5 tests
--echo #
--echo #
--echo # Start of 5.6 tests
--echo #
--echo #
--echo # WL#946: Testing rounding
--echo #
CREATE TABLE t1 (a DATETIME);
INSERT INTO t1 VALUES ('2001-01-01 10:10:10.9999994'), ('2001-01-01 10:10:10.9999995');
INSERT INTO t1 VALUES (20010101101010.9999994), (20010101101010.9999995);
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Test for bug#11747847 - 34280: create table fails if NO_ZERO_DATE
--echo # or NO_ZERO_IN_DATE SQL mode is set.
--disable_warnings
DROP TABLE if EXISTS t1, t2, t3;
--enable_warnings
SET @org_mode=@@sql_mode;
--echo #Table creation in strict mode
SET @@sql_mode='NO_ZERO_DATE,STRICT_ALL_TABLES';
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (c1 DATETIME DEFAULT 0);
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (c1 DATETIME DEFAULT '0000-00-00 00:00:00');
SET @@sql_mode='NO_ZERO_IN_DATE,STRICT_ALL_TABLES';
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (c1 DATETIME DEFAULT '2012-02-00 12:12:12');
--echo #Table creation in non-strict mode but with NO_ZERO_DATE/NO_ZERO_IN_DATE
SET @@sql_mode='NO_ZERO_DATE';
CREATE TABLE t1 (c1 DATETIME DEFAULT 0);
CREATE TABLE t2 (c1 DATETIME DEFAULT '0000-00-00 00:00:00');
SET @@sql_mode='NO_ZERO_IN_DATE';
CREATE TABLE t3 (c1 DATETIME DEFAULT '2012-02-00 12:12:12');
DROP TABLE t1, t2, t3;
--echo #Table creation with out any SQL modes
SET @@sql_mode='';
CREATE TABLE t1 (c1 DATETIME DEFAULT 0);
CREATE TABLE t2 (c1 DATETIME DEFAULT '0000-00-00 00:00:00');
CREATE TABLE t3 (c1 DATETIME DEFAULT '2012-02-00 12:12:12');
DROP TABLE t1, t2, t3;
CREATE TABLE t1 (c1 int);
--echo #Alter table in strict mode with NO_ZERO_DATE/NO_ZERO_IN_DATE
SET @@sql_mode='NO_ZERO_DATE,STRICT_ALL_TABLES';
--error ER_INVALID_DEFAULT
ALTER TABLE t1 ADD c2 DATETIME DEFAULT 0;
--error ER_INVALID_DEFAULT
ALTER TABLE t1 ADD c2 DATETIME DEFAULT '0000-00-00';
SET @@sql_mode='NO_ZERO_IN_DATE,STRICT_ALL_TABLES';
--error ER_INVALID_DEFAULT
ALTER TABLE t1 ADD c2 DATETIME DEFAULT '2012-02-00';
--echo #Alter table in non-strict mode but with NO_ZERO_DATE/NO_ZERO_IN_DATE
SET @@sql_mode='NO_ZERO_DATE';
ALTER TABLE t1 ADD c2 DATETIME DEFAULT 0;
ALTER TABLE t1 ADD c3 DATETIME DEFAULT '0000-00-00';
SET @@sql_mode='NO_ZERO_IN_DATE';
ALTER TABLE t1 ADD c4 DATETIME DEFAULT '2012-02-00';
DROP TABLE t1;
CREATE TABLE t1 (c1 INT);
--echo #Alter table with out any SQL modes
SET @@sql_mode='';
ALTER TABLE t1 ADD c2 DATETIME DEFAULT 0;
ALTER TABLE t1 ADD c3 DATETIME DEFAULT '0000-00-00';
ALTER TABLE t1 ADD c4 DATETIME DEFAULT '2012-02-00';
DROP TABLE t1;
SET @@sql_mode= @org_mode;
--echo # END of Test for bug#11747847 - 34280
--echo #
--echo # End of 5.6 tests
--echo #
--echo #
--echo #Bug#25586673: ASSERT IN DA FOR SQL_CMD_UPDATE::UPDATE_SINGLE_TABLE
--echo #Bug#25586959: SERVER CRASH IN SQL_CMD_DELETE::DELETE_FROM_SINGLE_TABLE
--echo #
CREATE TABLE test.t(col_varchar_nokey VARCHAR(1) NOT NULL,
col_time_nokey time NOT NULL,
col_int_nokey INT NOT NULL,
col_datetime_key datetime not null,
key(col_datetime_key)) ENGINE= InnoDB;
--error ER_TRUNCATED_WRONG_VALUE
DELETE FROM test.t WHERE `col_int_nokey` > `col_int_nokey`
AND TIMESTAMP( '18:16:35.025453' ) IS NULL;
--error ER_TRUNCATED_WRONG_VALUE
UPDATE test.t SET `col_varchar_nokey` = TIMESTAMP(`col_time_nokey`,'00:00:00')
WHERE `col_int_nokey` > `col_int_nokey`
AND TIMESTAMP('18:16:35.025453') IS NULL;
INSERT INTO t VALUES('x', CURRENT_TIME(), 0, CURRENT_TIMESTAMP());
--error ER_TRUNCATED_WRONG_VALUE
UPDATE test.t SET `col_datetime_key` = `col_datetime_key` WHERE
`col_datetime_key` <=> FROM_UNIXTIME(1151860736,CONCAT_WS(':','%D','%v'));
DROP TABLE test.t;
--echo #
--echo # Bug#25866743 - ASSERTION FAILED: FALSE IN
--echo # ITEM_FUNC_GEOMETRY_FROM_TEXT::VAL_STR
--echo # Bug#25866143 CRASH IN ST_ASWKB STRING::COPY
--echo #
--error ER_DATA_OUT_OF_RANGE
do is_ipv4_mapped(bin(maketime(11111,exp(repeat('1',32)),'')));
--error ER_WRONG_VALUE_FOR_TYPE
do ifnull((bin_to_uuid(uuid_to_bin(date_format('7088-02-14'
,0xabbd95)))),(maketime('4678-07-20 03:51:44.174847',1,'b')));
--error ER_WRONG_VALUE_FOR_TYPE
do ucase(insert(maketime(9.565398e+307 ,'',
st_longfromgeohash(('4358-04-12 03:45:08.727399'))),
0xdc0823,6756,release_all_locks()));
--error ER_DATA_OUT_OF_RANGE
do soundex(maketime(cast((2530967061762658367) as decimal),
exp(repeat('1',32)),((period_add(579349005,27636))xor (sha(current_user)))));
--error ER_DATA_OUT_OF_RANGE
do st_mlinefromtext(
maketime(
now(),
instr(1,pow(15270551309908264860,100)),
31
)
);
--echo #
--echo # Bug#26147274 ASSERTION `ITEM->MAYBE_NULL' AT MAKE_SORTKEY_FROM_ITEM
--echo # IN SQL/FILESORT.CC
--echo #
CREATE TABLE t1 (
col_datetime_1_not_null datetime NOT NULL,
col_datetime_2_not_null datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
SET sql_mode=NO_ENGINE_SUBSTITUTION;
INSERT INTO t1 VALUES ('0000-00-00 00:00:00.0','2005-12-22 19:53:31.01');
INSERT INTO t1 VALUES ('9999-00-00 00:00:00.0','2005-12-22 19:53:31.01');
SET sql_mode=default;
SELECT * FROM t1 order by col_datetime_1_not_null;
SELECT LEAST( '2005-06-05',
LEAST( col_datetime_1_not_null , col_datetime_2_not_null ) )
AS c1 FROM t1 ORDER BY c1;
DROP TABLE t1;
--echo #
--echo # Tests of date/time literals with time zone displacement.
--echo #
SET time_zone = '+00:00';
SELECT CAST('2019-09-20 10:00:00.999999+00:00' AS DATETIME);
SELECT CAST('2019-09-20 10:00:00.999999+00:00' AS DATETIME(1));
SELECT CAST('2019-09-20 10:00:00.999999+00:00' AS DATETIME(2));
SELECT CAST('2019-09-20 10:00:00.999999+00:00' AS DATETIME(3));
SELECT CAST('2019-09-20 10:00:00.999999+00:00' AS DATETIME(4));
SELECT CAST('2019-09-20 10:00:00.999999+00:00' AS DATETIME(5));
SELECT CAST('2019-09-20 10:00:00.999999+00:00' AS DATETIME(6));
SELECT CAST('2019-09-20 10:00:00.999999+02:00' AS DATETIME);
SELECT CAST('2019-09-20 10:00:00.999999+02:00' AS DATETIME(1));
SELECT CAST('2019-09-20 10:00:00.999999+02:00' AS DATETIME(2));
SELECT CAST('2019-09-20 10:00:00.999999+02:00' AS DATETIME(3));
SELECT CAST('2019-09-20 10:00:00.999999+02:00' AS DATETIME(4));
SELECT CAST('2019-09-20 10:00:00.999999+02:00' AS DATETIME(5));
SELECT CAST('2019-09-20 10:00:00.999999+02:00' AS DATETIME(6));
SELECT TIMESTAMP'2019-09-20 10:00:00.999999+02:00 ';
SET time_zone = DEFAULT;
--echo # Bug#32915973: Prepare DATE_ADD/DATE_SUB incorrectly returns DATETIME
# Check prepared statements with various DATETIME comparisons
set @d_str = '2020-01-01';
set @t_str = '01:01:01';
set @dt_str = '2020-01-01 01:01:01';
set @dt_tz = '2020-01-01 01:01:01+03:00';
set @d_int = 20200101;
set @t_int = 010101;
set @dt_int = 20200101010101;
set @d_dec = 20200101.0;
set @t_dec = 010101.0;
set @dt_dec = 20200101010101.0;
set @d_flt = 20200101E0;
set @t_flt = 010101E0;
set @dt_flt = 20200101010101E0;
# Executions that supply a date literal will convert the literal to a
# DATETIME value, and the comparison should fail.
# Executions that supply a time literal will convert the literal to a
# DATE value, and the comparison will fail.
# Executions that supply a datetime literal will need no conversions and
# the comparison should succeed.
prepare stmt from "SELECT TIMESTAMP'2020-01-01 01:01:01' = ?";
execute stmt using @d_str;
prepare stmt from "SELECT TIMESTAMP'2020-01-01 01:01:01' = ?";
execute stmt using @t_str;
prepare stmt from "SELECT TIMESTAMP'2020-01-01 01:01:01' = ?";
execute stmt using @dt_str;
prepare stmt from "SELECT TIMESTAMP'2020-01-01 01:01:01' = ?";
execute stmt using @dt_tz;
prepare stmt from "SELECT TIMESTAMP'2020-01-01 01:01:01' = ?";
execute stmt using @d_int;
prepare stmt from "SELECT TIMESTAMP'2020-01-01 01:01:01' = ?";
execute stmt using @t_int;
prepare stmt from "SELECT TIMESTAMP'2020-01-01 01:01:01' = ?";
execute stmt using @dt_int;
prepare stmt from "SELECT TIMESTAMP'2020-01-01 01:01:01' = ?";
execute stmt using @d_dec;
prepare stmt from "SELECT TIMESTAMP'2020-01-01 01:01:01' = ?";
execute stmt using @t_dec;
prepare stmt from "SELECT TIMESTAMP'2020-01-01 01:01:01' = ?";
execute stmt using @dt_dec;
prepare stmt from "SELECT TIMESTAMP'2020-01-01 01:01:01' = ?";
execute stmt using @d_flt;
prepare stmt from "SELECT TIMESTAMP'2020-01-01 01:01:01' = ?";
execute stmt using @t_flt;
prepare stmt from "SELECT TIMESTAMP'2020-01-01 01:01:01' = ?";
execute stmt using @dt_flt;
deallocate prepare stmt;
--echo # Bug#33788832: wrong result with COALESCE function
CREATE TABLE t1 (
pk INTEGER PRIMARY KEY,
t0 TIME NOT NULL,
t1 TIME NOT NULL,
dt DATETIME
);
INSERT INTO t1 VALUES
(1, TIME'08:00:00', TIME'12:00:00', TIMESTAMP'2020-01-01 00:00:00'),
(2, TIME'12:00:00', TIME'12:00:00', TIMESTAMP'2020-01-01 00:00:00'),
(3, TIME'16:00:00', TIME'12:00:00', TIMESTAMP'2020-01-01 00:00:00');
SELECT pk, t0, t1, dt,
t0 BETWEEN NULL AND t1 AS b1,
t0 NOT BETWEEN NULL AND t1 AS b2,
t0 BETWEEN NULL AND COALESCE(t1, dt) AS b3,
t0 NOT BETWEEN NULL AND COALESCE(t1, dt) AS b4
FROM t1;
SELECT pk, t0, t1, dt,
t1 BETWEEN t0 AND NULL AS b1,
t1 NOT BETWEEN t0 AND NULL AS b2,
t1 BETWEEN COALESCE(t0, dt) AND NULL AS b3,
t1 NOT BETWEEN COALESCE(t0, dt) AND NULL AS b4
FROM t1;
DROP TABLE t1;
--echo #
--echo # Bug #33897969 DATE/DATETIME
--echo # type cover other values type in Item_func_in
--echo #
CREATE TABLE t1 (
pk INTEGER PRIMARY KEY,
col_date date DEFAULT NULL,
col_datetime datetime DEFAULT NULL,
col_varchar VARCHAR(1) DEFAULT NULL,
KEY (col_varchar)
);
INSERT INTO t1 VALUES(5, '2022-02-25', '2022-02-25 11:01:14', 'I');
SELECT * FROM t1 WHERE pk = 5 AND
(col_datetime, col_varchar)
IN (('2022-02-25 11:01:14', 'Y'), ('2022-02-25 11:01:14', 'I'));
SELECT * FROM t1 WHERE pk = 5 AND
(col_datetime, col_varchar) IN ((@a, @b), (@c, @d));
SELECT * FROM t1 WHERE pk = 5 AND
(col_date, col_varchar) IN (('2022-02-25', 'Y'), ('2022-02-25', 'I'));
SELECT * FROM t1 wHERE pk = 5 AND
(col_varchar, col_date) IN (('Y','2022-02-25'), ('I', '2022-02-25'));
SELECT * FROM t1 wHERE pk = 5 AND
(col_varchar, col_date) IN (('I','2022-02-25'), ('I', '2022-02-25'));
DROP TABLE t1;
--echo #
--echo # Bug#35080094: MySQL server crash -
--echo # Assertion CompatibleTypesForIndexLookup failed
--echo #
CREATE TABLE t(a VARCHAR(100) CHARSET latin1, KEY(a));
INSERT INTO t VALUES ('2023-1-1 1:2:3'), ('2023-01-01 01:02:03');
--sorted_result
SELECT * FROM t WHERE a = TIMESTAMP'2023-01-01 01:02:03';
DROP TABLE t;
--echo #
--echo # Bug#35115909: Wrong join result when one of the join columns
--echo # is compared to a temporal literal
--echo #
CREATE TABLE t (a VARCHAR(30) CHARSET latin1,
b VARCHAR(30) CHARSET latin1);
INSERT INTO t VALUES
('2023-01-01 01:02:03', '2023-01-01 01:02:03'),
('2023-01-01 01:02:03', '2023-1-1 1:2:3'),
('2023-1-1 1:2:3', '2023-01-01 01:02:03'),
('2023-1-1 1:2:3', '2023-1-1 1:2:3');
# Used to return four rows. Should return only those two rows that
# satisfy the a=b predicate.
--sorted_result
SELECT * FROM t WHERE a = b and b = TIMESTAMP'2023-01-01 01:02:03';
DROP TABLE t;
--echo #
--echo # Bug#35173907: Assertion `CompatibleTypesForIndexLookup(eq_item,
--echo # field, right)' failed
--echo #
# Complements a test case with the same bug number in type_time. The
# assertion was only seen when the indexed column was a TIME column,
# so this test case is only for extra test coverage.
CREATE TABLE t(a DATETIME, KEY(a));
INSERT INTO t VALUES ('2023-03-15 00:00:00');
SET timestamp = UNIX_TIMESTAMP('2023-03-15 01:02:03');
SELECT * FROM t WHERE a = CURRENT_TIME;
SELECT * FROM t WHERE a = CURRENT_TIMESTAMP;
SELECT * FROM t WHERE a = CURRENT_DATE;
SET timestamp = DEFAULT;
DROP TABLE t;
|