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

Too long value in the Duplicate entry message with online alter and utf8

    XMLWordPrintable

Details

    Description

      This problem was found while working on MDEV-19123.

      I put a fragment of mysql-test/suite/innodb/t/online_table_rebuild.test into a separate test flle and add CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci into the table definition:

      --source include/have_innodb.inc
      --source include/have_debug.inc
      --source include/have_debug_sync.inc
      --source include/have_sequence.inc
       
      CREATE TABLE t1(f1 INT NOT NULL, f2 CHAR(200), f3 CHAR(200))
        ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
       
      INSERT INTO t1 VALUES(3, "innodb", "alter log");
       
      # InnoDB fails with DUPLICATE KEY error in commit phase
       
      SET DEBUG_SYNC="inplace_after_index_build SIGNAL dml_start WAIT_FOR dml_commit";
      send ALTER TABLE t1 ADD PRIMARY KEY(f3(10)), ADD UNIQUE KEY(f2(10));
      CONNECT(con1,localhost,root,,,);
      SET DEBUG_SYNC="now WAIT_FOR dml_start";
      BEGIN;
      INSERT INTO t1 VALUES(1, repeat('b', 100), repeat('c', 100));
      INSERT INTO t1 VALUES(2, repeat('b', 100), repeat('a', 100));
      COMMIT;
      SET DEBUG_SYNC="now SIGNAL dml_commit";
       
      connection default;
      --error ER_DUP_ENTRY
      reap;
       
      DROP TABLE t1;
       
      SET DEBUG_SYNC=reset;
      

      TEST                                      RESULT   TIME (ms) or COMMENT
      --------------------------------------------------------------------------
       
      worker[01] Using MTR_BUILD_THREAD 300, with reserved ports 19000..19029
      CREATE TABLE t1(f1 INT NOT NULL, f2 CHAR(200), f3 CHAR(200))
      ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
      INSERT INTO t1 VALUES(3, "innodb", "alter log");
      SET DEBUG_SYNC="inplace_after_index_build SIGNAL dml_start WAIT_FOR dml_commit";
      ALTER TABLE t1 ADD PRIMARY KEY(f3(10)), ADD UNIQUE KEY(f2(10));
      CONNECT con1,localhost,root,,,;
      SET DEBUG_SYNC="now WAIT_FOR dml_start";
      BEGIN;
      INSERT INTO t1 VALUES(1, repeat('b', 100), repeat('c', 100));
      INSERT INTO t1 VALUES(2, repeat('b', 100), repeat('a', 100));
      COMMIT;
      SET DEBUG_SYNC="now SIGNAL dml_commit";
      connection default;
      ERROR 23000: Duplicate entry 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' for key 'f2'
      DROP TABLE t1;
      SET DEBUG_SYNC=reset;
      

      Notice, the key is too long. The index size is only 10 characters. The expected output should be:

      ERROR 23000: Duplicate entry 'bbbbbbbbbb' for key 'f2'
      

      Tracing this test in gdb shows that in this code in key.cc key_part->key_part_flag misses the HA_PART_KEY_SEG flag, so field_unpack() is called with a wrong last parameter:

          field_unpack(to, key_part->field, table->record[0], key_part->length,
                       MY_TEST(key_part->key_part_flag & HA_PART_KEY_SEG));
      

      Attachments

        Issue Links

          Activity

            People

              thiru Thirunarayanan Balathandayuthapani
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

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