Skip to content
Permalink
Browse files
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.
  • Loading branch information
SachinSetiya authored and sanja-byelkin committed Nov 7, 2022
1 parent 0d927a5 commit 10132ad
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
@@ -314,6 +314,15 @@ ERROR 23000: Duplicate entry '1' for key 'v2'
update t1,t2 set v1 = v2 , v5 = 0;
ERROR 23000: Duplicate entry '-128' for key 'v1'
drop table t1, t2;
CREATE TABLE t1 (f TEXT UNIQUE);
INSERT INTO t1 VALUES (NULL),(NULL);
UPDATE t1 SET f = '';
ERROR 23000: Duplicate entry '' for key 'f'
SELECT * FROM t1;
f

NULL
DROP TABLE t1;
#
# MDEV-21540 Initialization of already inited long unique index on reorganize partition
#
@@ -396,6 +396,17 @@ update t1 set v2 = 1, v3 = -128;
update t1,t2 set v1 = v2 , v5 = 0;
drop table t1, t2;

#
# MDEV-23264 Unique blobs allow duplicate values upon UPDATE
#

CREATE TABLE t1 (f TEXT UNIQUE);
INSERT INTO t1 VALUES (NULL),(NULL);
--error ER_DUP_ENTRY
UPDATE t1 SET f = '';
SELECT * FROM t1;
DROP TABLE t1;

--echo #
--echo # MDEV-21540 Initialization of already inited long unique index on reorganize partition
--echo #
@@ -6750,8 +6750,13 @@ static int check_duplicate_long_entries_update(TABLE *table, handler *h, uchar *
for (uint j= 0; j < key_parts; j++, keypart++)
{
field= keypart->field;
/* Compare fields if they are different then check for duplicates*/
if(field->cmp_binary_offset(reclength))
/*
Compare fields if they are different then check for duplicates
cmp_binary_offset cannot differentiate between null and empty string
So also check for that too
*/
if((field->is_null(0) != field->is_null(reclength)) ||
field->cmp_binary_offset(reclength))
{
if((error= check_duplicate_long_entry_key(table, table->update_handler,
new_rec, i)))

0 comments on commit 10132ad

Please sign in to comment.