Mysql Optimization

1,921 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,921
On SlideShare
0
From Embeds
0
Number of Embeds
45
Actions
Shares
0
Downloads
80
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Mysql Optimization

  1. 1. MySQL Optimizations Title
  2. 2. MySQL Internals <ul><li>MyISAM </li></ul><ul><li>InnoDB </li></ul><ul><li>MemoryDB </li></ul><ul><li>Indexes </li></ul><ul><li>Ordering </li></ul>
  3. 3. MyISAM <ul><li>MyISAM has no clustered index </li></ul><ul><li>Data ordered by insertion order </li></ul>
  4. 4. InnoDB <ul><li>Clustered index for every table </li></ul><ul><li>rows are physically ordered by the primary key </li></ul><ul><li>Indexes are B-trees. </li></ul><ul><li>Primary key’s leaf nodes are the data . </li></ul><ul><li>there can be page splits </li></ul><ul><li>InnoDB uses the values from the primary key as its secondary index’s leaf nodes </li></ul><ul><li>secondary index lookups are more expensive than primary key lookups, </li></ul><ul><li>Covering index, Using Index </li></ul>
  5. 5. InnoDB
  6. 6. MemoryDB <ul><li>Fixed length </li></ul><ul><li>No blob, clob, text </li></ul>
  7. 7. Indexes <ul><li>Covering indexes - Query can be executed using only data from the index without reading the row itself </li></ul><ul><li>Clustered Indexes (Primary) - Table data is physically stored in the order of the keys on the index </li></ul><ul><li>Non-Clustered Index (Secondary)- </li></ul><ul><ul><li>The data rows of the underlying table are not sorted and stored in order based on their nonclustered keys. </li></ul></ul><ul><ul><li>The leaf layer of a nonclustered index is made up of index pages instead of data pages. </li></ul></ul><ul><li>Index Selectivity- more than 20-25% is bad </li></ul><ul><li>Index Cardinality </li></ul><ul><ul><li>RATIO of number of 'distinct' entries for the index against the total number of records in the table </li></ul></ul><ul><ul><li>Full table scan takes constant time no matter the cardinality, index traversing speed depends on the index cardinality </li></ul></ul>
  8. 8. OrderBy – How to <ul><li>3 Methods </li></ul><ul><li>Index access on an Ordered Index </li></ul><ul><li>FileSorting the table and then join </li></ul><ul><li>Join results to a temporary table and then do FileSort </li></ul><ul><li>FileSorting – 2 methods </li></ul><ul><ul><ul><li>the sorted elements contain all required columns of the source table </li></ul></ul></ul><ul><ul><ul><li>sort pairs and produce a sequence of rowids </li></ul></ul></ul><ul><ul><ul><li>max_length_of_sort_data </li></ul></ul></ul>
  9. 9. OrderBy – How to
  10. 10. OrderBy – How to
  11. 11. OrderBy – How to
  12. 12. Query Optimization <ul><li>Using Explain </li></ul><ul><li>Show table status </li></ul><ul><li>Show InnoDB status </li></ul><ul><li>Show index from table </li></ul>
  13. 13. MySQl Server Optimization <ul><li>Data partitioning </li></ul><ul><li>De-Normalize </li></ul><ul><li>Use of indexes </li></ul><ul><li>Server Tuning </li></ul>
  14. 14. Server Variables <ul><li>read_buffer_size </li></ul><ul><li>read_rnd_buffer_size </li></ul><ul><li>sort_buffer_size </li></ul><ul><li>myisam_sort_buffer_size </li></ul><ul><li>tmp_table_size </li></ul><ul><li>max_heap_table_size </li></ul><ul><li>key_buffer_size </li></ul><ul><li>innodb_buffer_pool_size </li></ul><ul><li>innodb_file_io_threads </li></ul><ul><li>bulk_insert_buffer_size </li></ul><ul><li>table_cache </li></ul><ul><li>open_files_limit </li></ul><ul><li>thread_cache_size </li></ul><ul><li>innodb_flush_log_at_trx_commit </li></ul><ul><li>low-priority-updates </li></ul><ul><li>max_tmp_table </li></ul><ul><li>log-slow-queries </li></ul><ul><li>long_query_time </li></ul><ul><li>join_buffer_size </li></ul>
  15. 15. How Much Buffer Size <ul><li>More is not always good </li></ul><ul><li>Random I/O </li></ul><ul><li>Mmap, malloc </li></ul><ul><li>Fragmentaion </li></ul><ul><li>Test </li></ul>
  16. 16. Show Status <ul><li>Bytes_received </li></ul><ul><li>Bytes_sent </li></ul><ul><li>Com_insert </li></ul><ul><li>Com_select </li></ul><ul><li>Connections </li></ul><ul><li>Created_tmp_disk_tables </li></ul><ul><li>Created_tmp_files </li></ul><ul><li>Created_tmp_tables </li></ul><ul><li>Handler_read_next </li></ul><ul><li>Opened_tables </li></ul><ul><li>Qcache_hits </li></ul><ul><li>Questions </li></ul><ul><li>Select_full_join </li></ul><ul><li>Select_scan </li></ul><ul><li>Select_range </li></ul><ul><li>Slow_queries </li></ul><ul><li>Sort_merge_passes </li></ul><ul><li>Sort_rows </li></ul><ul><li>Sort_scan </li></ul><ul><li>Table_locks_waited </li></ul><ul><li>Threads_cached </li></ul><ul><li>Threads_created </li></ul>
  17. 17. Tools <ul><li>mysqlreport - MySQL stat report </li></ul><ul><li>mysqlsla - MySQL slow log analyser </li></ul><ul><li>innotop - InnoDB monitor </li></ul><ul><li>Mtop </li></ul><ul><li>MaatKit </li></ul><ul><li>Query analyzer </li></ul>

×