Commit 5f9e20de authored by unknown's avatar unknown
Browse files

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

- make sure keys are copied correctly when varchar has 2 length bytes
- test case


mysql-test/r/ndb_basic.result:
  bug#25746 ndb: 4209 error with 2 VARCHAR primary keys
  - test case
mysql-test/t/ndb_basic.test:
  bug#25746 ndb: 4209 error with 2 VARCHAR primary keys
  - test case
sql/ha_ndbcluster.cc:
  bug#25746 ndb: 4209 error with 2 VARCHAR primary keys
  - make sure keys are copied correctly when varchar has 2 length bytes
parent 030e5f92
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -749,3 +749,19 @@ f1 f2 f3
222222	bbbbbb	2
drop table t1;
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
+19 −0
Original line number Diff line number Diff line
@@ -710,3 +710,22 @@ drop table t1;
--error 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

+16 −10
Original line number Diff line number Diff line
@@ -3144,8 +3144,9 @@ void ha_ndbcluster::position(const byte *record)
      size_t len = key_part->length;
      const byte * ptr = record + key_part->offset;
      Field *field = key_part->field;
      if ((field->type() ==  MYSQL_TYPE_VARCHAR) &&
	  ((Field_varstring*)field)->length_bytes == 1)
      if (unlikely(field->type() ==  MYSQL_TYPE_VARCHAR))
      {
        if (((Field_varstring*)field)->length_bytes == 1)
        {
          /**
           * Keys always use 2 bytes length
@@ -3153,6 +3154,11 @@ void ha_ndbcluster::position(const byte *record)
          buff[0] = ptr[0];
          buff[1] = 0;
          memcpy(buff+2, ptr + 1, len);
        }
        else
        {
          memcpy(buff, ptr, len + 2);
        }
        len += 2;
      }
      else