1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-12588 Add Type_handler::type_handler_for_tmp_table() and Type_handler::type_handler_for_union()

1. Implementing the task according to the description:

a. Adding Type_handler::type_handler_for_tmp_table().
b. Adding Type_handler::type_handler_for_union_table.
c. Adding helper methods Type_handler::varstring_type_handler(const Item*),
   Type_handler::blob_type_handler(const Item*)
d. Removing Item::make_string_field() and
   Item_func_group_concat::make_string_field().
   They are not needed any more.
e. Simplifying Item::tmp_table_field_from_field_type() to just two lines.
f. Renaming Item_type_holder::make_field_by_type() and implementing
   virtual Item_type_holder::create_tmp_field() instead.
   The new implementation is also as simple as two lines.
g. Adding a new virtual method Type_all_attributes::get_typelib(),
   to access to TYPELIB definitions for ENUM and SET columns.
h. Simplifying the code branch for TIME_RESULT, DECIMAL_RESULT, STRING_RESULT
   in Item::create_tmp_field(). It's now just one line.
i. Implementing Type_handler_enum::make_table_field() and
   Type_handler_set::make_table_field().

2. Code simplification in Field_str constructor calls.

a. Changing the "CHARSET_INFO *cs" argument in constuctors for Field_str
   and its descendants to "const DTCollation &collation". This is to
   avoid two step initialization:
   - setting Field_str::derivation and Field_str::repertoire to the
     default values first
   - then resetting them using:
     set_derivation(item->derivation, item->repertoire).

b. Removing Field::set_derivation()

c. Adding a new constructor DTCollation(CHARSET_INFO *cs),
   for the old code compatibility.

3. Changes in test results

As a side effect some test results have changed, because
in the old version Item::make_string_field() converted
TINYBLOB to VARCHAR(255). Now TINYBLOB is preserved.

a. sp-row.result
   This query:
     CREATE TABLE t1 AS SELECT tinyblob_sp_variable;
   Now preserves TINYBLOB as the data type.
   Before the patch a VARCHAR(255) was created.

b. gis-debug.result
   This is a debug test, to make sure that + and - operators
   are commutative and non-commutative correspondingly.
   The exact data type is not really important.
   (But anyway, it now chooses a better data type that fits the result)
This commit is contained in:
Alexander Barkov
2017-04-27 14:37:27 +04:00
parent b445c1ebb5
commit 441349aa06
12 changed files with 207 additions and 246 deletions

View File

@ -154,6 +154,17 @@ Type_handler::string_type_handler(uint max_octet_length)
}
const Type_handler *
Type_handler::varstring_type_handler(const Item *item)
{
if (!item->max_length)
return &type_handler_string;
if (item->too_big_for_varchar())
return blob_type_handler(item->max_length);
return &type_handler_varchar;
}
const Type_handler *
Type_handler::blob_type_handler(uint max_octet_length)
{
@ -167,6 +178,12 @@ Type_handler::blob_type_handler(uint max_octet_length)
}
const Type_handler *
Type_handler::blob_type_handler(const Item *item)
{
return blob_type_handler(item->max_length);
}
/**
This method is used by:
- Item_sum_hybrid, e.g. MAX(item), MIN(item).
@ -1514,7 +1531,7 @@ Field *Type_handler_string::make_table_field(const LEX_CSTRING *name,
{
return new (table->in_use->mem_root)
Field_string(addr.ptr, attr.max_length, addr.null_ptr, addr.null_bit,
Field::NONE, name, attr.collation.collation);
Field::NONE, name, attr.collation);
}
@ -1529,7 +1546,7 @@ Field *Type_handler_varchar::make_table_field(const LEX_CSTRING *name,
HA_VARCHAR_PACKLENGTH(attr.max_length),
addr.null_ptr, addr.null_bit,
Field::NONE, name,
table->s, attr.collation.collation);
table->s, attr.collation);
}
@ -1542,7 +1559,7 @@ Field *Type_handler_tiny_blob::make_table_field(const LEX_CSTRING *name,
return new (table->in_use->mem_root)
Field_blob(addr.ptr, addr.null_ptr, addr.null_bit,
Field::NONE, name, table->s,
1, attr.collation.collation);
1, attr.collation);
}
@ -1555,7 +1572,7 @@ Field *Type_handler_blob::make_table_field(const LEX_CSTRING *name,
return new (table->in_use->mem_root)
Field_blob(addr.ptr, addr.null_ptr, addr.null_bit,
Field::NONE, name, table->s,
2, attr.collation.collation);
2, attr.collation);
}
@ -1569,7 +1586,7 @@ Type_handler_medium_blob::make_table_field(const LEX_CSTRING *name,
return new (table->in_use->mem_root)
Field_blob(addr.ptr, addr.null_ptr, addr.null_bit,
Field::NONE, name, table->s,
3, attr.collation.collation);
3, attr.collation);
}
@ -1582,7 +1599,7 @@ Field *Type_handler_long_blob::make_table_field(const LEX_CSTRING *name,
return new (table->in_use->mem_root)
Field_blob(addr.ptr, addr.null_ptr, addr.null_bit,
Field::NONE, name, table->s,
4, attr.collation.collation);
4, attr.collation);
}
@ -1607,12 +1624,13 @@ Field *Type_handler_enum::make_table_field(const LEX_CSTRING *name,
const Type_all_attributes &attr,
TABLE *table) const
{
/*
Will be implemented when we split Item_type_holder::make_field_by_type()
and/or reuse Type_handler::make_table_field() in make_field() in field.cc
*/
DBUG_ASSERT(0);
return 0;
TYPELIB *typelib= attr.get_typelib();
DBUG_ASSERT(typelib);
return new (table->in_use->mem_root)
Field_enum(addr.ptr, attr.max_length, addr.null_ptr, addr.null_bit,
Field::NONE, name,
get_enum_pack_length(typelib->count), typelib,
attr.collation);
}
@ -1622,12 +1640,13 @@ Field *Type_handler_set::make_table_field(const LEX_CSTRING *name,
TABLE *table) const
{
/*
Will be implemented when we split Item_type_holder::make_field_by_type()
and/or reuse Type_handler::make_table_field() in make_field() in field.cc
*/
DBUG_ASSERT(0);
return 0;
TYPELIB *typelib= attr.get_typelib();
DBUG_ASSERT(typelib);
return new (table->in_use->mem_root)
Field_set(addr.ptr, attr.max_length, addr.null_ptr, addr.null_bit,
Field::NONE, name,
get_enum_pack_length(typelib->count), typelib,
attr.collation);
}
/*************************************************************************/
@ -3714,7 +3733,7 @@ bool Type_handler_string_result::
/*
Materialization also is unable to work when create_tmp_table() will
create a blob column because item->max_length is too big.
The following test is copied from Item::make_string_field():
The following test is copied from varstring_type_handler().
*/
!inner->too_big_for_varchar();
}
@ -3730,3 +3749,33 @@ bool Type_handler_temporal_result::
}
/***************************************************************************/
const Type_handler *
Type_handler_null::type_handler_for_tmp_table(const Item *item) const
{
return &type_handler_string;
}
const Type_handler *
Type_handler_null::type_handler_for_union(const Item *item) const
{
return &type_handler_string;
}
const Type_handler *
Type_handler_olddecimal::type_handler_for_tmp_table(const Item *item) const
{
return &type_handler_newdecimal;
}
const Type_handler *
Type_handler_olddecimal::type_handler_for_union(const Item *item) const
{
return &type_handler_newdecimal;
}
/***************************************************************************/