title: Milion Record Sql Order By and count rows
body: <p>I have a database with millions of records.
  The table is structured as:</p>
  
  <hr>
  
  <p>Table name : record</p>
  
  <p>Filed1: Name (varchar)(Primary key)</p>
  
  <p>Field2: Record(int/bigint)</p>
  
  <p>example:</p>
  
  <p><strong>Name | Record</strong></p>
  
  <p>Darrin | 256</p>
  
  <p>Aaron | 3</p>
  
  <p>Daryl | 12</p>
  
  <p>...</p>
  
  <hr>
  
  <p>I need to know what position does the user with the name 'namex' in sorted records.</p>
  
  <p>Currently i implement this solution:</p>
  
  <pre><code>...
  
  $name=namex;
  $query= mysqli_query($mysqli,"SELECT Name FROM record  ORDER BY Record DESC");
  
  $x=0;
  $rank=0;
  if ($query-&gt;num_rows &gt; 0) {
      // output data of each row
      while($row = $query-&gt;fetch_assoc()) {
          if($row["Name"]==$name){
              $rank=$x+1;
              echo "Rank : $rank&lt;br&gt;";
  
              break;
          }
  
  
          $x++;
      }
  }
  
  ...
  </code></pre>
  
  <p>With it and 1 million records in the database, the answer comes in about 4 second.</p>
  
  <p>I tried to put a table index on the field Record but have remained the same performance.</p>
  
  <p>how can I reduce the execution times?</p>