diff options
author | Alexander Barkov <bar@mariadb.com> | 2020-07-31 10:42:44 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2020-07-31 17:45:39 +0400 |
commit | dc513dff911d72eaaf9f752f390fef8d1ef9a4b0 (patch) | |
tree | 3af27646a38985babb5e2094aecf4e144060d4bd /mysql-test | |
parent | a773d932678a0b205f43d8a1aaa416d843d66bc8 (diff) | |
download | mariadb-git-dc513dff911d72eaaf9f752f390fef8d1ef9a4b0.tar.gz |
MDEV-23351 Rounding functions return wrong data types for DATE input
Fixing ROUND(date,0), TRUNCATE(date,x), FLOOR(date), CEILING(date)
to return the `int(8) unsigned` data type.
Details:
1. Cleanup: moving virtual implementations
- Type_handler_temporal_result::Item_func_int_val_fix_length_and_dec()
- Type_handler_temporal_result::Item_func_round_fix_length_and_dec()
to Type_handler_date_common. Other temporal data type handlers
override these methods anyway. So they were only DATE specific.
This change makes the code clearer.
2. Backporting DTCollation_numeric from 10.5, to reuse the code easier.
3. Adding the `preferred_attrs` argument to Item_func_round::fix_arg_int(). Now
Type_handler_xxx::Item_func_round_val_fix_length_and_dec() work as follows:
- The INT-alike and YEAR handlers copy preferred_attrs from args[0].
- The DATE handler passes explicit attributes, to get `int(8) unsigned`.
- The hex hybrid handler passes NULL, so fix_arg_int() calculates attributes.
4. Type_handler_date_common::Item_func_int_val_fix_length_and_dec()
now sets the type handler and attributes to get `int(8) unsigned`.
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/main/type_date.result | 14 | ||||
-rw-r--r-- | mysql-test/main/type_date.test | 8 |
2 files changed, 22 insertions, 0 deletions
diff --git a/mysql-test/main/type_date.result b/mysql-test/main/type_date.result index 616ba0a4529..f40a27e5f5c 100644 --- a/mysql-test/main/type_date.result +++ b/mysql-test/main/type_date.result @@ -1089,5 +1089,19 @@ CAST(1012.5 AS DATE) * 1.0 Warnings: Note 1292 Truncated incorrect date value: '1012.5' # +# MDEV-23351 Rounding functions return wrong data types for DATE input +# +CREATE TABLE t1 (a date); +CREATE TABLE t2 AS SELECT FLOOR(a), CEIL(a),ROUND(a),TRUNCATE(a,0) FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `FLOOR(a)` int(8) unsigned DEFAULT NULL, + `CEIL(a)` int(8) unsigned DEFAULT NULL, + `ROUND(a)` int(8) unsigned DEFAULT NULL, + `TRUNCATE(a,0)` int(8) unsigned DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t2,t1; +# # End of 10.4 tests # diff --git a/mysql-test/main/type_date.test b/mysql-test/main/type_date.test index c041295f845..33598846504 100644 --- a/mysql-test/main/type_date.test +++ b/mysql-test/main/type_date.test @@ -740,6 +740,14 @@ SET sql_mode=DEFAULT; SELECT NULLIF(CAST(1012.5 AS DATE), 1); SELECT CAST(1012.5 AS DATE) * 1.0; +--echo # +--echo # MDEV-23351 Rounding functions return wrong data types for DATE input +--echo # + +CREATE TABLE t1 (a date); +CREATE TABLE t2 AS SELECT FLOOR(a), CEIL(a),ROUND(a),TRUNCATE(a,0) FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2,t1; --echo # --echo # End of 10.4 tests |