title: Query Hangs when NOT IN is used with a SUBQUERY which returns NULL
body: <p>We are doing this:</p>
  
  <pre><code>SELECT x from d where x not in
  (
  SELECT xx FROM a
  INNER JOIN aa ON a.col = aa.col
  
  UNION
  SELECT xx FROM b 
  INNER JOIN bb on a.col = bb.col
  )
  </code></pre>
  
  <p>When we run sub query separately, it executes in 10 seconds and returns 0 records because one of the tables used in INNER JOIN is blank</p>
  
  <p>But, when we run the entire query, it keeps on running for more than 2 hours and never ends.</p>
  
  <p>When entire query is run, we expect to see all the data from d, but why does the query hangs?</p>