Skip to content

Commit 10132ad

Browse files
SachinSetiyasanja-byelkin
authored andcommitted
MDEV-23264 Unique blobs allow duplicate values upon UPDATE
Problem:- We are able to insert duplicate value in table because cmp_binary_offset is not able to differentiate between NULL and empty string. So check_duplicate_long_entry_key is never called and we don't check for duplicate. Solution Added a if condition with is_null() on field which can differentiate between NULL and empty string.
1 parent 0d927a5 commit 10132ad

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

mysql-test/main/long_unique_bugs.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,15 @@ ERROR 23000: Duplicate entry '1' for key 'v2'
314314
update t1,t2 set v1 = v2 , v5 = 0;
315315
ERROR 23000: Duplicate entry '-128' for key 'v1'
316316
drop table t1, t2;
317+
CREATE TABLE t1 (f TEXT UNIQUE);
318+
INSERT INTO t1 VALUES (NULL),(NULL);
319+
UPDATE t1 SET f = '';
320+
ERROR 23000: Duplicate entry '' for key 'f'
321+
SELECT * FROM t1;
322+
f
323+
324+
NULL
325+
DROP TABLE t1;
317326
#
318327
# MDEV-21540 Initialization of already inited long unique index on reorganize partition
319328
#

mysql-test/main/long_unique_bugs.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,17 @@ update t1 set v2 = 1, v3 = -128;
396396
update t1,t2 set v1 = v2 , v5 = 0;
397397
drop table t1, t2;
398398

399+
#
400+
# MDEV-23264 Unique blobs allow duplicate values upon UPDATE
401+
#
402+
403+
CREATE TABLE t1 (f TEXT UNIQUE);
404+
INSERT INTO t1 VALUES (NULL),(NULL);
405+
--error ER_DUP_ENTRY
406+
UPDATE t1 SET f = '';
407+
SELECT * FROM t1;
408+
DROP TABLE t1;
409+
399410
--echo #
400411
--echo # MDEV-21540 Initialization of already inited long unique index on reorganize partition
401412
--echo #

sql/handler.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6750,8 +6750,13 @@ static int check_duplicate_long_entries_update(TABLE *table, handler *h, uchar *
67506750
for (uint j= 0; j < key_parts; j++, keypart++)
67516751
{
67526752
field= keypart->field;
6753-
/* Compare fields if they are different then check for duplicates*/
6754-
if(field->cmp_binary_offset(reclength))
6753+
/*
6754+
Compare fields if they are different then check for duplicates
6755+
cmp_binary_offset cannot differentiate between null and empty string
6756+
So also check for that too
6757+
*/
6758+
if((field->is_null(0) != field->is_null(reclength)) ||
6759+
field->cmp_binary_offset(reclength))
67556760
{
67566761
if((error= check_duplicate_long_entry_key(table, table->update_handler,
67576762
new_rec, i)))

0 commit comments

Comments
 (0)