Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-20604

Duplicate key value is silently truncated to 64 characters in print_keydup_error

Details

    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.

      Attachments

        Issue Links

          Activity

            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).

            serg Sergei Golubchik added a comment - 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).

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

            sanja Oleksandr Byelkin added a comment - I found that we have plugin for my_snprintf, so theoretically it can be done with a plugin

            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;
            

            sanja Oleksandr Byelkin added a comment - 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;

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

            sanja Oleksandr Byelkin added a comment - IMHO we need something shorter than "..." (triple dot), I propose ":".

            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 ':'.

            sanja Oleksandr Byelkin added a comment - commit 42b77dd0549c8883a497e2385bf6c992222ecb02 (HEAD > bb-10.2 MDEV-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 ':'.

            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

            sanja Oleksandr Byelkin added a comment - 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

            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

            sanja Oleksandr Byelkin added a comment - commit fc90a39426c1756c204b5b3ff2f580a2f4224571 (HEAD > bb-10.2 MDEV-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

            People

              sanja Oleksandr Byelkin
              GeoffMontee Geoff Montee (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.