Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DOs and DON'Ts of MySQL Performance

TheBerg
July 10, 2014

DOs and DON'Ts of MySQL Performance

TheBerg

July 10, 2014
Tweet

Other Decks in Technology

Transcript

  1. when? • On almost every column ending in _id •

    On any column in WHERE, GROUP or ORDER • Be careful about adding too many
  2. left to right Index: first_name, last_name Query: 
 SELECT *

    FROM people WHERE first_name = ‘Jeff’ AND last_name = ‘Berg’
  3. left to right Index: first_name, last_name Query: 
 SELECT *

    FROM people WHERE last_name = ‘Berg’ AND first_name = ‘Jeff’
  4. left to right Index: first_name, last_name Query: 
 SELECT *

    FROM people WHERE first_name = ‘Jeff’
  5. left to right Index: first_name, last_name Query: 
 SELECT *

    FROM people WHERE last_name = ‘Jeff’
  6. don’t use like wrong Index: first_name, last_name Query: 
 SELECT

    * FROM people WHERE phone_number LIKE ‘760%’
  7. don’t use like wrong Index: first_name, last_name Query: 
 SELECT

    * FROM people WHERE phone_number LIKE ‘%1234’
  8. do use profiling SET PROFILING = 1; ! SELECT *

    FROM ccli_songs
 WHERE title LIKE ‘Title%'; ! SHOW PROFILE;
  9. check your config innodb_buffer_pool_size, innodb_log_file_size, max_connections, innodb_file_per_table, innodb_flush_log_at_trx_commit, innodb_flush_method, innodb_log_buffer_size,

    query_cache_size, log_bin, skip_name_resolve http://www.mysqlperformanceblog.com/2014/01/28/10-mysql-settings-to-tune-after-installation/
  10. primary keys • data is organized via primary key •

    integer auto increment primary key puts rows on disk in order created • UUID primary key puts rows in random order • combined PK, puts items in order grouped
  11. the right hardware • SSDs are worth their weight in

    gold • Try to have enough RAM to hold your whole database in memory
  12. don’t use mysql • use percona server or maria db

    • many Google & Facebook patches applied • many percona ideas • ran by many of original mysql team after oracle acquisition
  13. don’t use mysql • MySQL acquired by Sun • Sun

    acquired by Oracle • Oracle makes a lot of money charging for databases