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

explict LOCK TABLES inserttbl WRITE, subquerytbl READ" incorrectly errors "subquerytbl was not locked with LOCK TABLES"

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.5.27, 10.6.19, 11.4.4
    • 10.5
    • Locking
    • None

    Description

      from: https://stackoverflow.com/questions/79331718/table-s-was-not-locked-with-lock-tables-while-inserting-data-with-values-co

      $ podman run --env MARIADB_USER=bob --env MARIADB_PASSWORD=user --env MARIADB_DATABASE=students --env MARIADB_ROOT_PASSWORD=nottelling -v /tmp/t:/docker-entrypoint-initdb.d:z --rm mariadb:10.6
      2025-01-07 02:53:35+00:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/1-ddl.sql
       
       
      2025-01-07 02:53:35+00:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/2-dml.sql
      --------------
      INSERT INTO students (id_student, student_name, gender_id, student_date_of_birth) VALUES
      (1, '<Student Name>', (SELECT id_gender FROM genders WHERE gender_name = 'Female'),  '2000-01-02'),
      (95, '<Student Name>', (SELECT id_gender FROM genders WHERE gender_name = 'Male'),   '2010-02-10')
      --------------
       
      ERROR 1100 (HY000) at line 8: Table 'genders' was not locked with LOCK TABLES
      

      10.5.28-MariaDB source revision a226f12675c6312ca7632b90261397e313e6a7ae

      MariaDB [test]> CREATE TABLE genders (
          ->   id_gender int(1) NOT NULL,
          ->   gender_name varchar(50) NOT NULL,
          ->   PRIMARY KEY (id_gender)
          -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
      Query OK, 0 rows affected (0.001 sec)
       
      MariaDB [test]> 
      MariaDB [test]> CREATE TABLE students (
          ->   id_student int(11) NOT NULL,
          ->   student_name varchar(50) DEFAULT NULL,
          ->   gender_id int(1) DEFAULT NULL,
          ->   student_date_of_birth bigint(20) DEFAULT NULL,
          ->   PRIMARY KEY (id_student)
          -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
      Query OK, 0 rows affected (0.001 sec)
       
      MariaDB [test]> 
      MariaDB [test]> ALTER TABLE students ADD CONSTRAINT students_genders_FK FOREIGN KEY (gender_id) REFERENCES genders(id_gender);
      Query OK, 0 rows affected (0.003 sec)              
      Records: 0  Duplicates: 0  Warnings: 0
       
      MariaDB [test]> 
      MariaDB [test]> LOCK TABLES genders WRITE;
      Query OK, 0 rows affected (0.001 sec)
       
      MariaDB [test]> INSERT INTO genders (id_gender, gender_name) VALUES
          -> (1,'Female'), 
          -> (2,'Male');
      Query OK, 2 rows affected (0.001 sec)
      Records: 2  Duplicates: 0  Warnings: 0
       
      MariaDB [test]> UNLOCK TABLES;
      Query OK, 0 rows affected (0.000 sec)
       
      MariaDB [test]> 
      MariaDB [test]> 
      MariaDB [test]> LOCK TABLES students WRITE, genders READ;
      Query OK, 0 rows affected (0.000 sec)
       
      MariaDB [test]> INSERT INTO students (id_student, student_name, gender_id, student_date_of_birth) VALUES
          -> (1, '<Student Name>', (SELECT id_gender FROM genders WHERE gender_name = 'Female'),  '2000-01-02'),
          -> (95, '<Student Name>', (SELECT id_gender FROM genders WHERE gender_name = 'Male'),   '2010-02-10');
      ERROR 1100 (HY000): Table 'genders' was not locked with LOCK TABLES
      MariaDB [test]> 
      MariaDB [test]> \s
      --------------
      client/mariadb  Ver 15.1 Distrib 10.5.28-MariaDB, for Linux (x86_64) using  EditLine wrapper
      

      Attachments

        1. 1-ddl.sql
          0.6 kB
        2. 2-dml.sql
          0.4 kB

        Activity

          There are no comments yet on this issue.

          People

            nikitamalyavin Nikita Malyavin
            danblack Daniel Black
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.