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

ALTER from a bigger to a smaller blob type truncates too much data

Details

    Description

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a BLOB) ENGINE=MyISAM;
      INSERT INTO t1 VALUES (REPEAT(0x61,65000));
      SELECT LENGTH(a) FROM t1;
      ALTER TABLE t1 MODIFY a TINYBLOB;
      SELECT LENGTH(a) FROM t1;

      returns 65000 before ALTER:

      +-----------+
      | LENGTH(a) |
      +-----------+
      |     65000 |
      +-----------+

      and returns 232 after ALTER:

      +-----------+
      | LENGTH(a) |
      +-----------+
      |       232 |
      +-----------+

      This looks wrong. The expected length after ALTER is 255.

      It also does not produce any warnings on truncation. Probably it should.

      Attachments

        Issue Links

          Activity

            In case of a multi-byte TEXT field, truncation breaks characters apart:

            SET NAMES utf8;
            DROP TABLE IF EXISTS t1;
            CREATE TABLE t1 (a TEXT CHARACTER SET utf8) ENGINE=MyISAM;
            INSERT INTO t1 VALUES (REPEAT('A',100));
            SELECT OCTET_LENGTH(a) FROM t1;
            ALTER TABLE t1 MODIFY a TINYTEXT CHARACTER SET utf8;
            SELECT OCTET_LENGTH(a),a FROM t1;

            +-----------------+----------------------------------------------+
            | OCTET_LENGTH(a) | a                                            |
            +-----------------+----------------------------------------------+
            |              44 | AAAAAAAAAAAAAA??                 |
            +-----------------+----------------------------------------------+

            Notice the the garbage at the end.

            bar Alexander Barkov added a comment - In case of a multi-byte TEXT field, truncation breaks characters apart: SET NAMES utf8; DROP TABLE IF EXISTS t1; CREATE TABLE t1 (a TEXT CHARACTER SET utf8) ENGINE=MyISAM; INSERT INTO t1 VALUES (REPEAT('A',100)); SELECT OCTET_LENGTH(a) FROM t1; ALTER TABLE t1 MODIFY a TINYTEXT CHARACTER SET utf8; SELECT OCTET_LENGTH(a),a FROM t1; +-----------------+----------------------------------------------+ | OCTET_LENGTH(a) | a | +-----------------+----------------------------------------------+ | 44 | AAAAAAAAAAAAAA?? | +-----------------+----------------------------------------------+ Notice the the garbage at the end.

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.