출처 : http://www.84bytes.com/2008/10/14/mysql-query-performance-tips/

Almost all of the modern web applications involve the use of relational database. So the performance of your applications are very much affected by the quality of the SQL queries you run. Here are some simple performance tips from MYSQL forge that you should consider when writing queries.

1. Use EXPLAIN to profile the query execution plan (EXPLAIN 명령어로 실행할 쿼리를 조사해보기)
2. Use Slow Query Log (always have it on!)
3. Don’t use DISTINCT when you have or could use GROUP BY
4. Insert performance
   1. Batch INSERT and REPLACE
   2. Use LOAD DATA instead of INSERT (대용량일 때는 Insert보다는 LOAD DATA 명령어로~)
5. LIMIT m,n may not be as fast as it sounds
6. Don’t use ORDER BY RAND() if you have > ~2K records
7. Use SQL_NO_CACHE when you are SELECTing frequently updated data or large sets of data
8. Avoid wildcards at the start of LIKE queries
9. Avoid correlated subqueries and in select and where clause (try to avoid in)
10. ORDER BY and LIMIT work best with equalities and covered indexes
11. Separate text/blobs from metadata, don’t put text/blobs in results if you don’t need them
12. Delete small amounts at a time if you can
13. Make similar queries consistent so cache is used
14. Don’t use deprecated features
15. Turning OR on multiple index fields (<5.0) into UNION may speed things up (with LIMIT), after 5.0 the index_merge should pick stuff up.
16. Use INSERT … ON DUPLICATE KEY update (INSERT IGNORE) to avoid having to SELECT

Now if you know all the above tips, then may be you want to start looking at database scaling, design and more from MYSQL forge.

Here are some more detailed articles about optimizing MySQL for those of you want to get your hands dirty:


'Technology > Database' 카테고리의 다른 글

MySQL / MySQL Grant 권한주기  (0) 2011.01.07
MySQL / Join 중복문제  (0) 2010.04.06
MySQL / AND, OR, NOT with NULLs (Three-value logic)  (0) 2010.02.17
MySQL / MySQL 튜닝  (0) 2010.02.10
MySQL / 데이터베이스의 생성과 삭제  (0) 2010.02.10

+ Recent posts