MySQL Forums
Forum List  »  Optimizer & Parser

Re: Query using "ref" instead of "range" access
Posted by: Rick James
Date: July 12, 2009 09:32AM

Thanks for the timing and the bug link. I learned something.

The query is Order(n*n), so the real optimization is to shrink that to Order(n*log(n)) or better.

If 2 sec is not adequate, there may be complex ways (I have not thought through the details):

Plan A: Summary table that is maintained whenever a game is played. It would be indexed by a pair of player ids. It would be updated (twice?) to change the relative info about that pair of players. Then the SELECT could run against this table, thereby avoiding the subquery. Possibly a trigger could be used to do the update. (INSERTs would be slower, but probably tolerable.)

Plan B: Instead if trying to do the SELECT in a single statement, create a TEMPORARY TABLE. (I haven't thought through what would go in it.) Possibly add an INDEX to it (hence, the log(n)). Then SELECT from the tmp table.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Query using "ref" instead of "range" access
2160
July 12, 2009 09:32AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.