Commit e7b71e0d authored by Sujatha's avatar Sujatha

MDEV-19925: Column ... cannot be converted from type 'varchar(20)' to type 'varchar(20)'

Cherry picking:
Bug#25135304: RBR: WRONG FIELD LENGTH IN ERROR MESSAGE
commit 47bd3f7cf3c8518f62b1580ec65af2ba7ac13b95

Description:
============
In row based replication, when replicating from a table with a field with
character set set to UTF8mb3 to the same table with the same field set to
character set UTF8mb4 I get a confusing error message:

For VARCHAR: VARCHAR(1) 'utf8mb3' to VARCHAR(1) 'utf8mb4'
"Column 0 of table 'test.t1' cannot be converted from type 'varchar(3)' to
type 'varchar(1)'"

Similar issue with CHAR type as well.

Issue with respect to BLOB types:

For BLOB: LONGBLOB to TINYBLOB - Error message displays incorrect blob type.
"Column 0 of table 'test.t1' cannot be converted from type 'tinyblob' to type
'tinyblob'"

For BINARY to BINARY - Error message displays incorrect type for master side
field.
"Column 0 of table 'test.t' cannot be converted from type 'char(1)' to type
'binary(10)'"
Similar issue exists for VARBINARY type. It is displayed as 'VARCHAR'.

Analysis:
=========
In Row based replication charset information is not sent as part of metadata
from master to slave.

For VARCHAR field its character length is converted into equivalent
octets/bytes and stored internally. At the time of displaying the data to user
it is converted back to original character length.

For example:
VARCHAR(2)- utf8mb3 is stored as:2*3 = VARCHAR(6)
At the time of displaying it to user
VARCHAR(6)- charset utf8mb3:6/3= VARCHAR(2).

At present the internally converted octect length is sent from master to slave
with out providing the charset information. On slave side if the type
conversion fails 'show_sql_type' function is used to get the type specific
information from metadata. Since there is no charset information is available
the filed type is displayed as VARCHAR(6).

This results in confused error message.

For CHAR fields
CHAR(1)- utf8mb3 - CHAR(3)
CHAR(1)- utf8mb4 - CHAR(4)

'show_sql_type' function which retrieves type information from metadata uses
(bytes/local charset length) to get actual character length. If slave's chaset
is 'utf8mb4' then

CHAR(3/4)-->CHAR(0)
CHAR(4/4)-->CHAR(1).

This results in confused error message.

Analysis for BLOB type issue:

BLOB's length is represented in two forms.
1. Actual length
i.e
  (length < 256) type= MYSQL_TYPE_TINY_BLOB;
  (length < 65536) type= MYSQL_TYPE_BLOB; ...

2. packlength - The number of bytes used to represent the length of the blob
  1- tinyblob
  2- blob ...

In row based replication only the packlength is written in the binary log. On
the slave side this packlength is interpreted as actual length of the blob.
Hence the length is always < 256 and the type is displayed as tiny blob.

Analysis for BINARY to BINARY type issue:
The character set information is needed to identify a filed's type as char or
binary. Since master side character set information is not available on the
slave side both binary and char fields are displayed as char.

Fix:
===
For CHAR and VARCHAR fields display their length in octets for both source and
target fields. For target field display the charset information if it is
relevant.

For blob type changed the code to use the packlength and display appropriate
blob type in error message.

