title: MySql is null vs is not null performance
body: <p>I have a query where I am basically doing a left outer join and checking if the joined value is null</p>
  <pre><code>select count(T1.code) 
  from ( select code 
         from asset 
         where type = 'meter' 
         and creation_time &lt;= '2022-04-29 00:00:00' 
         and (deactivation_time &gt; '2022-04-28 00:00:00' or deactivation_time is null ) 
         group by code
         ) as T1 
  left join ( select asset_code 
              from amr_midnight_data 
              where server_time between '2022-04-28 00:00:00' and '2022-04-29 00:00:00' 
              group by asset_code
           ) as T2 on T1.code = T2.asset_code 
  Where T2.asset_code is null;
  </code></pre>
  <p>This query takes 3 seconds to execute, but if I replace the is null at the end with is not null, it takes less then a second. Why is there a performance difference here and what alternatives do I have to make my original query faster?</p>