Commit b9ea778f authored by Alexander Barkov's avatar Alexander Barkov

MDEV-18503 Assertion `native.length() == binlen' failed in...

MDEV-18503 Assertion `native.length() == binlen' failed in Type_handler_timestamp_common::make_sort_key
parent d8e936a2
......@@ -1251,5 +1251,21 @@ Warning 1292 Incorrect datetime value: '1' for column `test`.`t1`.`f` at row 1
Warning 1292 Incorrect datetime value: '2' for column `test`.`t1`.`f` at row 2
DROP TABLE t1;
#
# MDEV-18503 Assertion `native.length() == binlen' failed in Type_handler_timestamp_common::make_sort_key
#
SET sql_mode='';
CREATE TABLE t1 (a TIMESTAMP(3) DEFAULT 0, b TIMESTAMP);
INSERT INTO t1 (b) VALUES ('2012-12-12 12:12:12'),('1988-08-26 12:12:12');
SELECT GREATEST(a,b) AS f FROM t1 ORDER BY 1;
f
1988-08-26 12:12:12.000
2012-12-12 12:12:12.000
SELECT GREATEST(a,b) AS f FROM t1 ORDER BY 1 DESC;
f
2012-12-12 12:12:12.000
1988-08-26 12:12:12.000
DROP TABLE t1;
SET sql_mode=DEFAULT;
#
# End of 10.4 tests
#
......@@ -825,6 +825,18 @@ SELECT * FROM t1 WHERE f IN (DEFAULT(t),1);
DROP TABLE t1;
--echo #
--echo # MDEV-18503 Assertion `native.length() == binlen' failed in Type_handler_timestamp_common::make_sort_key
--echo #
SET sql_mode='';
CREATE TABLE t1 (a TIMESTAMP(3) DEFAULT 0, b TIMESTAMP);
INSERT INTO t1 (b) VALUES ('2012-12-12 12:12:12'),('1988-08-26 12:12:12');
SELECT GREATEST(a,b) AS f FROM t1 ORDER BY 1;
SELECT GREATEST(a,b) AS f FROM t1 ORDER BY 1 DESC;
DROP TABLE t1;
SET sql_mode=DEFAULT;
--echo #
--echo # End of 10.4 tests
--echo #
......@@ -1067,8 +1067,9 @@ Type_handler_timestamp_common::make_sort_key(uchar *to, Item *item,
const SORT_FIELD_ATTR *sort_field,
Sort_param *param) const
{
THD *thd= current_thd;
uint binlen= my_timestamp_binary_length(item->decimals);
Timestamp_or_zero_datetime_native_null native(current_thd, item);
Timestamp_or_zero_datetime_native_null native(thd, item);
if (native.is_null() || native.is_zero_datetime())
{
// NULL or '0000-00-00 00:00:00'
......@@ -1076,9 +1077,19 @@ Type_handler_timestamp_common::make_sort_key(uchar *to, Item *item,
}
else
{
DBUG_ASSERT(native.length() == binlen);
if (item->maybe_null)
*to++= 1;
if (native.length() != binlen)
{
/*
Some items can return native representation with a different
number of fractional digits, e.g.: GREATEST(ts_3, ts_4) can
return a value with 3 fractional digits, although its fractional
precision is 4. Re-pack with a proper precision now.
*/
Timestamp(native).to_native(&native, item->datetime_precision(thd));
}
DBUG_ASSERT(native.length() == binlen);
memcpy((char *) to, native.ptr(), binlen);
}
}
......
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