title: MySql Query Takes A Long Time PHP
body: <p>I have the following PHP code in Laravel is executing a MySql query:</p>
  
  <pre><code>DB::statement(DB::raw("SET @rownum = 0"));
  $sql = "@rownum := @rownum+1 AS rank, id, clanid, name, location, level, exp, warslost, warstied, warwinpercent, warswon, playercount, score";
  $clan = Clans::orderBy('clanid', 'asc')
      -&gt;selectRaw($sql)
      -&gt;take(7000)
      -&gt;get();
  </code></pre>
  
  <p>This query is taking a long time to execute. </p>
  
  <p>I have indexes on the columns I am ordering by as well as many of the other ones for other queries.</p>
  
  <p>What should I do?</p>
  
  <p>Update:</p>
  
  <p>Queries executed:</p>
  
  <pre><code>SET @rownum = 0
  
  select @rownum := @rownum+1 AS rank, id, clanid, name, location, level, exp, warslost, warstied, warwinpercent, warswon, playercount, score from `clans` order by `clanid` asc limit 7000
  </code></pre>
  
  <p><code>EXPLAIN EXTENDED</code> result:</p>
  
  <p><a href="https://i.stack.imgur.com/7T2sA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7T2sA.png" alt=""></a></p>