[MDEV-20604] Duplicate key value is silently truncated to 64 characters in print_keydup_error Created: 2019-09-16  Updated: 2022-03-22  Resolved: 2020-04-01

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.2.27, 10.3.18, 10.4.8
Fix Version/s: 10.2.32, 10.3.23, 10.4.13

Type: Bug Priority: Critical
Reporter: Geoff Montee (Inactive) Assignee: Oleksandr Byelkin
Resolution: Fixed Votes: 0
Labels: beginner-friendly

Issue Links:
Problem/Incident
causes MDEV-22147 main.mysqldump fails with wrong resul... Closed
causes MDEV-22545 my_vsnprintf behaves not as in C stan... Closed
Relates
relates to MDEV-20605 Awaken transaction can miss inserted ... Closed
relates to MDEV-20628 If temporary error occurs with optimi... Closed

 Description   

When a duplicate key is encountered, the error message is constructed in print_keydup_error:

https://github.com/MariaDB/server/blob/mariadb-10.2.27/sql/handler.cc#L3450

The duplicate value is silently truncated to 64 characters. This is because the format string for the error message sets the field width to 64:

https://github.com/MariaDB/server/blob/mariadb-10.2.27/sql/share/errmsg-utf8.txt#L6166

Truncation is probably fine, but since this specific error involves a "duplicate key", it can be a bit confusing if the user searches the table for that string, and then doesn't find another row with that specific value.

If we can't print the whole value, then the error message may want to mention that the string may be truncated to 64 characters.



 Comments   
Comment by Sergei Golubchik [ 2019-09-17 ]

We can fix my_vsprintf to print (optionally) some truncation hint, like "..." if the value was truncated. E.g. "%-.64...s" meaning it'll print "..."

Or we can rephrase the error message to be something like "Duplicate value for the key %$2-.128s: '%$1s'" — this way it'll allow few hundreds bytes for the key value, up to the max error message length of (iirc) 512. But might have compatibility implications if some tool looks for the exact error message text (that no sane tool should do).

Comment by Oleksandr Byelkin [ 2020-02-25 ]

I found that we have plugin for my_snprintf, so theoretically it can be done with a plugin

Comment by Oleksandr Byelkin [ 2020-03-16 ]

ho big description and no so small test suite:

create table t1 (a varchar(100), UNIQUE KEY akey (a));
 
insert into t1 values ("1234567890123456789012345678901234567890123456789012345678901234567890_end");
--error ER_DUP_ENTRY
insert into t1 values ("1234567890123456789012345678901234567890123456789012345678901234567890_end");
 
drop table t1;

Comment by Oleksandr Byelkin [ 2020-03-16 ]

IMHO we need something shorter than "..." (triple dot), I propose ":".

Comment by Oleksandr Byelkin [ 2020-03-16 ]

commit 42b77dd0549c8883a497e2385bf6c992222ecb02 (HEAD > bb-10.2MDEV-20604, origin/bb-10.2-MDEV-20604)
Author: Oleksandr Byelkin <sanja@mariadb.com>
Date: Mon Mar 16 16:53:10 2020 +0100

MDEV-20604: Duplicate key value is silently truncated to 64 characters in print_keydup_error

Added indication of truncated string with special width/precission suffix ':'.

Comment by Oleksandr Byelkin [ 2020-03-20 ]

commit 17449c44a5443934909ff38c547e5e6db06b9660 (HEAD -> bb-10.2-release)
Author: Oleksandr Byelkin <sanja@mariadb.com>
Date: Mon Mar 16 16:53:10 2020 +0100

MDEV-20604: Duplicate key value is silently truncated to 64 characters in print_keydup_error

Added indication of truncated string for "s" format

Comment by Oleksandr Byelkin [ 2020-03-24 ]

commit fc90a39426c1756c204b5b3ff2f580a2f4224571 (HEAD > bb-10.2MDEV-20604, origin/bb-10.2-release, origin/bb-10.2-MDEV-20604, bb-10.2-release)
Author: Oleksandr Byelkin <sanja@mariadb.com>
Date: Mon Mar 16 16:53:10 2020 +0100

MDEV-20604: Duplicate key value is silently truncated to 64 characters in print_keydup_error

Added indication of truncated string for "s" and "M" formats

Generated at Thu Feb 08 09:00:45 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.