diff options
author | Alexander Barkov <bar@mariadb.com> | 2019-04-27 08:44:29 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2019-04-27 08:44:29 +0400 |
commit | f239fd5034fe66a06a7a254fe1721eae781b118e (patch) | |
tree | 7b7e8f089dccd7e58c57f4d3ef1a6ec101de36ae | |
parent | 5fe0087a7234bb0b1304c8aeb010e00eca5cce5c (diff) | |
download | mariadb-git-f239fd5034fe66a06a7a254fe1721eae781b118e.tar.gz |
MDEV-11015 Assertion failed: precision > 0 in decimal_bin_size upon SELECT with DISTINCT, CAST and other functions
Item_func_min_max::fix_length_and_dec() erroneously set max_length
to UINT32_MAX.
Merge notes:
In 10.3 this problem had been fixed earlier.
During merge to 10.3, do a "null merge" in item_func.cc
-rw-r--r-- | mysql-test/r/func_hybrid_type.result | 40 | ||||
-rw-r--r-- | mysql-test/t/func_hybrid_type.test | 20 | ||||
-rw-r--r-- | sql/item_func.cc | 6 |
3 files changed, 60 insertions, 6 deletions
diff --git a/mysql-test/r/func_hybrid_type.result b/mysql-test/r/func_hybrid_type.result index eeaa79e7dce..dfec8b3210b 100644 --- a/mysql-test/r/func_hybrid_type.result +++ b/mysql-test/r/func_hybrid_type.result @@ -2179,10 +2179,10 @@ def if_______a_b 12 19 19 Y 128 0 63 def if_______b_a 12 19 19 Y 128 0 63 def ifnull___a_b 12 19 19 Y 128 0 63 def ifnull___b_a 12 19 19 Y 128 0 63 -def least____a_b 12 10 19 Y 128 0 63 -def least____b_a 12 10 19 Y 128 0 63 -def greatest_a_b 12 10 19 Y 128 0 63 -def greatest_b_a 12 10 19 Y 128 0 63 +def least____a_b 12 19 19 Y 128 0 63 +def least____b_a 12 19 19 Y 128 0 63 +def greatest_a_b 12 19 19 Y 128 0 63 +def greatest_b_a 12 19 19 Y 128 0 63 case_____a_b 2010-01-01 00:00:00 case_____b_a 2001-01-01 10:20:30 coalesce_a_b 2010-01-01 00:00:00 @@ -3034,7 +3034,7 @@ DROP TABLE t1; SET timestamp=UNIX_TIMESTAMP('2010-01-01 01:02:03'); SELECT GREATEST(CURRENT_TIME, CURRENT_DATE), COALESCE(CURRENT_TIME, CURRENT_DATE); Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def GREATEST(CURRENT_TIME, CURRENT_DATE) 12 10 19 N 129 0 63 +def GREATEST(CURRENT_TIME, CURRENT_DATE) 12 19 19 N 129 0 63 def COALESCE(CURRENT_TIME, CURRENT_DATE) 12 19 19 N 129 0 63 GREATEST(CURRENT_TIME, CURRENT_DATE) COALESCE(CURRENT_TIME, CURRENT_DATE) 2010-01-01 01:02:03 2010-01-01 01:02:03 @@ -3427,5 +3427,35 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t1; # +# MDEV-11015 Assertion failed: precision > 0 in decimal_bin_size upon SELECT with DISTINCT, CAST and other functions +# +CREATE TABLE t1 (b LONGBLOB); +INSERT IGNORE INTO t1 VALUES ('foo'),('bar'); +SELECT DISTINCT - GREATEST( b, CAST( NULL AS DATETIME ) ) AS f FROM t1; +f +NULL +Warnings: +Warning 1292 Incorrect datetime value: 'foo' +Warning 1292 Incorrect datetime value: 'bar' +DROP TABLE t1; +CREATE TABLE t1 (b LONGBLOB); +INSERT IGNORE INTO t1 VALUES ('foo'),('bar'); +SELECT DISTINCT - GREATEST( b, CAST( NULL AS TIME) ) AS f FROM t1; +f +NULL +Warnings: +Warning 1292 Truncated incorrect time value: 'foo' +Warning 1292 Truncated incorrect time value: 'bar' +DROP TABLE t1; +CREATE TABLE t1 (b LONGBLOB); +INSERT IGNORE INTO t1 VALUES ('foo'),('bar'); +SELECT DISTINCT - GREATEST( b, CAST( NULL AS DATE) ) AS f FROM t1; +f +NULL +Warnings: +Warning 1292 Incorrect datetime value: 'foo' +Warning 1292 Incorrect datetime value: 'bar' +DROP TABLE t1; +# # End of 10.1 tests # diff --git a/mysql-test/t/func_hybrid_type.test b/mysql-test/t/func_hybrid_type.test index dd8a399025b..c07303f7450 100644 --- a/mysql-test/t/func_hybrid_type.test +++ b/mysql-test/t/func_hybrid_type.test @@ -456,6 +456,26 @@ EXECUTE stmt USING @a,@a; SHOW CREATE TABLE t1; DROP TABLE t1; + +--echo # +--echo # MDEV-11015 Assertion failed: precision > 0 in decimal_bin_size upon SELECT with DISTINCT, CAST and other functions +--echo # + +CREATE TABLE t1 (b LONGBLOB); +INSERT IGNORE INTO t1 VALUES ('foo'),('bar'); +SELECT DISTINCT - GREATEST( b, CAST( NULL AS DATETIME ) ) AS f FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (b LONGBLOB); +INSERT IGNORE INTO t1 VALUES ('foo'),('bar'); +SELECT DISTINCT - GREATEST( b, CAST( NULL AS TIME) ) AS f FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (b LONGBLOB); +INSERT IGNORE INTO t1 VALUES ('foo'),('bar'); +SELECT DISTINCT - GREATEST( b, CAST( NULL AS DATE) ) AS f FROM t1; +DROP TABLE t1; + --echo # --echo # End of 10.1 tests --echo # diff --git a/sql/item_func.cc b/sql/item_func.cc index a1a2c3f1d1c..86111374175 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2793,6 +2793,7 @@ void Item_func_min_max::fix_length_and_dec() switch (tmp_cmp_type) { case TIME_RESULT: + { // At least one temporal argument was found. if (temporal_type_count < arg_count) maybe_null= true; // Non-temporal-to-temporal conversion can return NULL @@ -2802,8 +2803,11 @@ void Item_func_min_max::fix_length_and_dec() set_if_smaller(decimals, TIME_SECOND_PART_DIGITS); else decimals= 0; + uint len= decimals ? (decimals + 1) : 0; + len+= mysql_temporal_int_part_length(temporal_field_type); + fix_char_length(len); break; - + } case STRING_RESULT: /* All arguments are of string-alike types: |