Making MySQL Fast

Embed Size (px)

DESCRIPTION

A talk I gave at Multipack Show & Tell in February 2011

Citation preview

  • 1.
    • Making MySQL fast Richard Cunningham (@rythie)

2. FriendBinder

3.

  • How to measure
    • MySQL slow query log
  • 4. 'Explain Extended' feature of MySQL

5. Apache custom logs, page load time (%D) 6. mysql> show processlist; 7. iostat -x 10 / munin / RDDtool etc. 8. On FriendBinder we have (in dev. mode):

      • a page timer
    • 9. Explain extended and times for all queries on page
  • 10. Page load times recorded for all users

11.

  • Hard Disks
  • Sequential performance performance of 'spinning' disk is120Mb/sec , 1GBit network can only do 125Mb/sec, sounds good, but... What about 4KB random reads?
    • Fast Hard disk0.7MB/sec
  • 12. consumer Intel SSD:64.3MB/sec

13. RAM~4-16,000MB/sec

  • source: Anandtech: http://j.mp/g4lD6w

14.

  • Indexes
    • MySQL only uses one index per table for each query
  • 15. A index can cover several columns but can't miss one

16. Examples... 17. WHERE user=1 AND pub_date=NOW() AND id=34 18. WHERE user=1 AND id=34 19. WHERE user=1 AND pub_date < NOW() AND id=34 User pub_date id User pub_date id User pub_date id 20.

  • Covering Indexes
  • A covering index is one all of the query can be resolved from the index including the WHERE, JOIN and SELECT parts.
  • Covering...

21. SELECT date_pub FROM table1 22. WHERE User=2 23. Not covering... 24. SELECT name FROM table1 25. WHERE user=2 User pub_date id User pub_date id 26.

  • Clustered Indexes
  • In the MyISAM table type new records are simply added to the end of file. Problem is that queries often are jumping all around the file.
  • In InnoDB the records are stored in order of the primary key

27.

  • What not to index
    • Binary columns - these are not selective enough, MySQL will never use it
  • 28. Subset indexes of other indexes

29. Anything you don't have a query for design indexes for queries User pub_date User pub_date id 30.

  • Further Information
    • This book has more...
  • Contacting me:
  • @rythie

31. www.rythie.com 32. [email_address]