So today I was helping someone out with their database performance and ran across some poorly written queries. Now, certainly everyone makes mistakes, the goal is to do everything you can to avoid them.
So just a couple of helpful hints to do before you let a query loose into your environment.
Always execute the query via explain first. Something as simple as doing explain first will confirm no typos (since it will not run), and allow you optimize the query.
Several links already exist about how to use explain:
The next hint, try to test your queries with SQL_NO_CACHE. This allows you to test the real query and optimize it the best way you can. Once it becomes cached ( if it will be ) then it will just run that much faster for you.
So just a couple of helpful hints to do before you let a query loose into your environment.
Always execute the query via explain first. Something as simple as doing explain first will confirm no typos (since it will not run), and allow you optimize the query.
Several links already exist about how to use explain:
- http://ronaldbradford.com/blog/tag/explain/
- http://www.mysqlperformanceblog.com/2014/02/03/percona-toolkit-collection-pt-visual-explain/
- http://www.ustream.tv/recorded/15872720
- https://www.youtube.com/watch?v=qaB85pMVNJU
- https://dev.mysql.com/doc/refman/5.6/en/using-explain.html
- http://www.sitepoint.com/using-explain-to-write-better-mysql-queries/
The next hint, try to test your queries with SQL_NO_CACHE. This allows you to test the real query and optimize it the best way you can. Once it becomes cached ( if it will be ) then it will just run that much faster for you.
- https://dev.mysql.com/doc/refman/5.6/en/select.html
- http://ronaldbradford.com/blog/using-the-mysql-query-cache-effectively-2009-09-28/
No comments:
Post a Comment
@AnotherMySQLDBA