title: Count Alternative For Huge Databases
body: <p><strong>EDIT: Count seems to not work no matter what I do. I was thinking of a different way of counting where I use some kind of SQL query that would re-compile all of the rows id's.</strong></p>
  
  <p><strong>What I mean?
  Example Database:</strong></p>
  
  <pre><code>ID - First Name
  ----------------
  1 - John
  3 - Joe
  4 - Sal
  9 - Murry
  </code></pre>
  
  <p><strong>See it skips 2,5,6,7,8 because those rows were deleted. Is it possible to reset all current rows ids and auto increment them? If so then I could just do: <code>SELECT id FROM table ORDER BY id DESC LIMIT 1</code> and that should take like a few seconds and if I dont delete any records it should be pretty precise too.</strong></p>
  
  <hr>
  
  <p><code>Count(*)</code> is being so slow on my Database with about 800'000 rows.</p>
  
  <p>Almost all the time I can't even load the page.
  Is there any faster alternative? <code>Count(1)</code> makes no difference.</p>
  
  <p>This is my PHP:</p>
  
  
  
  <p>This is the countrows function:</p>
  
  <pre><code>//Create a new function named query;
  function countrows($sql = false,$dbname = false,$obj = false) {
  
      //Prepare The SQL Query;
      $query = Connect('localhost','shinymk_admin','password',$dbname)-&gt;prepare($sql);
  
      $res = true;
  
      //Execute Binded Query;
      try { $query-&gt;execute(); $count = $query-&gt;fetch(PDO::FETCH_NUM); }
  
      catch (PDOException $e) {
  
          $count = false;
  
      }
  
      //If no errors happened Make $row true;
      return $count[0];
  
  }
  </code></pre>