mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Fix bug #12537 UNION produces longtext instead of varchar
Item::tmp_table_field_from_field_type() and create_tmp_field_from_item() was converting string field to blob depending on byte-wise length instead of character length, which results in converting valid varchar string with length == 86 to longtext. Made that functions above take into account max width of character when converting string fields to blobs.
This commit is contained in:
@ -580,6 +580,13 @@ ERROR 42000: Incorrect database name 'xyz'
|
|||||||
create table t1(t1.name int);
|
create table t1(t1.name int);
|
||||||
create table t2(test.t2.name int);
|
create table t2(test.t2.name int);
|
||||||
drop table t1,t2;
|
drop table t1,t2;
|
||||||
|
CREATE TABLE t1 (f1 VARCHAR(255) CHARACTER SET utf8);
|
||||||
|
CREATE TABLE t2 AS SELECT LEFT(f1,86) AS f2 FROM t1 UNION SELECT LEFT(f1,86)
|
||||||
|
AS f2 FROM t1;
|
||||||
|
DESC t2;
|
||||||
|
Field Type Null Key Default Extra
|
||||||
|
f2 varchar(86) YES NULL
|
||||||
|
DROP TABLE t1,t2;
|
||||||
create database mysqltest;
|
create database mysqltest;
|
||||||
use mysqltest;
|
use mysqltest;
|
||||||
drop database mysqltest;
|
drop database mysqltest;
|
||||||
|
@ -492,6 +492,15 @@ create table t1(t1.name int);
|
|||||||
create table t2(test.t2.name int);
|
create table t2(test.t2.name int);
|
||||||
drop table t1,t2;
|
drop table t1,t2;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Bug #12537: UNION produces longtext instead of varchar
|
||||||
|
#
|
||||||
|
CREATE TABLE t1 (f1 VARCHAR(255) CHARACTER SET utf8);
|
||||||
|
CREATE TABLE t2 AS SELECT LEFT(f1,86) AS f2 FROM t1 UNION SELECT LEFT(f1,86)
|
||||||
|
AS f2 FROM t1;
|
||||||
|
DESC t2;
|
||||||
|
DROP TABLE t1,t2;
|
||||||
|
|
||||||
#
|
#
|
||||||
# Bug#11028: Crash on create table like
|
# Bug#11028: Crash on create table like
|
||||||
#
|
#
|
||||||
|
@ -2022,12 +2022,14 @@ Field *Item::tmp_table_field_from_field_type(TABLE *table)
|
|||||||
case MYSQL_TYPE_ENUM:
|
case MYSQL_TYPE_ENUM:
|
||||||
case MYSQL_TYPE_SET:
|
case MYSQL_TYPE_SET:
|
||||||
case MYSQL_TYPE_VAR_STRING:
|
case MYSQL_TYPE_VAR_STRING:
|
||||||
if (max_length > 255)
|
DBUG_ASSERT(collation.collation);
|
||||||
|
if (max_length/collation.collation->mbmaxlen > 255)
|
||||||
break; // If blob
|
break; // If blob
|
||||||
return new Field_varstring(max_length, maybe_null, name, table,
|
return new Field_varstring(max_length, maybe_null, name, table,
|
||||||
collation.collation);
|
collation.collation);
|
||||||
case MYSQL_TYPE_STRING:
|
case MYSQL_TYPE_STRING:
|
||||||
if (max_length > 255) // If blob
|
DBUG_ASSERT(collation.collation);
|
||||||
|
if (max_length/collation.collation->mbmaxlen > 255) // If blob
|
||||||
break;
|
break;
|
||||||
return new Field_string(max_length, maybe_null, name, table,
|
return new Field_string(max_length, maybe_null, name, table,
|
||||||
collation.collation);
|
collation.collation);
|
||||||
|
@ -4899,7 +4899,8 @@ static Field* create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
|
|||||||
item->name, table, item->unsigned_flag);
|
item->name, table, item->unsigned_flag);
|
||||||
break;
|
break;
|
||||||
case STRING_RESULT:
|
case STRING_RESULT:
|
||||||
if (item->max_length > 255)
|
DBUG_ASSERT(item->collation.collation);
|
||||||
|
if (item->max_length/item->collation.collation->mbmaxlen > 255)
|
||||||
{
|
{
|
||||||
if (convert_blob_length)
|
if (convert_blob_length)
|
||||||
new_field= new Field_varstring(convert_blob_length, maybe_null,
|
new_field= new Field_varstring(convert_blob_length, maybe_null,
|
||||||
|
Reference in New Issue
Block a user