Skip to content

Commit 8760932

Browse files
minggrspetrunia
authored andcommitted
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().
1 parent 8dda6d7 commit 8760932

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

sql/field.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8546,7 +8546,9 @@ void Field_blob::sort_string(uchar *to,uint length)
85468546
Store length of blob last in blob to shorter blobs before longer blobs
85478547
*/
85488548
length-= packlength;
8549-
store_bigendian(buf.length(), to + length, packlength);
8549+
8550+
uint key_length = MY_MIN(buf.length(), length);
8551+
store_bigendian(key_length, to + length, packlength);
85508552
}
85518553

85528554
#ifdef DBUG_ASSERT_EXISTS
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
include/master-slave.inc
2+
[connection master]
3+
CREATE TABLE t1 (b BLOB, i INT, KEY(b(8))) ENGINE=RocksDB;
4+
INSERT INTO t1 VALUES (REPEAT('a',9),1);
5+
UPDATE t1 SET i = 2;
6+
connection slave;
7+
connection master;
8+
DROP TABLE t1;
9+
include/rpl_end.inc
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--source include/have_rocksdb.inc
2+
--source include/have_binlog_format_row.inc
3+
--source include/master-slave.inc
4+
5+
CREATE TABLE t1 (b BLOB, i INT, KEY(b(8))) ENGINE=RocksDB;
6+
INSERT INTO t1 VALUES (REPEAT('a',9),1);
7+
8+
UPDATE t1 SET i = 2;
9+
10+
--sync_slave_with_master
11+
12+
# Cleanup
13+
--connection master
14+
DROP TABLE t1;
15+
--source include/rpl_end.inc

0 commit comments

Comments
 (0)