For binary and varbinary fields use the slave side character set as reference
to map them to binary or varbinary fields.
parent 9bf424bc
......@@ -468,7 +468,7 @@ INSERT INTO t10 () VALUES(1,@b1,DEFAULT,'Kyle',DEFAULT),
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t10' cannot be converted from type 'double' to type 'char(5)''
Last_SQL_Error = 'Column 2 of table 'test.t10' cannot be converted from type 'double' to type 'char(5 octets) character set latin1''
*** Drop t10 ***
connection master;
......@@ -510,7 +510,7 @@ INSERT INTO t11 () VALUES(1,@b1,'Testing is fun','Kyle',DEFAULT),
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t11' cannot be converted from type 'tinyblob' to type 'varchar(254)''
Last_SQL_Error = 'Column 2 of table 'test.t11' cannot be converted from type 'blob' to type 'varchar(254 octets) character set latin1''
*** Drop t11 ***
connection master;
......
......@@ -468,7 +468,7 @@ INSERT INTO t10 () VALUES(1,@b1,DEFAULT,'Kyle',DEFAULT),
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t10' cannot be converted from type 'double' to type 'char(5)''
Last_SQL_Error = 'Column 2 of table 'test.t10' cannot be converted from type 'double' to type 'char(5 octets) character set latin1''
*** Drop t10 ***
connection master;
......@@ -510,7 +510,7 @@ INSERT INTO t11 () VALUES(1,@b1,'Testing is fun','Kyle',DEFAULT),
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t11' cannot be converted from type 'tinyblob' to type 'varchar(254)''
Last_SQL_Error = 'Column 2 of table 'test.t11' cannot be converted from type 'blob' to type 'varchar(254 octets) character set latin1''
*** Drop t11 ***
connection master;
......
......@@ -64,7 +64,7 @@ a b c
connection slave;
START SLAVE;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t2' cannot be converted from type 'char(10)' to type 'char(5)''
Last_SQL_Error = 'Column 2 of table 'test.t2' cannot be converted from type 'char(10 octets)' to type 'char(5 octets) character set latin1''
STOP SLAVE;
RESET SLAVE;
SELECT * FROM t2 ORDER BY a;
......@@ -102,7 +102,7 @@ INSERT INTO t3 () VALUES(@b1,2,'Kyle, TEX'),(@b1,1,'JOE AUSTIN'),(@b1,4,'QA TEST
********************************************
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 0 of table 'test.t3' cannot be converted from type 'tinyblob' to type 'int(11)''
Last_SQL_Error = 'Column 0 of table 'test.t3' cannot be converted from type 'blob' to type 'int(11)''
*** Drop t3 ***
connection master;
DROP TABLE t3;
......@@ -160,7 +160,7 @@ INSERT INTO t5 () VALUES(1,'Kyle',200.23,1,'b1b1',23.00098),
********************************************
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 1 of table 'test.t5' cannot be converted from type 'varchar(6)' to type 'char(5)''
Last_SQL_Error = 'Column 1 of table 'test.t5' cannot be converted from type 'varchar(6 octets)' to type 'char(5 octets) character set latin1''
*** Drop t5 ***
connection master;
DROP TABLE t5;
......@@ -188,7 +188,7 @@ INSERT INTO t6 () VALUES(1,'Kyle',200.23,1),
********************************************
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 1 of table 'test.t6' cannot be converted from type 'varchar(6)' to type 'char(5)''
Last_SQL_Error = 'Column 1 of table 'test.t6' cannot be converted from type 'varchar(6 octets)' to type 'char(5 octets) character set latin1''
*** Drop t6 ***
include/rpl_reset.inc
connection master;
......@@ -310,7 +310,7 @@ INSERT INTO t10 () VALUES(1,@b1,'Kyle'),(2,@b1,'JOE'),(3,@b1,'QA');
********************************************
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t10' cannot be converted from type 'char(5)' to type 'double''
Last_SQL_Error = 'Column 2 of table 'test.t10' cannot be converted from type 'char(5 octets)' to type 'double''
*** Drop t10 ***
connection master;
DROP TABLE t10;
......@@ -338,7 +338,7 @@ INSERT INTO t11 () VALUES(1,@b1,'Kyle'),(2,@b1,'JOE'),(3,@b1,'QA');
********************************************
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t11' cannot be converted from type 'varchar(254)' to type 'int(11)''
Last_SQL_Error = 'Column 2 of table 'test.t11' cannot be converted from type 'varchar(254 octets)' to type 'int(11)''
*** Drop t11 ***
connection master;
DROP TABLE t11;
......
......@@ -64,7 +64,7 @@ a b c
connection slave;
START SLAVE;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t2' cannot be converted from type 'char(10)' to type 'char(5)''
Last_SQL_Error = 'Column 2 of table 'test.t2' cannot be converted from type 'char(10 octets)' to type 'char(5 octets) character set latin1''
STOP SLAVE;
RESET SLAVE;
SELECT * FROM t2 ORDER BY a;
......@@ -102,7 +102,7 @@ INSERT INTO t3 () VALUES(@b1,2,'Kyle, TEX'),(@b1,1,'JOE AUSTIN'),(@b1,4,'QA TEST
********************************************
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 0 of table 'test.t3' cannot be converted from type 'tinyblob' to type 'int(11)''
Last_SQL_Error = 'Column 0 of table 'test.t3' cannot be converted from type 'blob' to type 'int(11)''
*** Drop t3 ***
connection master;
DROP TABLE t3;
......@@ -160,7 +160,7 @@ INSERT INTO t5 () VALUES(1,'Kyle',200.23,1,'b1b1',23.00098),
********************************************
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 1 of table 'test.t5' cannot be converted from type 'varchar(6)' to type 'char(5)''
Last_SQL_Error = 'Column 1 of table 'test.t5' cannot be converted from type 'varchar(6 octets)' to type 'char(5 octets) character set latin1''
*** Drop t5 ***
connection master;
DROP TABLE t5;
......@@ -188,7 +188,7 @@ INSERT INTO t6 () VALUES(1,'Kyle',200.23,1),
********************************************
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 1 of table 'test.t6' cannot be converted from type 'varchar(6)' to type 'char(5)''
Last_SQL_Error = 'Column 1 of table 'test.t6' cannot be converted from type 'varchar(6 octets)' to type 'char(5 octets) character set latin1''
*** Drop t6 ***
include/rpl_reset.inc
connection master;
......@@ -310,7 +310,7 @@ INSERT INTO t10 () VALUES(1,@b1,'Kyle'),(2,@b1,'JOE'),(3,@b1,'QA');
********************************************
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t10' cannot be converted from type 'char(5)' to type 'double''
Last_SQL_Error = 'Column 2 of table 'test.t10' cannot be converted from type 'char(5 octets)' to type 'double''
*** Drop t10 ***
connection master;
DROP TABLE t10;
......@@ -338,7 +338,7 @@ INSERT INTO t11 () VALUES(1,@b1,'Kyle'),(2,@b1,'JOE'),(3,@b1,'QA');
********************************************
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t11' cannot be converted from type 'varchar(254)' to type 'int(11)''
Last_SQL_Error = 'Column 2 of table 'test.t11' cannot be converted from type 'varchar(254 octets)' to type 'int(11)''
*** Drop t11 ***
connection master;
DROP TABLE t11;
......
......@@ -560,7 +560,7 @@ INSERT INTO t5 VALUES (1, "", 1);
INSERT INTO t5 VALUES (2, repeat(_utf8'a', 255), 2);
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 1 of table 'test.t5' cannot be converted from type 'char(255)' to type 'char(16)''
Last_SQL_Error = 'Column 1 of table 'test.t5' cannot be converted from type 'char(765 octets)' to type 'char(48 octets) character set utf8''
include/rpl_reset.inc
[expecting slave to stop]
connection master;
......@@ -568,7 +568,7 @@ INSERT INTO t6 VALUES (1, "", 1);
INSERT INTO t6 VALUES (2, repeat(_utf8'a', 255), 2);
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 1 of table 'test.t6' cannot be converted from type 'char(255)' to type 'char(128)''
Last_SQL_Error = 'Column 1 of table 'test.t6' cannot be converted from type 'char(765 octets)' to type 'char(384 octets) character set utf8''
include/rpl_reset.inc
[expecting slave to replicate correctly]
connection master;
......
......@@ -565,7 +565,7 @@ INSERT INTO t5 VALUES (1, "", 1);
INSERT INTO t5 VALUES (2, repeat(_utf8'a', 255), 2);
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 1 of table 'test.t5' cannot be converted from type 'char(255)' to type 'char(16)''
Last_SQL_Error = 'Column 1 of table 'test.t5' cannot be converted from type 'char(765 octets)' to type 'char(48 octets) character set utf8''
include/rpl_reset.inc
[expecting slave to stop]
connection master;
......@@ -573,7 +573,7 @@ INSERT INTO t6 VALUES (1, "", 1);
INSERT INTO t6 VALUES (2, repeat(_utf8'a', 255), 2);
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 1 of table 'test.t6' cannot be converted from type 'char(255)' to type 'char(128)''
Last_SQL_Error = 'Column 1 of table 'test.t6' cannot be converted from type 'char(765 octets)' to type 'char(384 octets) character set utf8''
include/rpl_reset.inc
[expecting slave to replicate correctly]
connection master;
......
......@@ -185,7 +185,7 @@ INSERT INTO t1 VALUES ('This is a test.');
connection slave;
START SLAVE;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 0 of table 'test.t1' cannot be converted from type 'char(20)' to type 'char(10)''
Last_SQL_Error = 'Column 0 of table 'test.t1' cannot be converted from type 'char(20 octets)' to type 'char(10 octets) character set latin1''
SELECT COUNT(*) FROM t1;
COUNT(*)
0
......@@ -264,7 +264,7 @@ INSERT INTO t1 VALUES ('This is a test.');
connection slave;
START SLAVE;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 0 of table 'test.t1' cannot be converted from type 'varchar(2000)' to type 'varchar(100)''
Last_SQL_Error = 'Column 0 of table 'test.t1' cannot be converted from type 'varchar(2000 octets)' to type 'varchar(100 octets) character set latin1''
SELECT COUNT(*) FROM t1;
COUNT(*)
0
......@@ -287,7 +287,7 @@ INSERT INTO t1 VALUES ('This is a test.');
connection slave;
START SLAVE;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 0 of table 'test.t1' cannot be converted from type 'varchar(200)' to type 'varchar(10)''
Last_SQL_Error = 'Column 0 of table 'test.t1' cannot be converted from type 'varchar(200 octets)' to type 'varchar(10 octets) character set latin1''
SELECT COUNT(*) FROM t1;
COUNT(*)
0
......@@ -310,7 +310,7 @@ INSERT INTO t1 VALUES ('This is a test.');
connection slave;
START SLAVE;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 0 of table 'test.t1' cannot be converted from type 'varchar(2000)' to type 'varchar(1000)''
Last_SQL_Error = 'Column 0 of table 'test.t1' cannot be converted from type 'varchar(2000 octets)' to type 'varchar(1000 octets) character set latin1''
SELECT COUNT(*) FROM t1;
COUNT(*)
0
......@@ -334,7 +334,7 @@ INSERT INTO t1 VALUES ('This is a test.');
connection slave;
START SLAVE;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 0 of table 'test.t1' cannot be converted from type 'tinyblob' to type 'tinyblob''
Last_SQL_Error = 'Column 0 of table 'test.t1' cannot be converted from type 'longblob' to type 'tinyblob''
SELECT COUNT(*) FROM t1;
COUNT(*)
0
......
include/master-slave.inc
[connection master]
####################################################################
# Test Case1: Improved error message with charset information
####################################################################
connection master;
SET SQL_LOG_BIN=0;
CREATE TABLE t1 (c1 VARCHAR(1) CHARACTER SET 'utf8mb3');
SET SQL_LOG_BIN=1;
connection slave;
CREATE TABLE t1 (c1 VARCHAR(1) CHARACTER SET 'utf8mb4');
connection master;
INSERT INTO t1 VALUES ('a');
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
FOUND 1 /\'varchar\(3 octets\)\' to type \'varchar\(4 octets\) character set utf8mb4\'/ in mysqld.2.err
connection master;
DROP TABLE t1;
connection slave;
DROP TABLE t1;
include/rpl_reset.inc
####################################################################
# Test Case2: Improved error message with charset information for CHAR
# type
####################################################################
connection master;
SET SQL_LOG_BIN=0;
CREATE TABLE t1 (c1 CHAR(1) CHARACTER SET 'utf8mb3');
SET SQL_LOG_BIN=1;
connection slave;
CREATE TABLE t1 (c1 CHAR(1) CHARACTER SET 'utf8mb4');
connection master;
INSERT INTO t1 VALUES ('a');
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
FOUND 1 /\'char\(3 octets\)\' to type \'char\(4 octets\) character set utf8mb4\'/ in mysqld.2.err
connection master;
DROP TABLE t1;
connection slave;
DROP TABLE t1;
include/rpl_reset.inc
####################################################################
# Test Case3: For BLOB type fileds, when type conversion failed on
# slave, the errormessage had incorrect type names.
####################################################################
connection master;
SET SQL_LOG_BIN=0;
CREATE TABLE t1 (c1 LONGBLOB);
SET SQL_LOG_BIN=1;
connection slave;
CREATE TABLE t1 (c1 TINYBLOB);
connection master;
INSERT INTO t1 VALUES ('a');
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
FOUND 1 /\'longblob\' to type \'tinyblob\'/ in mysqld.2.err
connection master;
DROP TABLE t1;
connection slave;
DROP TABLE t1;
include/rpl_reset.inc
####################################################################
# Test Case4: Verifies varbinary to binary type conversion failure
# specific error message.
####################################################################
connection master;
SET SQL_LOG_BIN=0;
CREATE TABLE t1 (c1 VARBINARY(10));
SET SQL_LOG_BIN=1;
connection slave;
CREATE TABLE t1 (c1 BINARY(10));
connection master;
INSERT INTO t1 VALUES ('a');
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
FOUND 1 /\'varbinary\(10\)\' to type \'binary\(10\)\'/ in mysqld.2.err
connection master;
DROP TABLE t1;
connection slave;
DROP TABLE t1;
include/rpl_reset.inc
####################################################################
# Test Case5: Verifies binary to varbinary type conversion failure
# specific error message.
####################################################################
connection master;
SET SQL_LOG_BIN=0;
CREATE TABLE t1 (c1 BINARY(10));
SET SQL_LOG_BIN=1;
connection slave;
CREATE TABLE t1 (c1 VARBINARY(10));
connection master;
INSERT INTO t1 VALUES ('a');
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
FOUND 1 /\'binary\(10\)\' to type \'varbinary\(10\)\'/ in mysqld.2.err
connection master;
DROP TABLE t1;
connection slave;
DROP TABLE t1;
include/rpl_reset.inc
####################################################################
# Test Case6: Verifies binary to binary type conversion failure
# specific error message.
####################################################################
connection master;
SET SQL_LOG_BIN=0;
CREATE TABLE t1 (c1 BINARY(1));
SET SQL_LOG_BIN=1;
connection slave;
CREATE TABLE t1 (c1 BINARY(10));
connection master;
INSERT INTO t1 VALUES ('a');
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
FOUND 1 /\'binary\(1\)\' to type \'binary\(10\)\'/ in mysqld.2.err
connection master;
DROP TABLE t1;
connection slave;
DROP TABLE t1;
include/rpl_reset.inc
####################################################################
# Test Case7: Verifies char to blob type conversion failure
# specific error message. BLOB field on slave has no
# associated character set hence the master side field
# is also considered as binary.
####################################################################
connection master;
SET SQL_LOG_BIN=0;
CREATE TABLE t1 (c1 CHAR(1));
SET SQL_LOG_BIN=1;
connection slave;
CREATE TABLE t1 (c1 BLOB);
connection master;
INSERT INTO t1 VALUES ('a');
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
FOUND 1 /\'binary\(1\)\' to type \'blob\'/ in mysqld.2.err
connection master;
DROP TABLE t1;
connection slave;
DROP TABLE t1;
include/rpl_reset.inc
####################################################################
# Test Case8: Verifies char to text type conversion failure
# specific error message.
####################################################################
connection master;
SET SQL_LOG_BIN=0;
CREATE TABLE t1 (c1 CHAR(1));
SET SQL_LOG_BIN=1;
connection slave;
CREATE TABLE t1 (c1 TEXT);
connection master;
INSERT INTO t1 VALUES ('a');
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
FOUND 1 /\'char\(1 octets\)\' to type \'text\'/ in mysqld.2.err
connection master;
DROP TABLE t1;
connection slave;
DROP TABLE t1;
include/rpl_reset.inc
include/rpl_end.inc
This diff is collapsed.
......@@ -7392,6 +7392,28 @@ void Field_string::sql_type(String &res) const
res.append(STRING_WITH_LEN(" binary"));
}
/**
For fields which are associated with character sets their length is provided
in octets and their character set information is also provided as part of
type information.
@param res String which contains filed type and length.
*/
void Field_string::sql_rpl_type(String *res) const
{
CHARSET_INFO *cs=charset();
if (Field_string::has_charset())
{
size_t length= cs->cset->snprintf(cs, (char*) res->ptr(),
res->alloced_length(),
"char(%u octets) character set %s",
field_length,
charset()->csname);
res->length(length);
}
else
Field_string::sql_type(*res);
}
uchar *Field_string::pack(uchar *to, const uchar *from, uint max_length)
{
......@@ -7820,6 +7842,29 @@ void Field_varstring::sql_type(String &res) const
res.append(STRING_WITH_LEN(" binary"));
}
/**
For fields which are associated with character sets their length is provided
in octets and their character set information is also provided as part of
type information.
@param res String which contains filed type and length.
*/
void Field_varstring::sql_rpl_type(String *res) const
{
CHARSET_INFO *cs=charset();
if (Field_varstring::has_charset())
{
size_t length= cs->cset->snprintf(cs, (char*) res->ptr(),
res->alloced_length(),
"varchar(%u octets) character set %s",
field_length,
charset()->csname);
res->length(length);
}
else
Field_varstring::sql_type(*res);
}
uint32 Field_varstring::data_length()
{
......
......@@ -1106,6 +1106,7 @@ class Field: public Value_source
in str and restore it with set() if needed
*/
virtual void sql_type(String &str) const =0;
virtual void sql_rpl_type(String *str) const { sql_type(*str); }
virtual uint size_of() const =0; // For new field
inline bool is_null(my_ptrdiff_t row_offset= 0) const
{
......@@ -3162,6 +3163,7 @@ class Field_string :public Field_longstr {
int cmp(const uchar *,const uchar *);
void sort_string(uchar *buff,uint length);
void sql_type(String &str) const;
void sql_rpl_type(String*) const;
virtual uchar *pack(uchar *to, const uchar *from,
uint max_length);
virtual const uchar *unpack(uchar* to, const uchar *from,
......@@ -3264,6 +3266,7 @@ class Field_varstring :public Field_longstr {
uint get_key_image(uchar *buff,uint length, imagetype type);
void set_key_image(const uchar *buff,uint length);
void sql_type(String &str) const;
void sql_rpl_type(String*) const;
virtual uchar *pack(uchar *to, const uchar *from, uint max_length);
virtual const uchar *unpack(uchar* to, const uchar *from,
const uchar *from_end, uint param_data);
......
......@@ -341,7 +341,8 @@ uint32 table_def::calc_field_size(uint col, uchar *master_data) const
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
/**
*/
void show_sql_type(enum_field_types type, uint16 metadata, String *str, CHARSET_INFO *field_cs)
void show_sql_type(enum_field_types type, uint16 metadata, String *str,
bool char_with_octets)
{
DBUG_ENTER("show_sql_type");
DBUG_PRINT("enter", ("type: %d, metadata: 0x%x", type, metadata));
......@@ -408,9 +409,13 @@ void show_sql_type(enum_field_types type, uint16 metadata, String *str, CHARSET_
case MYSQL_TYPE_VARCHAR:
{
CHARSET_INFO *cs= str->charset();
uint32 length=
cs->cset->snprintf(cs, (char*) str->ptr(), str->alloced_length(),
"varchar(%u)", metadata);
uint32 length=0;
if (char_with_octets)
length= cs->cset->snprintf(cs, (char*) str->ptr(), str->alloced_length(),
"varchar(%u octets)", metadata);
else
length= cs->cset->snprintf(cs, (char*) str->ptr(), str->alloced_length(),
"varbinary(%u)", metadata);
str->length(length);
}
break;
......@@ -460,22 +465,22 @@ void show_sql_type(enum_field_types type, uint16 metadata, String *str, CHARSET_
it is necessary to check the pack length to figure out what kind
of blob it really is.
*/
switch (get_blob_type_from_length(metadata))
switch (metadata)
{
case MYSQL_TYPE_TINY_BLOB:
case 1:
str->set_ascii(STRING_WITH_LEN("tinyblob"));
break;
case MYSQL_TYPE_MEDIUM_BLOB:
str->set_ascii(STRING_WITH_LEN("mediumblob"));
case 2:
str->set_ascii(STRING_WITH_LEN("blob"));
break;
case MYSQL_TYPE_LONG_BLOB:
str->set_ascii(STRING_WITH_LEN("longblob"));
case 3:
str->set_ascii(STRING_WITH_LEN("mediumblob"));
break;
case MYSQL_TYPE_BLOB:
str->set_ascii(STRING_WITH_LEN("blob"));
case 4:
str->set_ascii(STRING_WITH_LEN("longblob"));
break;
default:
......@@ -491,9 +496,13 @@ void show_sql_type(enum_field_types type, uint16 metadata, String *str, CHARSET_
*/
CHARSET_INFO *cs= str->charset();
uint bytes= (((metadata >> 4) & 0x300) ^ 0x300) + (metadata & 0x00ff);
uint32 length=
cs->cset->snprintf(cs, (char*) str->ptr(), str->alloced_length(),
"char(%d)", bytes / field_cs->mbmaxlen);
uint32 length=0;
if (char_with_octets)
length= cs->cset->snprintf(cs, (char*) str->ptr(), str->alloced_length(),
"char(%u octets)", bytes);
else
length= cs->cset->snprintf(cs, (char*) str->ptr(), str->alloced_length(),
"binary(%u)", bytes);
str->length(length);
}
break;
......@@ -896,9 +905,13 @@ table_def::compatible_with(THD *thd, rpl_group_info *rgi,
String source_type(source_buf, sizeof(source_buf), &my_charset_latin1);
String target_type(target_buf, sizeof(target_buf), &my_charset_latin1);
THD *thd= table->in_use;
bool char_with_octets= field->cmp_type() == STRING_RESULT ?
field->has_charset() : true;
show_sql_type(type(col), field_metadata(col), &source_type,
char_with_octets);
field->sql_rpl_type(&target_type);
show_sql_type(type(col), field_metadata(col), &source_type, field->charset());
field->sql_type(target_type);
rli->report(ERROR_LEVEL, ER_SLAVE_CONVERSION_FAILED, rgi->gtid_info(),
ER_THD(thd, ER_SLAVE_CONVERSION_FAILED),
col, db_name, tbl_name,
......
......@@ -6461,7 +6461,7 @@ ER_MESSAGE_AND_STATEMENT
eng "%s Statement: %s"
ER_SLAVE_CONVERSION_FAILED
eng "Column %d of table '%-.192s.%-.192s' cannot be converted from type '%-.32s' to type '%-.32s'"
eng "Column %d of table '%-.192s.%-.192s' cannot be converted from type '%-.50s' to type '%-.50s'"
ER_SLAVE_CANT_CREATE_CONVERSION
eng "Can't create conversion table for table '%-.192s.%-.192s'"
ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT
......
......@@ -468,7 +468,7 @@ INSERT INTO t10 () VALUES(1,@b1,DEFAULT,'Kyle',DEFAULT),
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t10' cannot be converted from type 'double' to type 'char(5)''
Last_SQL_Error = 'Column 2 of table 'test.t10' cannot be converted from type 'double' to type 'char(5 octets) character set latin1''
*** Drop t10 ***
connection master;
......@@ -510,7 +510,7 @@ INSERT INTO t11 () VALUES(1,@b1,'Testing is fun','Kyle',DEFAULT),
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t11' cannot be converted from type 'tinyblob' to type 'varchar(254)''
Last_SQL_Error = 'Column 2 of table 'test.t11' cannot be converted from type 'blob' to type 'varchar(254 octets) character set latin1''
*** Drop t11 ***
connection master;
......
......@@ -64,7 +64,7 @@ a b c
connection slave;
START SLAVE;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t2' cannot be converted from type 'char(10)' to type 'char(5)''
Last_SQL_Error = 'Column 2 of table 'test.t2' cannot be converted from type 'char(10 octets)' to type 'char(5 octets) character set latin1''
STOP SLAVE;
RESET SLAVE;
SELECT * FROM t2 ORDER BY a;
......@@ -102,7 +102,7 @@ INSERT INTO t3 () VALUES(@b1,2,'Kyle, TEX'),(@b1,1,'JOE AUSTIN'),(@b1,4,'QA TEST
********************************************
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 0 of table 'test.t3' cannot be converted from type 'tinyblob' to type 'int(11)''
Last_SQL_Error = 'Column 0 of table 'test.t3' cannot be converted from type 'blob' to type 'int(11)''
*** Drop t3 ***
connection master;
DROP TABLE t3;
......@@ -160,7 +160,7 @@ INSERT INTO t5 () VALUES(1,'Kyle',200.23,1,'b1b1',23.00098),
********************************************
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 1 of table 'test.t5' cannot be converted from type 'varchar(6)' to type 'char(5)''
Last_SQL_Error = 'Column 1 of table 'test.t5' cannot be converted from type 'varchar(6 octets)' to type 'char(5 octets) character set latin1''
*** Drop t5 ***
connection master;
DROP TABLE t5;
......@@ -188,7 +188,7 @@ INSERT INTO t6 () VALUES(1,'Kyle',200.23,1),
********************************************
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 1 of table 'test.t6' cannot be converted from type 'varchar(6)' to type 'char(5)''
Last_SQL_Error = 'Column 1 of table 'test.t6' cannot be converted from type 'varchar(6 octets)' to type 'char(5 octets) character set latin1''
*** Drop t6 ***
include/rpl_reset.inc
connection master;
......@@ -310,7 +310,7 @@ INSERT INTO t10 () VALUES(1,@b1,'Kyle'),(2,@b1,'JOE'),(3,@b1,'QA');
********************************************
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t10' cannot be converted from type 'char(5)' to type 'double''
Last_SQL_Error = 'Column 2 of table 'test.t10' cannot be converted from type 'char(5 octets)' to type 'double''
*** Drop t10 ***
connection master;
DROP TABLE t10;
......@@ -338,7 +338,7 @@ INSERT INTO t11 () VALUES(1,@b1,'Kyle'),(2,@b1,'JOE'),(3,@b1,'QA');
********************************************
connection slave;
include/wait_for_slave_sql_error_and_skip.inc [errno=1677]
Last_SQL_Error = 'Column 2 of table 'test.t11' cannot be converted from type 'varchar(254)' to type 'int(11)''
Last_SQL_Error = 'Column 2 of table 'test.t11' cannot be converted from type 'varchar(254 octets)' to type 'int(11)''
*** Drop t11 ***
connection master;
DROP TABLE t11;
......
......@@ -565,7 +565,7 @@ INSERT INTO t5 VALUES (1, "", 1);
INSERT INTO t5 VALUES (2, repeat(_utf8'a', 255), 2);
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 1 of table 'test.t5' cannot be converted from type 'char(255)' to type 'char(16)''
Last_SQL_Error = 'Column 1 of table 'test.t5' cannot be converted from type 'char(765 octets)' to type 'char(48 octets) character set utf8''
include/rpl_reset.inc
[expecting slave to stop]
connection master;
......@@ -573,7 +573,7 @@ INSERT INTO t6 VALUES (1, "", 1);
INSERT INTO t6 VALUES (2, repeat(_utf8'a', 255), 2);
connection slave;
include/wait_for_slave_sql_error.inc [errno=1677]
Last_SQL_Error = 'Column 1 of table 'test.t6' cannot be converted from type 'char(255)' to type 'char(128)''
Last_SQL_Error = 'Column 1 of table 'test.t6' cannot be converted from type 'char(765 octets)' to type 'char(384 octets) character set utf8''
include/rpl_reset.inc
[expecting slave to replicate correctly]
connection master;
......
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