Skip to content
Permalink
Browse files
MDEV-16768: fix blob key length
The blob key length could be shorter than the length of the entire blob,
for example,

CREATE TABLE t1 (b BLOB, i INT, KEY(b(8)));
INSERT INTO t1 VALUES (REPEAT('a',9),1);

The key length is 8, while the blob length is 9.
So we need to set the correct key length in Field_blob::sort_string().
  • Loading branch information
minggr authored and spetrunia committed Sep 12, 2018
1 parent 8dda6d7 commit 8760932
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
@@ -8546,7 +8546,9 @@ void Field_blob::sort_string(uchar *to,uint length)
Store length of blob last in blob to shorter blobs before longer blobs
*/
length-= packlength;
store_bigendian(buf.length(), to + length, packlength);

uint key_length = MY_MIN(buf.length(), length);
store_bigendian(key_length, to + length, packlength);
}

#ifdef DBUG_ASSERT_EXISTS
@@ -0,0 +1,9 @@
include/master-slave.inc
[connection master]
CREATE TABLE t1 (b BLOB, i INT, KEY(b(8))) ENGINE=RocksDB;
INSERT INTO t1 VALUES (REPEAT('a',9),1);
UPDATE t1 SET i = 2;
connection slave;
connection master;
DROP TABLE t1;
include/rpl_end.inc
@@ -0,0 +1,15 @@
--source include/have_rocksdb.inc
--source include/have_binlog_format_row.inc
--source include/master-slave.inc

CREATE TABLE t1 (b BLOB, i INT, KEY(b(8))) ENGINE=RocksDB;
INSERT INTO t1 VALUES (REPEAT('a',9),1);

UPDATE t1 SET i = 2;

--sync_slave_with_master

# Cleanup
--connection master
DROP TABLE t1;
--source include/rpl_end.inc

0 comments on commit 8760932

Please sign in to comment.