Loading mysql-test/r/type_datetime.result +14 −0 Original line number Diff line number Diff line Loading @@ -436,3 +436,17 @@ f1 Warnings: Warning 1292 Truncated incorrect datetime value: '0000-00-00 45:44:44' drop table t1; create table t1 (a tinyint); insert into t1 values (), (), (); select sum(a) from t1 group by convert(a, datetime); sum(a) NULL select convert(a, datetime) from t1; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr def convert(a, datetime) 12 29 0 Y 128 6 63 convert(a, datetime) NULL NULL NULL drop table t1; End of 5.0 tests mysql-test/t/type_datetime.test +13 −0 Original line number Diff line number Diff line Loading @@ -292,3 +292,16 @@ insert into t1 set f1 = '45:44:44'; insert into t1 set f1 = '15:44:44'; select * from t1 where (convert(f1,datetime)) != 1; drop table t1; # # Bug #31249: problem with convert(..., datetime) # create table t1 (a tinyint); insert into t1 values (), (), (); select sum(a) from t1 group by convert(a, datetime); --enable_metadata select convert(a, datetime) from t1; --disable_metadata drop table t1; --echo End of 5.0 tests sql/item_timefunc.h +3 −1 Original line number Diff line number Diff line Loading @@ -844,7 +844,9 @@ class Item_datetime_typecast :public Item_typecast_maybe_null enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } void fix_length_and_dec() { Item_typecast_maybe_null::fix_length_and_dec(); collation.set(&my_charset_bin); maybe_null= 1; max_length= MAX_DATETIME_FULL_WIDTH * MY_CHARSET_BIN_MB_MAXLEN; decimals= DATETIME_DEC; } Loading sql/sql_select.cc +22 −4 Original line number Diff line number Diff line Loading @@ -13902,13 +13902,31 @@ calc_group_buffer(JOIN *join,ORDER *group) group_item->decimals); break; case STRING_RESULT: { enum enum_field_types type= group_item->field_type(); /* As items represented as DATE/TIME fields in the group buffer have STRING_RESULT result type, we increase the length by 8 as maximum pack length of such fields. */ if (type == MYSQL_TYPE_TIME || type == MYSQL_TYPE_DATE || type == MYSQL_TYPE_DATETIME || type == MYSQL_TYPE_TIMESTAMP) { key_length+= 8; } else { /* Group strings are taken as varstrings and require an length field. A field is not yet created by create_tmp_field() and the sizes should match up. */ key_length+= group_item->max_length + HA_KEY_BLOB_LENGTH; } break; } default: /* This case should never be choosen */ DBUG_ASSERT(0); Loading Loading
mysql-test/r/type_datetime.result +14 −0 Original line number Diff line number Diff line Loading @@ -436,3 +436,17 @@ f1 Warnings: Warning 1292 Truncated incorrect datetime value: '0000-00-00 45:44:44' drop table t1; create table t1 (a tinyint); insert into t1 values (), (), (); select sum(a) from t1 group by convert(a, datetime); sum(a) NULL select convert(a, datetime) from t1; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr def convert(a, datetime) 12 29 0 Y 128 6 63 convert(a, datetime) NULL NULL NULL drop table t1; End of 5.0 tests
mysql-test/t/type_datetime.test +13 −0 Original line number Diff line number Diff line Loading @@ -292,3 +292,16 @@ insert into t1 set f1 = '45:44:44'; insert into t1 set f1 = '15:44:44'; select * from t1 where (convert(f1,datetime)) != 1; drop table t1; # # Bug #31249: problem with convert(..., datetime) # create table t1 (a tinyint); insert into t1 values (), (), (); select sum(a) from t1 group by convert(a, datetime); --enable_metadata select convert(a, datetime) from t1; --disable_metadata drop table t1; --echo End of 5.0 tests
sql/item_timefunc.h +3 −1 Original line number Diff line number Diff line Loading @@ -844,7 +844,9 @@ class Item_datetime_typecast :public Item_typecast_maybe_null enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } void fix_length_and_dec() { Item_typecast_maybe_null::fix_length_and_dec(); collation.set(&my_charset_bin); maybe_null= 1; max_length= MAX_DATETIME_FULL_WIDTH * MY_CHARSET_BIN_MB_MAXLEN; decimals= DATETIME_DEC; } Loading
sql/sql_select.cc +22 −4 Original line number Diff line number Diff line Loading @@ -13902,13 +13902,31 @@ calc_group_buffer(JOIN *join,ORDER *group) group_item->decimals); break; case STRING_RESULT: { enum enum_field_types type= group_item->field_type(); /* As items represented as DATE/TIME fields in the group buffer have STRING_RESULT result type, we increase the length by 8 as maximum pack length of such fields. */ if (type == MYSQL_TYPE_TIME || type == MYSQL_TYPE_DATE || type == MYSQL_TYPE_DATETIME || type == MYSQL_TYPE_TIMESTAMP) { key_length+= 8; } else { /* Group strings are taken as varstrings and require an length field. A field is not yet created by create_tmp_field() and the sizes should match up. */ key_length+= group_item->max_length + HA_KEY_BLOB_LENGTH; } break; } default: /* This case should never be choosen */ DBUG_ASSERT(0); Loading