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

Partitioning changes the query result after an ALTER TABLE makes a partitioning column NOT NULL: a = 0 misses the rows that held NULL

    XMLWordPrintable

Details

    Description

      Likely cause: old code, not a recent change. CS 10.4.25 has the bug too, while MySQL 5.5 to 9.1 find both rows.

      --source include/have_partition.inc
      --source include/have_innodb.inc
      SET sql_mode='';
      CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB PARTITION BY LIST (a) (PARTITION pn VALUES IN (NULL), PARTITION p0 VALUES IN (0));
      INSERT INTO t1 VALUES (NULL, 1), (0, 2);
      ALTER TABLE t1 MODIFY a INT NOT NULL;
      --let $n= `SELECT COUNT(*) FROM t1 WHERE a = 0`
      if ($n != 2)
      {
        --die The row whose NULL became 0 stays in the NULL partition, and a = 0 finds $n of the 2 rows
      }
      DROP TABLE t1;

      Leads to:

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

      mysqltest: At line 10: The row whose NULL became 0 stays in the NULL partition, and a = 0 finds 1 of the 2 rows

      Partitioning changes the query result. Without partitioning, WHERE a = 0 finds both rows.

      The ALTER TABLE changes the NULL to 0 in place, with warning 1265, but the row stays in pn. WHERE a = 0 finds 1 of the 2 rows, and CHECK TABLE reports "Found a misplaced row". The same happens with ALGORITHM=INPLACE, LOCK=NONE, with ALTER IGNORE TABLE under the default strict sql_mode, and with RANGE and KEY partitioning. ALGORITHM=COPY, and MyISAM, give the right result. Debug builds give the same result.

      MySQL

      +--------+--------+--------+
      | MySQL  | Finds  | Engine |
      +--------+--------+--------+
      | 5.5.62 | 2 rows | InnoDB |
      | 5.6.51 | 2 rows | InnoDB |
      | 5.7.44 | 2 rows | InnoDB |
      | 8.0.36 | 2 rows | InnoDB |
      | 9.1.0  | 2 rows | InnoDB |
      +--------+--------+--------+

      From the code it seems that ha_partition::check_if_supported_inplace_alter() lets InnoDB make the change in place, and that nothing checks whether the column is a partitioning column.

      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:

                Time Tracking

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

                  Git Integration

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