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

Table with a short UNIQUE ... USING HASH key can no longer be read after SYSTEM_TIME AUTO or INTERVAL partitioning adds partitions

    XMLWordPrintable

Details

    Description

      Likely cause: MDEV-17554, commit 92bfc0e8c4bb5c86359c29458d67f3e7836ec18a, which added the AUTO creation of history partitions in 10.9.1. The fix for MDEV-25654 made a manual ADD PARTITION keep the hidden hash column, but not the automatic one. CS 10.11.2, which does not have that fix, gives the same error.

      --source include/have_partition.inc
      --source include/have_innodb.inc
      SET timestamp= UNIX_TIMESTAMP('2026-01-01 00:00:00');
      CREATE TABLE t1 (a INT, b VARCHAR(20), UNIQUE KEY (b) USING HASH) ENGINE=InnoDB WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 DAY AUTO;
      INSERT INTO t1 VALUES (1, 'x');
      SET timestamp= UNIX_TIMESTAMP('2026-01-03 00:00:00');
      --error 0,ER_CRASHED_ON_USAGE
      UPDATE t1 SET a = 2;
      if ($mysql_errno)
      {
        --die An UPDATE that adds a history partition fails, and the table with a short UNIQUE USING HASH index reads as crashed
      }
      FLUSH TABLES;
      --error 0,ER_TABLE_CORRUPT
      SELECT * FROM t1;
      if ($mysql_errno)
      {
        --die After history partitions are added automatically, a table with a short UNIQUE USING HASH index cannot be read
      }
      DROP TABLE t1;

      Leads to:

      CS 13.1.2 87e62ca17270e163a6d41b3fc8d6f4d440f1bb88 (Optimized, Clang 22.1.8-20260622) Build 06/10/2026

      mysqltest: At line 11: An UPDATE that adds a history partition fails, and the table with a short UNIQUE USING HASH index reads as crashed

      The error log:

      CS 13.1.2 87e62ca17270e163a6d41b3fc8d6f4d440f1bb88 (Optimized, Clang 22.1.8-20260622) Build 06/10/2026

      2026-11-12 16:16:44 4 [Warning] InnoDB: Table test/t1#P#p0 contains 5 user defined columns in InnoDB, but 4 columns in MariaDB. Please check INFORMATION_SCHEMA.INNODB_SYS_COLUMNS and https://mariadb.com/docs/server/server-usage/storage-engines/innodb/innodb-troubleshooting/innodb-data-dictionary-troubleshooting for how to resolve the issue.
      2026-11-12 16:16:44 4 [ERROR] mariadbd: Table 't1' is marked as crashed and should be repaired

      The UPDATE gives ERROR 1194 (HY000): Table 't1' is marked as crashed and should be repaired. After a FLUSH TABLES or a restart, SELECT, INSERT, UPDATE, DELETE, SHOW CREATE TABLE and ALTER TABLE on t1 give ERROR 1877 (t1#P#p0 is corrupted). Debug builds give the same errors. With MyISAM, the UPDATE gives ERROR 1030 (error 190). With PARTITION BY RANGE COLUMNS ... INTERVAL, the INSERT that adds the partitions gives ERROR 1194. A TEXT column is not affected.

      On an optimized build, a background thread then writes the "is corrupted" and "Failed to open table" errors to the error log about 50,000 times a second, also while no statement runs. A debug build crashes in the InnoDB purge thread when it starts again.

      From the code it seems that alter_add_partitions() (vers_create_partitions() in 10.11 to 13.0) keeps the result of prep_alter_part_table() in a local variable, so alter_ctx.fast_alter_partition stays false. mysql_prepare_alter_table() then sets the algorithm of the hash key to HA_KEY_ALG_UNDEF, and a key that is short enough becomes a plain UNIQUE index without the hash column.

      Attachments

        Issue Links

          Activity

            People

              midenok Aleksey Midenkov
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - Not Specified
                  Not Specified
                  Logged:
                  Time Spent - 1h
                  1h

                  Git Integration

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