Skip to content
Permalink
Browse files
MDEV-18503 Assertion `native.length() == binlen' failed in Type_handl…
…er_timestamp_common::make_sort_key
  • Loading branch information
abarkov committed Apr 2, 2019
1 parent d8e936a commit b9ea778
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
@@ -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,18 +1067,29 @@ 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'
bzero(to, item->maybe_null ? binlen + 1 : binlen);
}
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);
}
}

0 comments on commit b9ea778

Please sign in to comment.