title: DELETE without lock in MariaDB/MySQL?`(InnoDB)
body: <p>As far as I know, <code>DELETE FROM ... WHERE</code> issues a lock on the table.</p>
  
  <p>Now, I have a huge InnoDB table in MariaDB with a size of 1TB+ that is actively being used, and having it locked until the entire database has been searched for rows to delete is no option.</p>
  
  <p>Is there any way how I could delete rows matching certain criteria <strong>without</strong> locking it while the delete is happening?</p>
  
  <p><strong>Here are some more specifics for this case:</strong></p>
  
  <ul>
  <li>The server is running MariaDB 10.1.22-3 from the Debian Stretch repository</li>
  <li>The server has 32 GB ram and <code>innodb_buffer_pool_size = 20G</code></li>
  <li>The database has a size of 1TB+ with lots of active <code>INSERT</code>s and <code>SELECT</code>s at all times</li>
  <li>The entire database contains only 2 tables:
  
  <ul>
  <li>One table for the actual data (which basically has a structure like <code>data (BIGINT id, LONGTEXT data)</code> (where <code>data</code> is a big chunk of JSON. I know that this is not a perfect relational database model, but the JSON comes from a third party, it's pretty complex, and could contain structure changes from the third party at any time and without notice)</li>
  <li>And one table for some kind of 'indexes' to satisfy <code>SELECT</code>s. (Simplified example, this could have a structure like <code>data_index (BIGINT id, INT userId, INT itemId, BIGINT timestamp)</code>, so I could use <code>SELECT</code> on userId and itemId, and join on the actual data. (timestamp is the unix timestamp in milliseconds)</li>
  </ul></li>
  <li>Like I said, the data is meant to be stored for a limited time only. So basically now I want to create a cronjob that runs once per day to delete rows that are older than 7 days.</li>
  </ul>
  
  <p>To fulfill the task, I would naturally come up with this simple query:</p>
  
  <pre><code>DELETE `data`, `data_index`
  FROM `data_index`
  LEFT JOIN `data` ON `data`.`id` = `data_index`.`id`
  WHERE `timestamp` &gt; (NOW() * 1000) - (7 * 24 * 60 * 60 * 1000)
  </code></pre>
  
  <p>But this would probably lock the tables for a pretty long time. How could I accomplish the same task <strong>without</strong> locking the tables, so the database remains functional for other <code>SELECT</code> and <code>INSERT</code> queries?</p>