title: MySQL: INSERT blocked by an UPDATE of the foreign key referenced row
body: <p>Let me start my question with an SQL example.</p>
  
  <p>Here is the table setup: </p>
  
  <ol>
  <li>Create table <code>x</code> and <code>y</code>. With <code>y.x</code> refers to <code>x.id</code>.</li>
  <li>Insert a row into <code>x</code> (id=1).</li>
  </ol>
  
  <hr>
  
  <pre><code>START TRANSACTION;
  CREATE TABLE `x` (
      `id` INT(11) NOT NULL AUTO_INCREMENT,
      `value` INT(11) NOT NULL,
      PRIMARY KEY (`id`)
  )  ENGINE=INNODB;
  CREATE TABLE `y` (
      `id` INT(11) NOT NULL AUTO_INCREMENT,
      `x_id` INT(11) NOT NULL,
      `value` INT(11) NOT NULL,
      PRIMARY KEY (`id`),
      CONSTRAINT `fk_x` FOREIGN KEY (`x_id`)
          REFERENCES `x` (`id`)
  )  ENGINE=INNODB;
  
  INSERT INTO x values (1,123456);
  COMMIT;
  </code></pre>
  
  <p>Now start a transaction (Trx A) to update the row in <code>x</code>.</p>
  
  <pre><code>START TRANSACTION;
  UPDATE x SET value=value+1 WHERE id = 1;
  </code></pre>
  
  <p>Before it is committed, I am starting another transaction (Trx B) to insert a row to <code>y</code>.</p>
  
  <pre><code>START TRANSACTION;
  INSERT INTO y VALUES (null,1,123456);
  ---- HANGED ----
  -- Until Trx A is committed or rolled-back, the Trx B is hanged here.
  </code></pre>
  
  <p>The question is - is it expected that Trx B to be hanged at that point? Why and any way to workaround that?</p>
  
  <blockquote>
    <p>This has been tested on MySQL 5.7.21, Percona 5.7.21, MariaDB 10.2.14</p>
  </blockquote>