MySQL Forums
Forum List  »  Optimizer & Parser

Re: Dynamic Queries Optimization
Posted by: Rick James
Date: November 18, 2010 12:46AM

MySQL's optimizer always dynamically decides how to optimize each query. Don't worry. (This is unlike what some competitors do.)

WHERE id=1 GROUP BY id -- Why have the GROUP BY?

WHERE id=1 ORDER BY date DESC; -- needs INDEX(id, date)

WHERE id=1 ORDER BY date DESC; -- The ORDER BY is useless if id is UNIQUE.

WHERE username='abc' ORDER BY id; -- needs INDEX(username, id)

SELECT count(userid) FROM table WHERE email='abc@example.com' GROUP BY userid ORDER BY id DESC; -- this ORDER BY does not make sense in this context.

Maybe those are not real queries?

Options: ReplyQuote


Subject
Views
Written By
Posted
2506
November 15, 2010 01:51PM
Re: Dynamic Queries Optimization
1461
November 18, 2010 12:46AM


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.