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

Statement referencing the same locked sequence more than once fails with ER_TABLE_NOT_LOCKED

    XMLWordPrintable

Details

    • Can result in unexpected behaviour

    Description

      When a sequence is locked with LOCK TABLES, a statement that references it once works. A statement that references it twice or more fails with ER_TABLE_NOT_LOCKED (1100) "Table 's' was not locked with LOCK TABLES"

      CREATE SEQUENCE s ENGINE=InnoDB;
      LOCK TABLES s WRITE;
      SELECT NEXTVAL(s);                                    # works
      SELECT NEXTVAL(s) AS x, NEXTVAL(s) AS y;              # ERROR 1100
      UNLOCK TABLES;
       
      LOCK TABLES s READ;
      SELECT LASTVAL(s);                                    # works
      SELECT LASTVAL(s), LASTVAL(s);                        # ERROR 1100
      UNLOCK TABLES;
      

      13.2.0-opt>CREATE SEQUENCE s ENGINE=InnoDB;
      Query OK, 0 rows affected (0.009 sec)
       
      13.2.0-opt>LOCK TABLES s WRITE;
      Query OK, 0 rows affected (0.000 sec)
       
      13.2.0-opt>SELECT NEXTVAL(s);                                    # works
      +------------+
      | NEXTVAL(s) |
      +------------+
      |          1 |
      +------------+
      1 row in set (0.000 sec)
       
      13.2.0-opt>SELECT NEXTVAL(s) AS x, NEXTVAL(s) AS y;              # ERROR 1100
      ERROR 1100 (HY000): Table 's' was not locked with LOCK TABLES
      13.2.0-opt>UNLOCK TABLES;
      Query OK, 0 rows affected (0.000 sec)
       
      13.2.0-opt>
      13.2.0-opt>LOCK TABLES s READ;
      Query OK, 0 rows affected (0.000 sec)
       
      13.2.0-opt>SELECT LASTVAL(s);                                    # works
      +------------+
      | LASTVAL(s) |
      +------------+
      |          1 |
      +------------+
      1 row in set (0.000 sec)
       
      13.2.0-opt>SELECT LASTVAL(s), LASTVAL(s);                        # ERROR 1100
      ERROR 1100 (HY000): Table 's' was not locked with LOCK TABLES
      13.2.0-opt>UNLOCK TABLES;
      Query OK, 0 rows affected (0.000 sec)
       
      13.2.0-opt>
      

      Attachments

        Activity

          People

            midenok Aleksey Midenkov
            ramesh Ramesh Sivaraman
            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 - 0d
                0d
                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.