title: SQL: "NOT IN" subquery optimization or alternatives
body: <p>I have two database tables: &quot;places&quot; and &quot;translations&quot;. The translations of places names are made by selecting records from &quot;places&quot;, which don't have the translations to the specified language yet:</p>
  <pre><code>SELECT `id`, `name`
  FROM `places`
  WHERE `id` NOT IN (SELECT `place_id` FROM `translations` WHERE `lang` = 'en')
  </code></pre>
  <p>This worked fine with 7 000 records of places, but crashed when the number of translations reached 5 000. Since then, the query takes about 10 seconds and returns the error:</p>
  <blockquote>
  <h1>2006 - MySQL server has gone away</h1>
  </blockquote>
  <p>As I understand, the main problem here is the subquery returning to many results, bu how could I solve it, if I need to select all the places which are not translated yet?</p>
  <p>My plan B is to create a new boolean field in &quot;places&quot; table, called &quot;translated&quot;, and reset it to &quot;false&quot;, each time I change language - that would prevent for having subquery. However, maybe I could just modify my current SQL statement and prevent from adding additional field?</p>