1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

A cleanup for MDEV-9217 Split Item::tmp_table_field_from_field_type() into virtual methods in Type_handler

Fixing that the server tried to create the old decimal for:

  CREATE TABLE t2 AS SELECT old_decimal_field FROM t1
               UNION SELECT bigint_field FROM t1;

  CREATE TABLE t2 AS SELECT old_decimal_field FROM t1
               UNION SELECT mediumint_field FROM t1;

  CREATE TABLE t2 AS SELECT year FROM t1
               UNION SELECT old_decimal_field FROM t1;

  CREATE TABLE t2 AS SELCT COALESCE(old_decimal_field) FROM t1;

Solution:

1. field_types_merge_rules[][] had three MYSQL_TYPE_DECIMAL remainders.
   Fixing to MYSQL_TYPE_NEWDECIMAL, like it is done for all other type pairs.
   This fixes the above queries with UNION.

2. Convert MYSQL_TYPE_DECIMAL to MYSQL_TYPE_NEWDECIMAL in
   Item::tmp_table_field_from_field_type().
   This fixed the above query with COALESCE.

3. Adding "new Field_decimal" into Type_handler_olddecimal::make_table_field().
   In case if something goes wrong it will crash on assert only in debug builds,
   while create the old decimal in release.
   Note, this "new Field_decimal" will be needed later anyway,
   when we reuse Type_handler::make_table_field() in make_field() in field.cc.
This commit is contained in:
Alexander Barkov
2017-04-24 16:08:28 +04:00
parent 791374354c
commit 5f1544fef3
5 changed files with 103 additions and 4 deletions

View File

@ -1281,11 +1281,15 @@ Type_handler_olddecimal::make_table_field(const LEX_CSTRING *name,
/*
Currently make_table_field() is used for Item purpose only.
On Item level we have type_handler_newdecimal only.
Will be implemented when we reuse Type_handler::make_table_field()
For now we have DBUG_ASSERT(0).
It will be removed when we reuse Type_handler::make_table_field()
in make_field() in field.cc, to open old tables with old decimal.
*/
DBUG_ASSERT(0);
return NULL;
return new (table->in_use->mem_root)
Field_decimal(addr.ptr, attr.max_length, addr.null_ptr, addr.null_bit,
Field::NONE, name, attr.decimals,
0/*zerofill*/,attr.unsigned_flag);
}