[MDEV-30034] UNIQUE USING HASH accepts duplicate entries for tricky collations Created: 2022-11-18  Updated: 2023-04-24  Resolved: 2023-04-04

Status: Closed
Project: MariaDB Server
Component/s: Data types
Affects Version/s: 10.4
Fix Version/s: 10.11.3, 10.4.29, 10.5.20, 10.6.13, 10.8.8, 10.9.6, 10.10.4

Type: Bug Priority: Critical
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Problem/Incident
is caused by MDEV-371 Unique indexes for blobs Closed
is caused by MDEV-25904 New collation functions to compare In... Closed
Relates
relates to MDEV-30048 Prefix keys for CHAR work differently... Closed
relates to MDEV-30050 Inconsistent results of DISTINCT with... Closed
relates to MDEV-30072 Wrong ORDER BY for a partitioned pref... Closed
relates to MDEV-27670 Assertion `(cs->state & 0x20000) == 0... Closed
relates to MDEV-27768 MDEV-25440: Assertion `(cs->state & 0... Closed

 Description   

If I use a traditional unique constraint, the table correctly rejects the second record:

CREATE OR REPLACE TABLE t1 (a VARCHAR(2000) COLLATE utf8_unicode_nopad_ci, UNIQUE(a(3)));
INSERT INTO t1 VALUES ('ss ');
INSERT INTO t1 VALUES ('ß ');

ERROR 1062 (23000): Duplicate entry 'ß ' for key 'a'

Now if I do the same thing with UNIQUE USING HASH, it accepts the duplicate record:

CREATE OR REPLACE TABLE t1 (a VARCHAR(2000) COLLATE utf8_unicode_nopad_ci, UNIQUE(a(3)) USING HASH);
INSERT INTO t1 VALUES ('ss ');
INSERT INTO t1 VALUES ('ß ');

This is wrong. The second record should be rejected.



 Comments   
Comment by Alexander Barkov [ 2023-01-24 ]

It seems the problem is related to broken Field_varstring::cmp_prefix().

See a similar bug: MDEV-30072

Was likely caused by: MDEV-25904

Generated at Thu Feb 08 10:13:08 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.