Jump to content

BigDummy

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

BigDummy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. That is exactly what I will do. I really should have thought of that. Hence my username. Thanks very much for your suggestions.
  2. Rank is indexed in the stats table, and so is memberid, along with member.id in the member table. I had thought about breaking it down like you mentioned, and I think that is what I will do. Still, I do things like this quite frequently, and I would love to know how to speed it up in a single query. Thanks again.
  3. I cannot seem to optimize this query. SELECT username,rank FROM stats LEFT JOIN member ON memberid=member.id ORDER BY rank DESC LIMIT 10 where username is in the member table and rank is in the stats table. It is taking much longer than I know it should. Here is the EXPLAIN of the query: +--------+--------+---------------+---------+---------+----------------+-------+----------------+ | table | type | possible_keys | key | key_len | ref | rows | Extra | +--------+--------+---------------+---------+---------+----------------+-------+----------------+ | stats | ALL | NULL | NULL | NULL | NULL | 49999 | Using filesort | | member | eq_ref | PRIMARY | PRIMARY | 3 | stats.memberid | 1 | | +--------+--------+---------------+---------+---------+----------------+-------+----------------+ It seems that it is doing the JOIN first, and then the ORDER and LIMIT. I say this because if I add a where clause like \"WHERE rank > 10000\" it is almost instanteous. Unfortunately I will not always know what number to use in place of 10000. According to the MySQL documentation, this query should use the index for sorting instead of the file sort, which it does if I remove the join as in: desc SELECT rank FROM stats ORDER BY rank DESC LIMIT 10; +-------+-------+---------------+------+---------+------+-------+-------------+ | table | type | possible_keys | key | key_len | ref | rows | Extra | +-------+-------+---------------+------+---------+------+-------+-------------+ | stats | index | NULL | rank | 10 | NULL | 49999 | Using index | +-------+-------+---------------+------+---------+------+-------+-------------+ which is also instanteous. Can anyone help me optimize this?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.