title: Problems with ORDER BY RAND() and big tables
body: <p>Hello I asked a question this morning, and I realized that the problem was not where I was looking (<a href="https://stackoverflow.com/questions/64259451/why-does-this-function-use-100-cpu-only-if-call-it-by-onclick-event">here the original question</a>)</p>
  <p>I have this query to randomly generate registries from an address book.</p>
  <pre><code>SELECT * FROM address_book ab 
              WHERE 
              ab.source = &quot;PB&quot; AND 
              ab.city_id = :city_id AND 
              pb_campaign_id = :pb_campaign_id AND 
              ab.id NOT IN (SELECT address_book_id FROM calls WHERE calls.address_book_id = ab.id AND calls.status_id IN (&quot;C&quot;,&quot;NO&quot;) OR (calls.status_id IN (&quot;NR&quot;,&quot;OC&quot;) AND TIMESTAMPDIFF(MINUTE,calls.updated_at,NOW()) &lt; 30))
              ORDER BY RAND()
              LIMIT 1';
  </code></pre>
  <p>but I noticed that &quot;order by rand ()&quot; take more than 50s and use up to 25-50% CPU with large tables (100k +) so i looked for solutions here but i didn't find anything that worked.
  note: <strong>ids are not self-incrementing, there may be gaps</strong></p>
  <p>Any idea?</p>