Commit 87609324 authored by Ming Lin's avatar Ming Lin Committed by Sergei Petrunia

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().
parent 8dda6d79
...@@ -8546,7 +8546,9 @@ void Field_blob::sort_string(uchar *to,uint length) ...@@ -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 Store length of blob last in blob to shorter blobs before longer blobs
*/ */
length-= packlength; 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 #ifdef DBUG_ASSERT_EXISTS
......
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
--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
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