mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Bug#43668: Wrong comparison and MIN/MAX for YEAR(2)
MySQL manual describes values of the YEAR(2) field type as follows: values 00 - 69 mean 2000 - 2069 years and values 70 - 99 mean 1970 - 1999 years. MIN/MAX and comparison functions was comparing them as int values thus producing wrong result. Now the Arg_comparator class is extended with compare_year function which performs correct comparison of the YEAR type. The Item_sum_hybrid class now uses Item_cache and Arg_comparator objects to correctly calculate its value. To allow Arg_comparator to use func_name() function for Item_func and Item_sum objects the func_name declaration is moved to the Item_result_field class. A helper function is_owner_equal_func is added to the Arg_comparator class. It checks whether the Arg_comparator object owner is the <=> function or not. A helper function setup is added to the Item_sum_hybrid class. It sets up cache item and comparator. mysql-test/r/func_group.result: Added a test case for the bug#43668. mysql-test/t/func_group.test: Added a test case for the bug#43668. sql/item.cc: Bug#43668: Wrong comparison and MIN/MAX for YEAR(2) Now Item_cache_int returns the type of cached item. sql/item.h: Bug#43668: Wrong comparison and MIN/MAX for YEAR(2) To allow Arg_comparator to use func_name() function for Item_func and Item_sum objects the func_name declaration is moved to the Item_result_field class. sql/item_cmpfunc.cc: Bug#43668: Wrong comparison and MIN/MAX for YEAR(2) The Arg_comparator class is extended with compare_year function which performs correct comparison of the YEAR type. sql/item_cmpfunc.h: Bug#43668: Wrong comparison and MIN/MAX for YEAR(2) The year_as_datetime variable is added to the Arg_comparator class. It's set to TRUE when YEAR value should be converted to the YYYY-00-00 00:00:00 format for correct YEAR-DATETIME comparison. sql/item_geofunc.cc: Bug#43668: Wrong comparison and MIN/MAX for YEAR(2) Item_func_spatial_rel::val_int chenged to use Arg_comparator's string buffers. sql/item_subselect.h: Bug#43668: Wrong comparison and MIN/MAX for YEAR(2) Added an implementation of the virtual func_name function. sql/item_sum.cc: Bug#43668: Wrong comparison and MIN/MAX for YEAR(2) The Item_sum_hybrid class now uses Item_cache and Arg_comparator objects to correctly calculate its value. A helper function setup is added to the Item_sum_hybrid class. It sets up cache item and comparator. sql/item_sum.h: Bug#43668: Wrong comparison and MIN/MAX for YEAR(2) The Item_sum_hybrid class now uses Item_cache and Arg_comparator objects to correctly calculate its value. Added an implementation of the virtual func_name function.
This commit is contained in:
@ -885,7 +885,7 @@ cast(sum(distinct df) as signed)
|
||||
3
|
||||
select cast(min(df) as signed) from t1;
|
||||
cast(min(df) as signed)
|
||||
0
|
||||
1
|
||||
select 1e8 * sum(distinct df) from t1;
|
||||
1e8 * sum(distinct df)
|
||||
330000000
|
||||
@ -1477,3 +1477,196 @@ COUNT(*)
|
||||
SET SQL_MODE=default;
|
||||
DROP TABLE t1;
|
||||
End of 5.0 tests
|
||||
#
|
||||
# Bug#43668: Wrong comparison and MIN/MAX for YEAR(2)
|
||||
#
|
||||
create table t1 (f1 year(2), f2 year(4), f3 date, f4 datetime);
|
||||
insert into t1 values
|
||||
(98,1998,19980101,"1998-01-01 00:00:00"),
|
||||
(00,2000,20000101,"2000-01-01 00:00:01"),
|
||||
(02,2002,20020101,"2002-01-01 23:59:59"),
|
||||
(60,2060,20600101,"2060-01-01 11:11:11"),
|
||||
(70,1970,19700101,"1970-11-11 22:22:22"),
|
||||
(NULL,NULL,NULL,NULL);
|
||||
select min(f1),max(f1) from t1;
|
||||
min(f1) max(f1)
|
||||
70 60
|
||||
select min(f2),max(f2) from t1;
|
||||
min(f2) max(f2)
|
||||
1970 2060
|
||||
select min(f3),max(f3) from t1;
|
||||
min(f3) max(f3)
|
||||
1970-01-01 2060-01-01
|
||||
select min(f4),max(f4) from t1;
|
||||
min(f4) max(f4)
|
||||
1970-11-11 22:22:22 2060-01-01 11:11:11
|
||||
select a.f1 as a, b.f1 as b, a.f1 > b.f1 as gt,
|
||||
a.f1 < b.f1 as lt, a.f1<=>b.f1 as eq
|
||||
from t1 a, t1 b;
|
||||
a b gt lt eq
|
||||
98 98 0 0 1
|
||||
00 98 1 0 0
|
||||
02 98 1 0 0
|
||||
60 98 1 0 0
|
||||
70 98 0 1 0
|
||||
NULL 98 NULL NULL 0
|
||||
98 00 0 1 0
|
||||
00 00 0 0 1
|
||||
02 00 1 0 0
|
||||
60 00 1 0 0
|
||||
70 00 0 1 0
|
||||
NULL 00 NULL NULL 0
|
||||
98 02 0 1 0
|
||||
00 02 0 1 0
|
||||
02 02 0 0 1
|
||||
60 02 1 0 0
|
||||
70 02 0 1 0
|
||||
NULL 02 NULL NULL 0
|
||||
98 60 0 1 0
|
||||
00 60 0 1 0
|
||||
02 60 0 1 0
|
||||
60 60 0 0 1
|
||||
70 60 0 1 0
|
||||
NULL 60 NULL NULL 0
|
||||
98 70 1 0 0
|
||||
00 70 1 0 0
|
||||
02 70 1 0 0
|
||||
60 70 1 0 0
|
||||
70 70 0 0 1
|
||||
NULL 70 NULL NULL 0
|
||||
98 NULL NULL NULL 0
|
||||
00 NULL NULL NULL 0
|
||||
02 NULL NULL NULL 0
|
||||
60 NULL NULL NULL 0
|
||||
70 NULL NULL NULL 0
|
||||
NULL NULL NULL NULL 1
|
||||
select a.f1 as a, b.f2 as b, a.f1 > b.f2 as gt,
|
||||
a.f1 < b.f2 as lt, a.f1<=>b.f2 as eq
|
||||
from t1 a, t1 b;
|
||||
a b gt lt eq
|
||||
98 1998 0 0 1
|
||||
00 1998 1 0 0
|
||||
02 1998 1 0 0
|
||||
60 1998 1 0 0
|
||||
70 1998 0 1 0
|
||||
NULL 1998 NULL NULL 0
|
||||
98 2000 0 1 0
|
||||
00 2000 0 0 1
|
||||
02 2000 1 0 0
|
||||
60 2000 1 0 0
|
||||
70 2000 0 1 0
|
||||
NULL 2000 NULL NULL 0
|
||||
98 2002 0 1 0
|
||||
00 2002 0 1 0
|
||||
02 2002 0 0 1
|
||||
60 2002 1 0 0
|
||||
70 2002 0 1 0
|
||||
NULL 2002 NULL NULL 0
|
||||
98 2060 0 1 0
|
||||
00 2060 0 1 0
|
||||
02 2060 0 1 0
|
||||
60 2060 0 0 1
|
||||
70 2060 0 1 0
|
||||
NULL 2060 NULL NULL 0
|
||||
98 1970 1 0 0
|
||||
00 1970 1 0 0
|
||||
02 1970 1 0 0
|
||||
60 1970 1 0 0
|
||||
70 1970 0 0 1
|
||||
NULL 1970 NULL NULL 0
|
||||
98 NULL NULL NULL 0
|
||||
00 NULL NULL NULL 0
|
||||
02 NULL NULL NULL 0
|
||||
60 NULL NULL NULL 0
|
||||
70 NULL NULL NULL 0
|
||||
NULL NULL NULL NULL 1
|
||||
select a.f1 as a, b.f3 as b, a.f1 > b.f3 as gt,
|
||||
a.f1 < b.f3 as lt, a.f1<=>b.f3 as eq
|
||||
from t1 a, t1 b;
|
||||
a b gt lt eq
|
||||
98 1998-01-01 0 1 0
|
||||
00 1998-01-01 1 0 0
|
||||
02 1998-01-01 1 0 0
|
||||
60 1998-01-01 1 0 0
|
||||
70 1998-01-01 0 1 0
|
||||
NULL 1998-01-01 NULL NULL 0
|
||||
98 2000-01-01 0 1 0
|
||||
00 2000-01-01 0 1 0
|
||||
02 2000-01-01 1 0 0
|
||||
60 2000-01-01 1 0 0
|
||||
70 2000-01-01 0 1 0
|
||||
NULL 2000-01-01 NULL NULL 0
|
||||
98 2002-01-01 0 1 0
|
||||
00 2002-01-01 0 1 0
|
||||
02 2002-01-01 0 1 0
|
||||
60 2002-01-01 1 0 0
|
||||
70 2002-01-01 0 1 0
|
||||
NULL 2002-01-01 NULL NULL 0
|
||||
98 2060-01-01 0 1 0
|
||||
00 2060-01-01 0 1 0
|
||||
02 2060-01-01 0 1 0
|
||||
60 2060-01-01 0 1 0
|
||||
70 2060-01-01 0 1 0
|
||||
NULL 2060-01-01 NULL NULL 0
|
||||
98 1970-01-01 1 0 0
|
||||
00 1970-01-01 1 0 0
|
||||
02 1970-01-01 1 0 0
|
||||
60 1970-01-01 1 0 0
|
||||
70 1970-01-01 0 1 0
|
||||
NULL 1970-01-01 NULL NULL 0
|
||||
98 NULL NULL NULL 0
|
||||
00 NULL NULL NULL 0
|
||||
02 NULL NULL NULL 0
|
||||
60 NULL NULL NULL 0
|
||||
70 NULL NULL NULL 0
|
||||
NULL NULL NULL NULL 1
|
||||
select a.f1 as a, b.f4 as b, a.f1 > b.f4 as gt,
|
||||
a.f1 < b.f4 as lt, a.f1<=>b.f4 as eq
|
||||
from t1 a, t1 b;
|
||||
a b gt lt eq
|
||||
98 1998-01-01 00:00:00 0 1 0
|
||||
00 1998-01-01 00:00:00 1 0 0
|
||||
02 1998-01-01 00:00:00 1 0 0
|
||||
60 1998-01-01 00:00:00 1 0 0
|
||||
70 1998-01-01 00:00:00 0 1 0
|
||||
NULL 1998-01-01 00:00:00 NULL NULL 0
|
||||
98 2000-01-01 00:00:01 0 1 0
|
||||
00 2000-01-01 00:00:01 0 1 0
|
||||
02 2000-01-01 00:00:01 1 0 0
|
||||
60 2000-01-01 00:00:01 1 0 0
|
||||
70 2000-01-01 00:00:01 0 1 0
|
||||
NULL 2000-01-01 00:00:01 NULL NULL 0
|
||||
98 2002-01-01 23:59:59 0 1 0
|
||||
00 2002-01-01 23:59:59 0 1 0
|
||||
02 2002-01-01 23:59:59 0 1 0
|
||||
60 2002-01-01 23:59:59 1 0 0
|
||||
70 2002-01-01 23:59:59 0 1 0
|
||||
NULL 2002-01-01 23:59:59 NULL NULL 0
|
||||
98 2060-01-01 11:11:11 0 1 0
|
||||
00 2060-01-01 11:11:11 0 1 0
|
||||
02 2060-01-01 11:11:11 0 1 0
|
||||
60 2060-01-01 11:11:11 0 1 0
|
||||
70 2060-01-01 11:11:11 0 1 0
|
||||
NULL 2060-01-01 11:11:11 NULL NULL 0
|
||||
98 1970-11-11 22:22:22 1 0 0
|
||||
00 1970-11-11 22:22:22 1 0 0
|
||||
02 1970-11-11 22:22:22 1 0 0
|
||||
60 1970-11-11 22:22:22 1 0 0
|
||||
70 1970-11-11 22:22:22 0 1 0
|
||||
NULL 1970-11-11 22:22:22 NULL NULL 0
|
||||
98 NULL NULL NULL 0
|
||||
00 NULL NULL NULL 0
|
||||
02 NULL NULL NULL 0
|
||||
60 NULL NULL NULL 0
|
||||
70 NULL NULL NULL 0
|
||||
NULL NULL NULL NULL 1
|
||||
select *, f1 = f2 from t1;
|
||||
f1 f2 f3 f4 f1 = f2
|
||||
98 1998 1998-01-01 1998-01-01 00:00:00 1
|
||||
00 2000 2000-01-01 2000-01-01 00:00:01 1
|
||||
02 2002 2002-01-01 2002-01-01 23:59:59 1
|
||||
60 2060 2060-01-01 2060-01-01 11:11:11 1
|
||||
70 1970 1970-01-01 1970-11-11 22:22:22 1
|
||||
NULL NULL NULL NULL NULL
|
||||
drop table t1;
|
||||
#
|
||||
|
@ -1006,3 +1006,35 @@ DROP TABLE t1;
|
||||
|
||||
###
|
||||
--echo End of 5.0 tests
|
||||
|
||||
--echo #
|
||||
--echo # Bug#43668: Wrong comparison and MIN/MAX for YEAR(2)
|
||||
--echo #
|
||||
create table t1 (f1 year(2), f2 year(4), f3 date, f4 datetime);
|
||||
insert into t1 values
|
||||
(98,1998,19980101,"1998-01-01 00:00:00"),
|
||||
(00,2000,20000101,"2000-01-01 00:00:01"),
|
||||
(02,2002,20020101,"2002-01-01 23:59:59"),
|
||||
(60,2060,20600101,"2060-01-01 11:11:11"),
|
||||
(70,1970,19700101,"1970-11-11 22:22:22"),
|
||||
(NULL,NULL,NULL,NULL);
|
||||
select min(f1),max(f1) from t1;
|
||||
select min(f2),max(f2) from t1;
|
||||
select min(f3),max(f3) from t1;
|
||||
select min(f4),max(f4) from t1;
|
||||
select a.f1 as a, b.f1 as b, a.f1 > b.f1 as gt,
|
||||
a.f1 < b.f1 as lt, a.f1<=>b.f1 as eq
|
||||
from t1 a, t1 b;
|
||||
select a.f1 as a, b.f2 as b, a.f1 > b.f2 as gt,
|
||||
a.f1 < b.f2 as lt, a.f1<=>b.f2 as eq
|
||||
from t1 a, t1 b;
|
||||
select a.f1 as a, b.f3 as b, a.f1 > b.f3 as gt,
|
||||
a.f1 < b.f3 as lt, a.f1<=>b.f3 as eq
|
||||
from t1 a, t1 b;
|
||||
select a.f1 as a, b.f4 as b, a.f1 > b.f4 as gt,
|
||||
a.f1 < b.f4 as lt, a.f1<=>b.f4 as eq
|
||||
from t1 a, t1 b;
|
||||
select *, f1 = f2 from t1;
|
||||
drop table t1;
|
||||
--echo #
|
||||
|
||||
|
Reference in New Issue
Block a user