title: Slow MYSQL Query with 500,000 records
body: <p>I have a mySQL table of around 500,000 records. The table is around 45MB in size. The first time the query executes, it takes nearly 20 seconds each time but subsequent queries are fast. If I log out, and log back in, Queries are still fast.  If I come back 4-5 hours later.  The same Query is slow again.</p>
  
  <p>The query is pretty simple.</p>
  
  <pre><code>$query = "select * from tableName where uniqueID='$passedID' ORDER BY tableName ASC";
  $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  </code></pre>
  
  <p>The site is being hosted on a VPS with 1 GB of memory. Site receives, approximately 150 visitors a day, each visiting 10 pages or so.  500,000 records doesn't appear to be too large so the performance should be fine.  Does anyone have any ideas what may be causing the slowness?</p>