Commit ee6ac4d3 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-12574 MAX(old_decimal) produces a column of the old DECIMAL type

parent 01bbb912
......@@ -1033,5 +1033,30 @@ c1 c2
0.123456 0.123456
SET sql_mode=DEFAULT;
#
# MDEV-12574 MAX(old_decimal) produces a column of the old DECIMAL type
#
SHOW CREATE TABLE t1dec102;
Table Create Table
t1dec102 CREATE TABLE `t1dec102` (
`a` decimal(10,2)/*old*/ DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE t1 AS SELECT a, MAX(a), COALESCE(a) FROM t1dec102;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` decimal(10,2) DEFAULT NULL,
`MAX(a)` decimal(10,2) DEFAULT NULL,
`COALESCE(a)` decimal(12,2) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
CREATE TABLE t1 AS SELECT a FROM t1dec102 UNION SELECT a FROM t1dec102;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` decimal(12,2) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
DROP TABLE t1dec102;
#
# End of 10.2 tests
#
......@@ -627,6 +627,27 @@ SELECT
CAST(TIME'00:00:00.123456' AS DECIMAL(10,6)) AS c2;
SET sql_mode=DEFAULT;
--echo #
--echo # MDEV-12574 MAX(old_decimal) produces a column of the old DECIMAL type
--echo #
let $MYSQLD_DATADIR= `select @@datadir`;
--copy_file std_data/old_decimal/t1dec102.frm $MYSQLD_DATADIR/test/t1dec102.frm
--copy_file std_data/old_decimal/t1dec102.MYD $MYSQLD_DATADIR/test/t1dec102.MYD
--copy_file std_data/old_decimal/t1dec102.MYI $MYSQLD_DATADIR/test/t1dec102.MYI
SHOW CREATE TABLE t1dec102;
CREATE TABLE t1 AS SELECT a, MAX(a), COALESCE(a) FROM t1dec102;
SHOW CREATE TABLE t1;
DROP TABLE t1;
CREATE TABLE t1 AS SELECT a FROM t1dec102 UNION SELECT a FROM t1dec102;
SHOW CREATE TABLE t1;
DROP TABLE t1;
DROP TABLE t1dec102;
--echo #
--echo # End of 10.2 tests
--echo #
......@@ -2973,6 +2973,23 @@ void Field_decimal::sql_type(String &res) const
}
Field *Field_decimal::make_new_field(MEM_ROOT *root, TABLE *new_table,
bool keep_type)
{
if (keep_type)
return Field_real::make_new_field(root, new_table, keep_type);
Field *field= new (root) Field_new_decimal(NULL, field_length,
maybe_null() ? (uchar*) "" : 0, 0,
NONE, field_name,
dec, flags & ZEROFILL_FLAG,
unsigned_flag);
if (field)
field->init_for_make_new_field(new_table, orig_table);
return field;
}
/****************************************************************************
** Field_new_decimal
****************************************************************************/
......@@ -7439,15 +7456,7 @@ Field *Field_string::make_new_field(MEM_ROOT *root, TABLE *new_table,
This is done to ensure that ALTER TABLE will convert old VARCHAR fields
to now VARCHAR fields.
*/
field->init(new_table);
/*
Normally orig_table is different from table only if field was
created via ::make_new_field. Here we alter the type of field,
so ::make_new_field is not applicable. But we still need to
preserve the original field metadata for the client-server
protocol.
*/
field->orig_table= orig_table;
field->init_for_make_new_field(new_table, orig_table);
}
return field;
}
......
......@@ -1368,6 +1368,18 @@ class Field: public Value_source
orig_table= table= table_arg;
set_table_name(&table_arg->alias);
}
void init_for_make_new_field(TABLE *new_table_arg, TABLE *orig_table_arg)
{
init(new_table_arg);
/*
Normally orig_table is different from table only if field was
created via ::make_new_field. Here we alter the type of field,
so ::make_new_field is not applicable. But we still need to
preserve the original field metadata for the client-server
protocol.
*/
orig_table= orig_table_arg;
}
/* maximum possible display length */
virtual uint32 max_display_length()= 0;
......@@ -1828,6 +1840,7 @@ class Field_decimal :public Field_real {
unireg_check_arg, field_name_arg,
dec_arg, zero_arg, unsigned_arg)
{}
Field *make_new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type);
enum_field_types type() const { return MYSQL_TYPE_DECIMAL;}
enum ha_base_keytype key_type() const
{ return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; }
......
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