title: What is a good way to find the closest 100 matches to a single index/hash when comparing it to 2M+ indexes/hashes stored in a MySQL Table?
body: <p>I have a single hash/index in PHP which I need to compare to a table with 2M+ rows.</p>
  
  <p>If I compare using like, '=' it will try to find me exact matches.</p>
  
  <p>I would instead like to find the closest matches using a hamming distance.</p>
  
  <p>How do I show the closest 100 matches and order them.</p>
  
  <p>Thoughts to consider:
  When comparing the given hash/index to the table, there will be 2M+ distances calculated, which will be difficult to order.</p>
  
  <p>Progress so far:
  Use php to do an insert sort into an array of 100 elements and then remove the last element every time a smaller distance is found, then update my 'threshhold' value to the 100th element so that I reduce the number of values needed to be inserted over time.</p>