bug#25746 ndb: 4209 error with 2 VARCHAR primary keys

- make sure keys are copied correctly when varchar has 2 length bytes
- test case
parent 7aeddb4c
...@@ -749,3 +749,19 @@ f1 f2 f3 ...@@ -749,3 +749,19 @@ f1 f2 f3
222222 bbbbbb 2 222222 bbbbbb 2
drop table t1; drop table t1;
Illegal ndb error code: 1186 Illegal ndb error code: 1186
CREATE TABLE t1 (
a VARBINARY(40) NOT NULL,
b VARCHAR (256) CHARACTER SET UTF8 NOT NULL,
c VARCHAR(256) CHARACTER SET UTF8 NOT NULL,
PRIMARY KEY (b,c)) ENGINE=ndbcluster;
INSERT INTO t1 VALUES
("a","ab","abc"),("b","abc","abcd"),("c","abc","ab"),("d","ab","ab"),("e","abc","abc");
SELECT * FROM t1 ORDER BY a;
a b c
a ab abc
b abc abcd
c abc ab
d ab ab
e abc abc
DROP TABLE t1;
End of 5.0 tests
...@@ -710,3 +710,22 @@ drop table t1; ...@@ -710,3 +710,22 @@ drop table t1;
--error 1 --error 1
--exec $MY_PERROR --ndb 1186 2>&1 --exec $MY_PERROR --ndb 1186 2>&1
#
# Bug #25746 - VARCHAR UTF8 PK issue
# - prior to bugfix 4209, illegal length parameter would be
# returned in SELECT *
CREATE TABLE t1 (
a VARBINARY(40) NOT NULL,
b VARCHAR (256) CHARACTER SET UTF8 NOT NULL,
c VARCHAR(256) CHARACTER SET UTF8 NOT NULL,
PRIMARY KEY (b,c)) ENGINE=ndbcluster;
INSERT INTO t1 VALUES
("a","ab","abc"),("b","abc","abcd"),("c","abc","ab"),("d","ab","ab"),("e","abc","abc");
SELECT * FROM t1 ORDER BY a;
DROP TABLE t1;
# End of 5.0 tests
--echo End of 5.0 tests
...@@ -3144,20 +3144,26 @@ void ha_ndbcluster::position(const byte *record) ...@@ -3144,20 +3144,26 @@ void ha_ndbcluster::position(const byte *record)
size_t len = key_part->length; size_t len = key_part->length;
const byte * ptr = record + key_part->offset; const byte * ptr = record + key_part->offset;
Field *field = key_part->field; Field *field = key_part->field;
if ((field->type() == MYSQL_TYPE_VARCHAR) && if (unlikely(field->type() == MYSQL_TYPE_VARCHAR))
((Field_varstring*)field)->length_bytes == 1)
{ {
/** if (((Field_varstring*)field)->length_bytes == 1)
* Keys always use 2 bytes length {
*/ /**
buff[0] = ptr[0]; * Keys always use 2 bytes length
buff[1] = 0; */
memcpy(buff+2, ptr + 1, len); buff[0] = ptr[0];
len += 2; buff[1] = 0;
memcpy(buff+2, ptr + 1, len);
}
else
{
memcpy(buff, ptr, len + 2);
}
len += 2;
} }
else else
{ {
memcpy(buff, ptr, len); memcpy(buff, ptr, len);
} }
buff += len; buff += len;
} }
......
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