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

ALTER TABLE and TRUNCATE give an InnoDB partition the page compression of the table instead of its own PAGE_COMPRESSED option

    XMLWordPrintable

Details

    Description

      Likely cause: MDEV-5271, which added engine-defined options such as PAGE_COMPRESSED per partition in CS 10.8.1. CREATE TABLE and a copying ALTER TABLE use the options of the partition. An in-place ALTER TABLE and TRUNCATE use the options of the table.

      --source include/have_partition.inc
      --source include/have_innodb.inc
      CREATE TABLE t1 (a INT) ENGINE=InnoDB PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (10) PAGE_COMPRESSED=1, PARTITION p1 VALUES LESS THAN MAXVALUE);
      INSERT INTO t1 VALUES (1), (11);
      --let $f= `SELECT FLAG FROM information_schema.INNODB_SYS_TABLES WHERE NAME = 'test/t1#P#p0'`
      ALTER TABLE t1 FORCE;
      --let $g= `SELECT FLAG FROM information_schema.INNODB_SYS_TABLES WHERE NAME = 'test/t1#P#p0'`
      if ($g != $f)
      {
        --die ALTER TABLE FORCE rebuilds the partition that has PAGE_COMPRESSED=1 without page compression, its InnoDB flags change from $f to $g
      }
      DROP TABLE t1;

      Leads to:

      CS 11.8.9 8c4943d20876e15de08e1656af0e4c11b425864c (Optimized, Clang 22.1.8-20260622) Build 16/10/2026

      mysqltest: At line 10: ALTER TABLE FORCE rebuilds the partition that has PAGE_COMPRESSED=1 without page compression, its InnoDB flags change from 1697 to 33

      The InnoDB flags of p0 in information_schema.INNODB_SYS_TABLES change from 1697 to 33, while SHOW CREATE TABLE still shows PAGE_COMPRESSED='1' for p0. ALTER TABLE ... OPTIMIZE PARTITION, ALTER TABLE t1 ENGINE=InnoDB, ALTER TABLE t1 TRUNCATE PARTITION p0 and TRUNCATE TABLE t1 do the same. A copying ALTER TABLE and ALTER TABLE ... REBUILD PARTITION keep the page compression. With default subpartitions, a copying ALTER TABLE gives the subpartitions the page compression of the table. Debug builds give the same result.

      An ALTER TABLE that does not rebuild the table does the opposite: it gives each partition the page compression of the table. When the table has PAGE_COMPRESSED=1, ALTER TABLE t1 COMMENT='x' changes the flags of a partition with PAGE_COMPRESSED=0 from 33 to 1697, and of a partition with PAGE_COMPRESSION_LEVEL=3 from 929 to 1697. On 12.3 and later, the first of these crashes the server instead, see MDEV-40915 and MDEV-42314.

      With file_key_management, ALTER TABLE t1 ENCRYPTED=NO, TRUNCATE TABLE t1 and ALTER TABLE t1 TRUNCATE PARTITION p0 create a partition with its own ENCRYPTED=YES again without encryption, while SHOW CREATE TABLE still shows ENCRYPTED = YES for it.

      From the code it seems that ha_partition::prepare_inplace_alter_table() gives the same altered_table to each partition, and that create_table_info_t::innobase_table_flags() takes the page compression from altered_table->s->option_struct, which holds the table options. Without a rebuild, ha_innobase::prepare_inplace_alter_table() takes the page compression from create_info->option_struct, which also holds the table options. prepare_inplace_alter_table_dict() takes the encryption of a rebuilt partition from it as well.

      On 12.3 and 13.1 the fix of MDEV-40915 resolves the testcase, and it passes on CS 12.3.4. 10.11, 11.4, 11.8 and 13.0 do not have that fix. A CS 13.1.2 build without that fix keeps the page compression on TRUNCATE, and on a copying ALTER TABLE with default subpartitions.

      Attachments

        Issue Links

          Activity

            People

              ycp Yuchen Pei
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              1 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.