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

Concurrent INSERTs each add the missing INTERVAL partitions, so the table gets several times the partitions it needs

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Critical
    • Resolution: Unresolved
    • 13.1, 13.2
    • 13.1
    • Partitioning
    • None

    Description

      --source include/have_partition.inc
      --source include/have_innodb.inc
       
      SET timestamp= UNIX_TIMESTAMP('2026-05-02 00:00:00');
      --error 0,ER_PARSE_ERROR,ER_PARTITIONS_MUST_BE_DEFINED_ERROR
      CREATE TABLE t1 (c DATE) ENGINE=InnoDB PARTITION BY RANGE COLUMNS (c) INTERVAL 1 DAY (PARTITION p0 VALUES LESS THAN ('2026-04-30'));
      if ($mysql_errno)
      {
        --skip Needs RANGE COLUMNS ... INTERVAL partitioning
      }
      DROP TABLE t1;
      # 10 rounds. In each round, 8 sessions send the same INSERT at the same time
      --let $r= 10
      while ($r)
      {
        CREATE TABLE t1 (c DATE) ENGINE=InnoDB PARTITION BY RANGE COLUMNS (c) INTERVAL 1 DAY (PARTITION p0 VALUES LESS THAN ('2026-04-30'));
        --let $i= 8
        while ($i)
        {
          --connect (con$i,localhost,root,,test)
          SET timestamp= UNIX_TIMESTAMP('2026-05-02 00:00:00');
          --dec $i
        }
        --let $i= 8
        while ($i)
        {
          --connection con$i
          --send INSERT INTO t1 VALUES ('2026-04-25')
          --dec $i
        }
        --let $i= 8
        while ($i)
        {
          --connection con$i
          --reap
          --disconnect con$i
          --dec $i
        }
        --connection default
        # One INSERT alone adds 3 partitions: up to 2026-05-03
        --let $n= query_get_value(SELECT COUNT(*) AS n FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1', n, 1)
        if ($n != 4)
        {
          --die Concurrent INSERTs each added the missing INTERVAL partitions: t1 has $n partitions instead of 4
        }
        DROP TABLE t1;
        --dec $r
      }

      Leads to:

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

      mysqltest: At line 44: Concurrent INSERTs each added the missing INTERVAL partitions: t1 has 10 partitions instead of 4

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

      mysqltest: At line 44: Concurrent INSERTs each added the missing INTERVAL partitions: t1 has 25 partitions instead of 4

      Each waiting INSERT adds another 3 partitions, for 2026-05-04, 2026-05-05 and so on. All 8 rows are added and no INSERT gives an error. With PARTITION BY SYSTEM_TIME INTERVAL 1 DAY ... AUTO and 8 concurrent UPDATE statements, the table gets the same partitions as with one UPDATE.

      From the code it seems that TABLE::range_interval_check_partition() in sql/sql_partition_auto_interval.cc counts the missing partitions before the session waits in lock_table_names(), and Open_table_context::recover_from_failed_open() in sql/sql_base.cc then adds that count without counting again. For SYSTEM_TIME, TABLE::vers_switch_partition() lets one session add the partitions and makes the others reopen the table, by way of TABLE_SHARE::vers_skip_auto_create.

      Attachments

        Issue Links

          Activity

            People

              ycp Yuchen Pei
              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 - 0d
                  0d
                  Remaining:
                  Time Spent - 1h Remaining Estimate - 1.5d
                  1.5d
                  Logged:
                  Time Spent - 1h Remaining Estimate - 1.5d
                  1h

                  Git Integration

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