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

select (consistent read) within IF block in store procedure locks rows

    Details

      Description

      I have a problem with SELECT in stored procedure.

      Isolation level is READ-COMMITED, engine is InnoDB so all select should be nonlocking consistent read: https://dev.mysql.com/doc/refman/8.0/en/innodb-consistent-read.html

      Following select in store procedure locks acquires lock on table agent:

      IF  v_pack_agent_id IS NULL OR 
          v_pack_agent_id not in                  
          (
              select ID from agent where LINKED_AGENTS_GUID = (select LINKED_AGENTS_GUID from agent where ID = a_agent_id) union all 
              select a_agent_id
          )
      THEN
          SET a_sign = SIGN_NOT_OWN_BLOCK;
          LEAVE l_proc;
      END IF;
      

      Table agent definition:

      MariaDB [db_mercury]> show create table agent\G
      *************************** 1. row ***************************
      Table: agent
      Create Table: CREATE TABLE `agent` (
      `ID` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK',
       ...
      `LINKED_AGENTS_GUID` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
       PRIMARY KEY (`ID`),
       UNIQUE KEY `UK$ORA_ID` (`ORA_ID`),
       KEY `IDX_LINKED_AGENTS_GUID` (`LINKED_AGENTS_GUID`)
       ) ENGINE=InnoDB AUTO_INCREMENT=6198 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
      

      Problem is because select nested in IF block, if I move select outside of IF like below, then no locks are acquired. This locks nothing:

      select ID from agent where LINKED_AGENTS_GUID = (select LINKED_AGENTS_GUID from agent where ID = a_agent_id) union all 
      select a_agent_id
      

      For me it seems like a bug.

        Attachments

          Activity

            People

            • Assignee:
              sanja Oleksandr Byelkin
              Reporter:
              pustovalov1 Dmitry Pustovalov
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: