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

INSERT DELAYED into a table with INTERVAL partitioning hangs

    XMLWordPrintable

Details

    Description

      --source include/have_partition.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 (a INT, c DATE) PARTITION BY RANGE COLUMNS (c) INTERVAL 1 DAY (PARTITION p0 VALUES LESS THAN ('2026-04-20'));
      if ($mysql_errno)
      {
        --skip Needs RANGE COLUMNS ... INTERVAL partitioning
      }
      --connect (con1,localhost,root,,test)
      --send INSERT DELAYED INTO t1 VALUES (1,'2026-04-10')
      --connection default
      --sleep 5
      --let $c= query_get_value(SELECT COUNT(*) AS c FROM information_schema.PROCESSLIST WHERE STATE='Waiting for handler open', c, 1)
      if ($c)
      {
        --die INSERT DELAYED into a table with INTERVAL partitioning hangs in the state Waiting for handler open
      }
      --connection con1
      --error 0,ER_DELAYED_NOT_SUPPORTED
      --reap
      --disconnect con1
      --connection default
      DROP TABLE t1;

      Leads to:

      CS 13.1.0 da18481158c81ca94689702073c3e04aad85a6a3 (Debug, Clang 22.1.8-20260622) Build 18/08/2026

      mysqltest: At line 17: INSERT DELAYED into a table with INTERVAL partitioning hangs in the state Waiting for handler open

      The client waits in "Waiting for handler open", and the INSERT DELAYED handler thread waits in "Waiting for table metadata lock". A lower lock_wait_timeout does not end the wait: with SET GLOBAL lock_wait_timeout=3, the INSERT DELAYED has not returned after 60 seconds. While it waits, an INSERT DELAYED into a second table, without partitions, does not return either. On a partitioned table without INTERVAL, INSERT DELAYED gives ER_DELAYED_NOT_SUPPORTED at once. Optimized builds give the same result.

      From the code it seems that the INSERT DELAYED handler thread opens the table as SQLCOM_INSERT, so TABLE::range_interval_check_partition() asks it to add the INTERVAL partitions. Open_table_context::recover_from_failed_open() in sql/sql_base.cc then calls lock_table_names() for an exclusive metadata lock on t1. The client thread holds MDL_SHARED_WRITE on t1 and waits in delayed_get_table() for the handler thread, which uses LONG_TIMEOUT as its lock_wait_timeout. The client thread waits with LOCK_delayed_create locked, and an INSERT DELAYED that starts a new handler thread locks it first.

      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 - 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.