Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should add an index on <code>(tried, id)</code>.</p> <p>You already added an index on <code>(username,id,tried)</code> but this index cannot be used efficiently for the query you wrote because the field <code>tried</code> is not the first item in the index.</p> <hr> <p>From the manual page <a href="http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html" rel="nofollow">How MySQL Uses Indexes</a>:</p> <blockquote> <p>MySQL uses indexes for these operations:</p> <ul> <li><p>To find the <code>MIN()</code> or <code>MAX()</code> value for a specific indexed column <code>key_col</code>. This is optimized by a preprocessor that checks whether you are using <code>WHERE key_part_N = constant</code> on all key parts that occur before <code>key_col</code> in the index. In this case, MySQL does a single key lookup for each <code>MIN()</code> or <code>MAX()</code> expression and replaces it with a constant. If all expressions are replaced with constants, the query returns at once. For example:</p> <p>SELECT MIN(key_part2),MAX(key_part2) FROM tbl_name WHERE key_part1=10;</p></li> </ul> </blockquote> <p>Note in particular that the <code>WHERE</code> clause must refer to columns that occur <em>before</em> the column for which you wish to calculate the <code>MIN</code> or <code>MAX</code>, which is why your current index is not used efficiently.</p> <hr> <blockquote> <p>I need to rapidly do select queries on it in a loop</p> </blockquote> <p>Are you sure that you need to query in a loop? Have you considered moving the loop into the database? Maybe what you really need is a join? It's better to send a single query that fetches a lot of data than lots of small queries that fetch only a small amount of data each.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload