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

INSTANT ALTER from ascii_general_ci to latin1_general_ci produces corrupt data

Details

    Description

      Copying ALTER from ascii_general_ci to latin1_general_ci may fail in case of 8-bit characters:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET ascii COLLATE ascii_general_ci, PRIMARY KEY(a)) ENGINE=InnoDB;
      INSERT INTO t1 VALUES ('a'),(0xC0),('b');
      ALTER TABLE t1 ALGORITHM=COPY, MODIFY a VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_general_ci;
      

      Instant ALTER performs such conversion silently, but then CHECK TABLE rerpots corrupted data:

      ALTER TABLE t1 ALGORITHM=INSTANT, MODIFY a VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_general_ci;
      CHECK TABLE t1;
      

      +---------+-------+----------+---------------------------------------------------+
      | Table   | Op    | Msg_type | Msg_text                                          |
      +---------+-------+----------+---------------------------------------------------+
      | test.t1 | check | Warning  | InnoDB: The B-tree of index PRIMARY is corrupted. |
      | test.t1 | check | error    | Corrupt                                           |
      +---------+-------+----------+---------------------------------------------------+
      

      Instant ALTER should be disallowed from ascii_general_ci to xxx_general_ci.

      Attachments

        Issue Links

          Activity

            A similar problem is repeatable on alter from ascii_general_ci to utf8_general_ci.

            DROP TABLE IF EXISTS t1;
            CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET ascii COLLATE ascii_general_ci, PRIMARY KEY(a)) ENGINE=InnoDB;
            INSERT INTO t1 VALUES ('a'),(0xC0),('b');
            ALTER TABLE t1 ALGORITHM=COPY, MODIFY a VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci;
            

            ERROR 1366 (22007): Incorrect string value: '\xC0' for column `test`.`t1`.`a` at row 3
            

            ALTER TABLE t1 ALGORITHM=INSTANT, MODIFY a VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci;
            SELECT HEX(a) FROM t1;
            

            +--------+
            | HEX(a) |
            +--------+
            | 61     |
            | 62     |
            | C0     |
            +--------+
            

            Notice, 0xC0 is a not well-formed utf8 string.

            bar Alexander Barkov added a comment - A similar problem is repeatable on alter from ascii_general_ci to utf8_general_ci . DROP TABLE IF EXISTS t1; CREATE TABLE t1 (a VARCHAR (10) CHARACTER SET ascii COLLATE ascii_general_ci, PRIMARY KEY (a)) ENGINE=InnoDB; INSERT INTO t1 VALUES ( 'a' ),(0xC0),( 'b' ); ALTER TABLE t1 ALGORITHM=COPY, MODIFY a VARCHAR (10) CHARACTER SET utf8 COLLATE utf8_general_ci; ERROR 1366 (22007): Incorrect string value: '\xC0' for column `test`.`t1`.`a` at row 3 ALTER TABLE t1 ALGORITHM=INSTANT, MODIFY a VARCHAR (10) CHARACTER SET utf8 COLLATE utf8_general_ci; SELECT HEX(a) FROM t1; +--------+ | HEX(a) | +--------+ | 61 | | 62 | | C0 | +--------+ Notice, 0xC0 is a not well-formed utf8 string.

            A similar problem is repeatable on alter from ascii_bin to utf8_bin.

            DROP TABLE IF EXISTS t1;
            CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET ascii COLLATE ascii_bin, PRIMARY KEY(a)) ENGINE=InnoDB;
            INSERT INTO t1 VALUES ('a'),(0xC0),('b');
            ALTER TABLE t1 ALGORITHM=COPY, MODIFY a VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_bin;
            

            ERROR 1366 (22007): Incorrect string value: '\xC0' for column `test`.`t1`.`a` at row 3
            

            ALTER TABLE t1 ALGORITHM=INSTANT, MODIFY a VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci;
            SELECT HEX(a) FROM t1;
            

            +--------+
            | HEX(a) |
            +--------+
            | 61     |
            | 62     |
            | C0     |
            +--------+
            

            Notice, 0xC0 is a not well-formed utf8 string.

            bar Alexander Barkov added a comment - A similar problem is repeatable on alter from ascii_bin to utf8_bin . DROP TABLE IF EXISTS t1; CREATE TABLE t1 (a VARCHAR (10) CHARACTER SET ascii COLLATE ascii_bin, PRIMARY KEY (a)) ENGINE=InnoDB; INSERT INTO t1 VALUES ( 'a' ),(0xC0),( 'b' ); ALTER TABLE t1 ALGORITHM=COPY, MODIFY a VARCHAR (10) CHARACTER SET utf8 COLLATE utf8_bin; ERROR 1366 (22007): Incorrect string value: '\xC0' for column `test`.`t1`.`a` at row 3 ALTER TABLE t1 ALGORITHM=INSTANT, MODIFY a VARCHAR (10) CHARACTER SET utf8 COLLATE utf8_general_ci; SELECT HEX(a) FROM t1; +--------+ | HEX(a) | +--------+ | 61 | | 62 | | C0 | +--------+ Notice, 0xC0 is a not well-formed utf8 string.

            Closed by a join patch with MDEV-19284

            bar Alexander Barkov added a comment - Closed by a join patch with MDEV-19284

            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.