title: Impossible row counts in MySQL
body: <p>I don't know how does MySQL works internally, but I'm sure there are some problem with indexes or some metainformation about table counts:</p>
  
  <pre><code>mysql&gt; select count(*) from Event;
  +----------+
  | count(*) |
  +----------+
  |     5925 |
  +----------+
  1 row in set (0,01 sec)
  
  mysql&gt; select count(*) from Event where event_id in (select discount_event_id from Discount);
  +----------+
  | count(*) |
  +----------+
  |     5901 |
  +----------+
  1 row in set (0,12 sec)
  
  mysql&gt; select count(*) from Event where event_id not in (select discount_event_id from Discount);
  +----------+
  | count(*) |
  +----------+
  |        0 |
  +----------+
  1 row in set (0,11 sec)
  </code></pre>
  
  <p>These <code>24</code> missing <code>event_id</code>s makes no sense. It's just logically impossible from my point of view. There cannot be <code>24</code> rows that both are and aren't in another set. Or they are, or they aren't.</p>
  
  <p>Also, as suggested from some of the answers and comments, there are no <code>NULL</code> <code>event_id</code>s, since these are the <em>rowids</em>:</p>
  
  <pre><code>mysql&gt; select count(*) from Event where event_id is null;
  +----------+
  | count(*) |
  +----------+
  |        0 |
  +----------+
  </code></pre>
  
  <p>What is going on?</p>