Commit f239fd50 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-11015 Assertion failed: precision > 0 in decimal_bin_size upon SELECT...

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
parent 5fe0087a
......@@ -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
#
......@@ -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 #
......@@ -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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment