SlideShare una empresa de Scribd logo
1 de 30
MySQLinsanity!




                 1
Topic

▪ Who am I?
▪ MySQL performance tuning experience sharing.
▪ Q & A.




                                                 2
Who am I?

▪ Stanley Huang (黃偉倫)
▪ My email
 ▪ wenlien1001@gmail.com
▪ My Blog
 ▪ http://stanley-huang.blogspot.com




                                       3
MySQL performance tuning experience
sharing

▪       What happened to the product?
    ▪    Too many data and have query performance issue
▪       Performance tuning phases
    1. SQL tuning
           ▪   Over 90%, bad SQLs make great impact on
               performance
           ▪   Over 90%, do not using the correct index(es) in bad
               SQLs
    2. RDBMS tuning



                                                          4
MySQL SQL tuning(1/2)

▪ Enable slow query log and find out the top 10 slow
  queries
 ▪ Add two settings in my.cnf
   ▪ log-slow-queries ## default off
   ▪ long-query-time=5 ## default 10
 ▪ [data folder]/[host name]-slow.log




                                                  5
MySQL SQL tuning(2/2)

▪    Perform full-text search on InnoDB
     (select … like ‘*pattern*’)
    1. Change storage engine from InnoDB to MyISAM
    2. Hybrid storage engine, create a new MyISAM table and move
       data need to be full-text search from InnoDB to MyISAM
▪    Too many indexes
    1. Create more indexes won’t enhance performance but impact on
       writing.
    2. (Suggestion) Don’t create more than 5 indexes on one table.


    InnoDB in MySQL 5.6 has supported full-text search

                                                            6
Useful Tips For Networking System

1. IP Support
2. Mac Support




                             7
IP address support

 Build In Function: inet_ntoa()/inet_aton()
  mysql> CREATE TABLE testIP (
  ip_int int unsigned DEFAULT NULL,
  ip_char char(15) DEFAULT NULL,
  index ip_int (ip_int),
  index ip_char (ip_char)
  ) ENGINE=InnoDB;
  mysql> insert into testIP valuse(inet_aton('216.18.50.126'),'216.18.50.126');
  mysql> select inet_ntoa(ip_int),ip_char from testIP;
  +-------------------+---------------+
  | inet_ntoa(ip_int) | ip_char         |
  +-------------------+---------------+
  | 216.18.50.126 | 216.18.50.126 |
  +-------------------+---------------+




                                                                      8
Execution Plain

mysql> explain select * from testIP where ip_char='216.18.50.126';
  +----+-------------+--------+------+---------------+---------+---------+-------+------+-------------+
  | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra                |
  +----+-------------+--------+------+---------------+---------+---------+-------+------+-------------+
  | 1 | SIMPLE        | testIP | ref | ip_char        | ip_char | 16       | const | 1 | Using where |
  +----+-------------+--------+------+---------------+---------+---------+-------+------+-------------+

mysql> explain select * from testIP where ip_int=inet_aton('216.18.50.126');
  +----+-------------+--------+------+---------------+--------+---------+-------+------+-------------+
  | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra                 |
  +----+-------------+--------+------+---------------+--------+---------+-------+------+-------------+
  | 1 | SIMPLE        | testIP | ref | ip_int        | ip_int | 5     | const | 1 | Using where |
  +----+-------------+--------+------+---------------+--------+---------+-------+------+-------------+




                                                                                             9
Mac address support??

   Build In Function: hex()
    mysql> create table testMAC(mac_bit bit(48), mac_char char(17),
    index(mac_bit), index(mac_char));
    mysql> insert into testMAC values (x'00241DDC5548', '00:24:1D:DC:55:48');
    mysql> select hex(mac_bit), mac_char from testMAC;
    +--------------+-------------------+
    | hex(mac_bit) | mac_char            |
    +--------------+-------------------+
    | 241DDC5548 | 00:24:1D:DC:55:48 |
    +--------------+-------------------+
    Build In Function seems not enough~

    1.   create MySQL stored function

    2.   create UDF (User Define Function)




                                                                     10
Execution Plain


mysql> explain select hex(mac_bit), mac_char from testMAC where
mac_char='00:24:1D:DC:55:48';
+----+-------------+----------+------+---------------+----------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key              | key_len | ref | rows | Extra      |
+----+-------------+----------+------+---------------+----------+---------+-------+------+-------------+
| 1 | SIMPLE        | testMAC2 | ref | mac_char             | mac_char | 18        | const | 1 | Using where |
+----+-------------+----------+------+---------------+----------+---------+-------+------+-------------+


mysql> explain select hex(mac_bit), mac_char from testMAC where mac_bit=x'00241DDC5548';
+----+-------------+----------+------+---------------+---------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra                  |
+----+-------------+----------+------+---------------+---------+---------+-------+------+-------------+
| 1 | SIMPLE        | testMAC2 | ref | mac_bit            | mac_bit | 7        | const | 1 | Using where |
+----+-------------+----------+------+---------------+---------+---------+-------+------+-------------+




                                                                                            11
Stored Function for MAC address
## create stored function ether_atob(), from ascii to bit
## must define "deterministic", or explain will not use index


  delimiter //
  drop function if exists ether_atob//
  create function ether_atob(sAscii char(17))
  returns bit(48)
  deterministic
  Begin
   declare bReturn bit(48);
   set bReturn=unhex(replace(sAscii,':',''));
   return bReturn;
  end//
  delimiter ;




                                                                12
Stored Function for MAC address
(cont.)
## create stored function ether_btoa(), from bit to ascii
## must define "deterministic", or explain will not use index


  delimiter //
  drop function if exists ether_btoa//
  create function ether_btoa(sBit bit(48))
  returns char(17)
  deterministic
  begin
   declare sReturn char(17);
   set sReturn=lpad(hex(sBit),12,'0');
   set sReturn=concat_ws(':', substr(sReturn,1,2), substr(sReturn,3,2),
  substr(sReturn,5,2),
       substr(sReturn,7,2), substr(sReturn,9,2), substr(sReturn,11,2));
   return sReturn;
  end//
  delimiter ;


                                                                  13
Stored Function for MAC address
(cont.)
mysql> create table ether_table (b bit(48), a char(17), index(b), index(a));
 Query OK, 0 rows affected (0.67 sec)
mysql> insert into ether_table values
 (ether_atob('00:CD:EF:00:CD:EF'),'00:CD:EF:00:CD:EF');
 Query OK, 1 row affected (0.01 sec)
mysql> select ether_btoa(b), a from ether_table
 where b=ether_atob('00:CD:EF:00:CD:EF');
 +----------------+-------------------+
 | ether_btoa(b) | a                  |
 +----------------+-------------------+
 | 00:CD:EF:00:CD:EF | 00:CD:EF:00:CD:EF |
 +----------------+-------------------+
 1 rows in set (0.01 sec )




                                                                     14
Stored Function for MAC address
  (cont.)

mysql> explain select ether_btoa(b), a from ether_table where
b=ether_atob('00:CD:EF:00:CD:EF');
+----+-------------+-------------+------+---------------+------+---------+-------+------+-------------+
| id | select_type | table        | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------+------+---------------+------+---------+-------+------+-------------+
| 1 | SIMPLE        | ether_table | ref | b              |b |7         | const | 1 | Using where |
+----+-------------+-------------+------+---------------+------+---------+-------+------+-------------+
1 row in set (0.00 sec)




                                                                                    15
Create UDF

▪ http://stanley-huang.blogspot.com/2010/03/level-3-
  create-udf-for-storing-mac.html




                                                 16
Using UDF on MySQL Database

Make sure your MySQL supports UDF.
mysql> create function lib_mysqludf_log_info returns string soname
 'lib_mysqludf_log.so';
ERROR 1126 (HY000): Can't open shared library 'lib_mysqludf_log.so' (errno:
 0 feature disabled)




                                                                 17
Compile MySQL with UDF enable

1. Download source code
2. # ./configure --with-mysqld-ldflags=--rdynamic
3. # gcc -shared -o ./udf_example.so ./udf_example.c -
   I/usr/local/include/mysql -fPIC
4. # cp ./udf_example.so /usr/local/mysql/lib/mysql/plugin
5. mysql> CREATE FUNCTION metaphon RETURNS STRING
   SONAME 'udf_example.so';
   ERROR 1126 (HY000): Can't open shared library 'udf_example.so'
   (errno: 22 /usr/local/lib/mysql/plugin/udf_example.so: cannot
   restore segment prot after reloc: Permission denied)
6. # chcon -t texrel_shlib_t /usr/local/lib/mysql/plugin/udf_example.so




                                                             18
Characters of Stored Function, UDF
and Native Function


Method   Speed   Language Development Maintenance

Stored   slow    SQL      ~minutes     easy
Function                  (for small
                          functions)
UDF      fast    C        ~hour        hard
Native   fast    C        Major pain   hard
Function




                                          19
Compare with UDF and Stored
Functions




Reference: Roland Bouman's blog
http://rpbouman.blogspot.com/2008/03/
udfs-at-mysql-users-conference.html
                                        20
MySQL performance tuning

▪ Separate disk I/O
  ▪ Separate disk I/O of bin log files and data files to different disks
▪ MyISAM configuration
  ▪ key_buffer_size=128M            # default is 8M
  ▪ bulk_insert_buffer_size=4194304 # default is 8M
▪ InnoDB configuration
  ▪ innodb_buffer_pool_size=32M # default
  ▪ 8Minnodb_log_buffer_size=8M # default 1M
▪ Prevent large single large file of InnoDB tablespace
  ▪ innodb_file_per_table




                                                                      21
MySQL upgrade from 5.0 to 5.1

▪ In internal tests, MySQL 5.1 demonstrates, on average, a 15% gain
  in total performance over MySQL 5.0. (There really is the free lunch)




                                                            22
Partitioning Sample SQL

mysql> CREATE TABLE test_partition_np

-> ( c1 int default NULL,

-> c2 varchar(30) default NULL,

-> c3 date default NULL

-> ) engine=InnoDB;

Query OK, 0 rows affected (0.00 sec)




                                        23
What's wrong with “my” SQL

mysql> select count(1) from test_partition_wp where year(c3)=1995;
  +----------+
  | count(1) |
  +----------+
  | 47358 |
  +----------+
  1 row in set (0.58 sec)

mysql> select count(1) from test_partition_np where year(c3)=1995;
  +----------+
  | count(1) |
  +----------+
  | 47358 |
  +----------+
  1 row in set (0.53 sec) -- Faster then partition table, why??



                                                                     24
Execution Plan

mysql> explain partitions select count(1) from test_partition_wp where
  year(c3)=1995G
  *************************** 1. row ***************************
  id: 1
  select_type: SIMPLE
  table: test_partition_wp
  partitions: p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11
  type: ALL
  possible_keys: NULL
  key: NULL
  key_len: NULL
  ref: NULL
  rows: 12006556
  Extra: Using where
  1 row in set (0.00 sec)



                                                                    25
The correct SQL

mysql> select count(1) from test_partition_wp where c3 between '1995/01/01'
  and '1995/12/31';
  +----------+
  | count(1) |
  +----------+
  | 47358 |
  +----------+
  1 row in set (0.04 sec) -- That's what I want!!

mysql> select count(1) from test_partition_np where c3 between '1995/01/01' and
  '1995/12/31';
  +----------+
  | count(1) |
  +----------+
  | 47358 |
  +----------+
  1 row in set (0.62 sec)

                                                                  26
Execution Plan

mysql> explain partitions select count(1) from test_partition_wp where c3
  between '1995/01/01' and '1995/12/31'G
  *************************** 1. row ***************************
  id: 1
  select_type: SIMPLE
  table: test_partition_wp
  partitions: p1
  type: ALL
  possible_keys: NULL
  key: NULL
  key_len: NULL
  ref: NULL
  rows: 12006556
  Extra: Using where
  1 row in set (0.00 sec)



                                                                    27
Performance Enhancement With Table
Partitioning

After we use partition on the large tables, the performance raise 11-45% up.
1. 5.1-partition 377.4146         tableA
   5.1             687.4756          tableA
   (687.4756-377.4146) / 687.4756 = 0.45
2. 5.1-partition 171.7333         tableB
   5.1             193.9878          tableB
   (193.9878-171.7333) / 193.9878 = 0.11
3. 5.1-partition 22.0741     tableC
   5.1             34.4792      tableC
   (34.4792-22.0741) / 34.4792 = 0.36
4. 5.1-partition 1.8519      tableD
   5.1             3.3750       tableD
   (3.3750-1.8519) / 3.3750 = 0.45



                                                                  28
MySQL Performance Tips Summary

▪ Use EXPLAIN to profile the query.
▪ Always have slow query log.
▪ Avoid using wildcards at the start of LIKE queries.
▪ Isolate the workloads.
▪ Using data partitions..
▪ Don’t duplicate indexes.
▪ Use INET_ATON and INET_NTOA.
▪ Hire a MySQL Certified DBA.

http://forge.mysql.com/wiki/Top10SQLPerformanceTips




                                                        29
Q&A




      30

Más contenido relacionado

La actualidad más candente

MySQL Document Store
MySQL Document StoreMySQL Document Store
MySQL Document StoreI Goo Lee
 
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB ClusterHow to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB ClusterSveta Smirnova
 
Introduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sIntroduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sSveta Smirnova
 
How to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with GaleraHow to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with GaleraSveta Smirnova
 
PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개PgDay.Seoul
 
Managing MariaDB Server operations with Percona Toolkit
Managing MariaDB Server operations with Percona ToolkitManaging MariaDB Server operations with Percona Toolkit
Managing MariaDB Server operations with Percona ToolkitSveta Smirnova
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL PerformanceSveta Smirnova
 
My sql fabric ha and sharding solutions
My sql fabric ha and sharding solutionsMy sql fabric ha and sharding solutions
My sql fabric ha and sharding solutionsLouis liu
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in ActionSveta Smirnova
 
How to migrate from MySQL to MariaDB without tears
How to migrate from MySQL to MariaDB without tearsHow to migrate from MySQL to MariaDB without tears
How to migrate from MySQL to MariaDB without tearsSveta Smirnova
 
New features-in-mariadb-and-mysql-optimizers
New features-in-mariadb-and-mysql-optimizersNew features-in-mariadb-and-mysql-optimizers
New features-in-mariadb-and-mysql-optimizersSergey Petrunya
 
Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON? Sveta Smirnova
 
Using Apache Spark and MySQL for Data Analysis
Using Apache Spark and MySQL for Data AnalysisUsing Apache Spark and MySQL for Data Analysis
Using Apache Spark and MySQL for Data AnalysisSveta Smirnova
 
Introduction into MySQL Query Tuning
Introduction into MySQL Query TuningIntroduction into MySQL Query Tuning
Introduction into MySQL Query TuningSveta Smirnova
 
Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance Alexey Ermakov
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingSveta Smirnova
 
Spider Setup with AWS/sandbox
Spider Setup with AWS/sandboxSpider Setup with AWS/sandbox
Spider Setup with AWS/sandboxI Goo Lee
 
MyAWR another mysql awr
MyAWR another mysql awrMyAWR another mysql awr
MyAWR another mysql awrLouis liu
 

La actualidad más candente (20)

MySQL Document Store
MySQL Document StoreMySQL Document Store
MySQL Document Store
 
MySQL 5.5 Guide to InnoDB Status
MySQL 5.5 Guide to InnoDB StatusMySQL 5.5 Guide to InnoDB Status
MySQL 5.5 Guide to InnoDB Status
 
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB ClusterHow to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
 
Introduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sIntroduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]s
 
How to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with GaleraHow to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with Galera
 
PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개
 
Managing MariaDB Server operations with Percona Toolkit
Managing MariaDB Server operations with Percona ToolkitManaging MariaDB Server operations with Percona Toolkit
Managing MariaDB Server operations with Percona Toolkit
 
Mysql56 replication
Mysql56 replicationMysql56 replication
Mysql56 replication
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL Performance
 
My sql fabric ha and sharding solutions
My sql fabric ha and sharding solutionsMy sql fabric ha and sharding solutions
My sql fabric ha and sharding solutions
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in Action
 
How to migrate from MySQL to MariaDB without tears
How to migrate from MySQL to MariaDB without tearsHow to migrate from MySQL to MariaDB without tears
How to migrate from MySQL to MariaDB without tears
 
New features-in-mariadb-and-mysql-optimizers
New features-in-mariadb-and-mysql-optimizersNew features-in-mariadb-and-mysql-optimizers
New features-in-mariadb-and-mysql-optimizers
 
Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON?
 
Using Apache Spark and MySQL for Data Analysis
Using Apache Spark and MySQL for Data AnalysisUsing Apache Spark and MySQL for Data Analysis
Using Apache Spark and MySQL for Data Analysis
 
Introduction into MySQL Query Tuning
Introduction into MySQL Query TuningIntroduction into MySQL Query Tuning
Introduction into MySQL Query Tuning
 
Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
Spider Setup with AWS/sandbox
Spider Setup with AWS/sandboxSpider Setup with AWS/sandbox
Spider Setup with AWS/sandbox
 
MyAWR another mysql awr
MyAWR another mysql awrMyAWR another mysql awr
MyAWR another mysql awr
 

Destacado

Introduction4 SQLite
Introduction4 SQLiteIntroduction4 SQLite
Introduction4 SQLiteStanley Huang
 
Facebook and Beyond - Lessons for Brand Engagement with Social Customers
Facebook and Beyond - Lessons for Brand Engagement with Social Customers Facebook and Beyond - Lessons for Brand Engagement with Social Customers
Facebook and Beyond - Lessons for Brand Engagement with Social Customers Lithium
 
Seo Sm 2010 Presentation
Seo Sm 2010 PresentationSeo Sm 2010 Presentation
Seo Sm 2010 PresentationMark_Juelich
 
2010 01 lecture SIG UM MFES 3 - Reverse engineering
2010 01 lecture SIG UM MFES 3 - Reverse engineering2010 01 lecture SIG UM MFES 3 - Reverse engineering
2010 01 lecture SIG UM MFES 3 - Reverse engineeringjstvssr
 
Mysql Datadictionary
Mysql DatadictionaryMysql Datadictionary
Mysql Datadictionarykalog
 
Databases for Beginners SQLite
Databases for Beginners SQLiteDatabases for Beginners SQLite
Databases for Beginners SQLiteChristopher Wimble
 
SQLite3
SQLite3SQLite3
SQLite3cltru
 
SQLite Techniques
SQLite TechniquesSQLite Techniques
SQLite Techniquesjoaopmaia
 
SQLite: Light, Open Source Relational Database Management System
SQLite: Light, Open Source Relational Database Management SystemSQLite: Light, Open Source Relational Database Management System
SQLite: Light, Open Source Relational Database Management SystemTanner Jessel
 
Steganography presentation
Steganography presentationSteganography presentation
Steganography presentationAshwin Prasad
 

Destacado (18)

Introduction4 SQLite
Introduction4 SQLiteIntroduction4 SQLite
Introduction4 SQLite
 
Facebook and Beyond - Lessons for Brand Engagement with Social Customers
Facebook and Beyond - Lessons for Brand Engagement with Social Customers Facebook and Beyond - Lessons for Brand Engagement with Social Customers
Facebook and Beyond - Lessons for Brand Engagement with Social Customers
 
Seo Sm 2010 Presentation
Seo Sm 2010 PresentationSeo Sm 2010 Presentation
Seo Sm 2010 Presentation
 
2010 01 lecture SIG UM MFES 3 - Reverse engineering
2010 01 lecture SIG UM MFES 3 - Reverse engineering2010 01 lecture SIG UM MFES 3 - Reverse engineering
2010 01 lecture SIG UM MFES 3 - Reverse engineering
 
Mysql Datadictionary
Mysql DatadictionaryMysql Datadictionary
Mysql Datadictionary
 
MySQL進階介紹
MySQL進階介紹MySQL進階介紹
MySQL進階介紹
 
Sq lite
Sq liteSq lite
Sq lite
 
Databases for Beginners SQLite
Databases for Beginners SQLiteDatabases for Beginners SQLite
Databases for Beginners SQLite
 
SQLite3
SQLite3SQLite3
SQLite3
 
Sq lite presentation
Sq lite presentationSq lite presentation
Sq lite presentation
 
SQLite Techniques
SQLite TechniquesSQLite Techniques
SQLite Techniques
 
Getting Started with SQLite
Getting Started with SQLiteGetting Started with SQLite
Getting Started with SQLite
 
SQLite: Light, Open Source Relational Database Management System
SQLite: Light, Open Source Relational Database Management SystemSQLite: Light, Open Source Relational Database Management System
SQLite: Light, Open Source Relational Database Management System
 
SQLite - Overview
SQLite - OverviewSQLite - Overview
SQLite - Overview
 
SQLite 3
SQLite 3SQLite 3
SQLite 3
 
Sqlite
SqliteSqlite
Sqlite
 
Steganography presentation
Steganography presentationSteganography presentation
Steganography presentation
 
PPT steganography
PPT steganographyPPT steganography
PPT steganography
 

Similar a MySQLinsanity

MySQL 5.7 innodb_enhance_partii_20160527
MySQL 5.7 innodb_enhance_partii_20160527MySQL 5.7 innodb_enhance_partii_20160527
MySQL 5.7 innodb_enhance_partii_20160527Saewoong Lee
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 MinutesSveta Smirnova
 
16 MySQL Optimization #burningkeyboards
16 MySQL Optimization #burningkeyboards16 MySQL Optimization #burningkeyboards
16 MySQL Optimization #burningkeyboardsDenis Ristic
 
OSMC 2008 | Monitoring MySQL by Geert Vanderkelen
OSMC 2008 | Monitoring MySQL by Geert VanderkelenOSMC 2008 | Monitoring MySQL by Geert Vanderkelen
OSMC 2008 | Monitoring MySQL by Geert VanderkelenNETWAYS
 
Beginner guide to mysql command line
Beginner guide to mysql command lineBeginner guide to mysql command line
Beginner guide to mysql command linePriti Solanki
 
Memcached Functions For My Sql Seemless Caching In My Sql
Memcached Functions For My Sql Seemless Caching In My SqlMemcached Functions For My Sql Seemless Caching In My Sql
Memcached Functions For My Sql Seemless Caching In My SqlMySQLConference
 
HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)akirahiguchi
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)Valeriy Kravchuk
 
ProxySQL & PXC(Query routing and Failover Test)
ProxySQL & PXC(Query routing and Failover Test)ProxySQL & PXC(Query routing and Failover Test)
ProxySQL & PXC(Query routing and Failover Test)YoungHeon (Roy) Kim
 
MySQL Tokudb engine benchmark
MySQL Tokudb engine benchmarkMySQL Tokudb engine benchmark
MySQL Tokudb engine benchmarkLouis liu
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellEmily Ikuta
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 
Percona Live UK 2014 Part III
Percona Live UK 2014  Part IIIPercona Live UK 2014  Part III
Percona Live UK 2014 Part IIIAlkin Tezuysal
 
Drizzle to MySQL, Stress Free Migration
Drizzle to MySQL, Stress Free MigrationDrizzle to MySQL, Stress Free Migration
Drizzle to MySQL, Stress Free MigrationAndrew Hutchings
 
Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Philip Zhong
 
Undelete (and more) rows from the binary log
Undelete (and more) rows from the binary logUndelete (and more) rows from the binary log
Undelete (and more) rows from the binary logFrederic Descamps
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfzJoshua Thijssen
 
Deep Dive Spider Engine
Deep Dive Spider EngineDeep Dive Spider Engine
Deep Dive Spider EngineI Goo Lee
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingSveta Smirnova
 

Similar a MySQLinsanity (20)

MySQL 5.7 innodb_enhance_partii_20160527
MySQL 5.7 innodb_enhance_partii_20160527MySQL 5.7 innodb_enhance_partii_20160527
MySQL 5.7 innodb_enhance_partii_20160527
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 Minutes
 
16 MySQL Optimization #burningkeyboards
16 MySQL Optimization #burningkeyboards16 MySQL Optimization #burningkeyboards
16 MySQL Optimization #burningkeyboards
 
OSMC 2008 | Monitoring MySQL by Geert Vanderkelen
OSMC 2008 | Monitoring MySQL by Geert VanderkelenOSMC 2008 | Monitoring MySQL by Geert Vanderkelen
OSMC 2008 | Monitoring MySQL by Geert Vanderkelen
 
Beginner guide to mysql command line
Beginner guide to mysql command lineBeginner guide to mysql command line
Beginner guide to mysql command line
 
Memcached Functions For My Sql Seemless Caching In My Sql
Memcached Functions For My Sql Seemless Caching In My SqlMemcached Functions For My Sql Seemless Caching In My Sql
Memcached Functions For My Sql Seemless Caching In My Sql
 
HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
 
ProxySQL & PXC(Query routing and Failover Test)
ProxySQL & PXC(Query routing and Failover Test)ProxySQL & PXC(Query routing and Failover Test)
ProxySQL & PXC(Query routing and Failover Test)
 
MySQL Tokudb engine benchmark
MySQL Tokudb engine benchmarkMySQL Tokudb engine benchmark
MySQL Tokudb engine benchmark
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Percona Live UK 2014 Part III
Percona Live UK 2014  Part IIIPercona Live UK 2014  Part III
Percona Live UK 2014 Part III
 
Drizzle to MySQL, Stress Free Migration
Drizzle to MySQL, Stress Free MigrationDrizzle to MySQL, Stress Free Migration
Drizzle to MySQL, Stress Free Migration
 
Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8
 
Undelete (and more) rows from the binary log
Undelete (and more) rows from the binary logUndelete (and more) rows from the binary log
Undelete (and more) rows from the binary log
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
 
Deep Dive Spider Engine
Deep Dive Spider EngineDeep Dive Spider Engine
Deep Dive Spider Engine
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 

Último

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Último (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

MySQLinsanity

  • 2. Topic ▪ Who am I? ▪ MySQL performance tuning experience sharing. ▪ Q & A. 2
  • 3. Who am I? ▪ Stanley Huang (黃偉倫) ▪ My email ▪ wenlien1001@gmail.com ▪ My Blog ▪ http://stanley-huang.blogspot.com 3
  • 4. MySQL performance tuning experience sharing ▪ What happened to the product? ▪ Too many data and have query performance issue ▪ Performance tuning phases 1. SQL tuning ▪ Over 90%, bad SQLs make great impact on performance ▪ Over 90%, do not using the correct index(es) in bad SQLs 2. RDBMS tuning 4
  • 5. MySQL SQL tuning(1/2) ▪ Enable slow query log and find out the top 10 slow queries ▪ Add two settings in my.cnf ▪ log-slow-queries ## default off ▪ long-query-time=5 ## default 10 ▪ [data folder]/[host name]-slow.log 5
  • 6. MySQL SQL tuning(2/2) ▪ Perform full-text search on InnoDB (select … like ‘*pattern*’) 1. Change storage engine from InnoDB to MyISAM 2. Hybrid storage engine, create a new MyISAM table and move data need to be full-text search from InnoDB to MyISAM ▪ Too many indexes 1. Create more indexes won’t enhance performance but impact on writing. 2. (Suggestion) Don’t create more than 5 indexes on one table. InnoDB in MySQL 5.6 has supported full-text search 6
  • 7. Useful Tips For Networking System 1. IP Support 2. Mac Support 7
  • 8. IP address support  Build In Function: inet_ntoa()/inet_aton() mysql> CREATE TABLE testIP ( ip_int int unsigned DEFAULT NULL, ip_char char(15) DEFAULT NULL, index ip_int (ip_int), index ip_char (ip_char) ) ENGINE=InnoDB; mysql> insert into testIP valuse(inet_aton('216.18.50.126'),'216.18.50.126'); mysql> select inet_ntoa(ip_int),ip_char from testIP; +-------------------+---------------+ | inet_ntoa(ip_int) | ip_char | +-------------------+---------------+ | 216.18.50.126 | 216.18.50.126 | +-------------------+---------------+ 8
  • 9. Execution Plain mysql> explain select * from testIP where ip_char='216.18.50.126'; +----+-------------+--------+------+---------------+---------+---------+-------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------+------+---------------+---------+---------+-------+------+-------------+ | 1 | SIMPLE | testIP | ref | ip_char | ip_char | 16 | const | 1 | Using where | +----+-------------+--------+------+---------------+---------+---------+-------+------+-------------+ mysql> explain select * from testIP where ip_int=inet_aton('216.18.50.126'); +----+-------------+--------+------+---------------+--------+---------+-------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------+------+---------------+--------+---------+-------+------+-------------+ | 1 | SIMPLE | testIP | ref | ip_int | ip_int | 5 | const | 1 | Using where | +----+-------------+--------+------+---------------+--------+---------+-------+------+-------------+ 9
  • 10. Mac address support??  Build In Function: hex() mysql> create table testMAC(mac_bit bit(48), mac_char char(17), index(mac_bit), index(mac_char)); mysql> insert into testMAC values (x'00241DDC5548', '00:24:1D:DC:55:48'); mysql> select hex(mac_bit), mac_char from testMAC; +--------------+-------------------+ | hex(mac_bit) | mac_char | +--------------+-------------------+ | 241DDC5548 | 00:24:1D:DC:55:48 | +--------------+-------------------+ Build In Function seems not enough~ 1. create MySQL stored function 2. create UDF (User Define Function) 10
  • 11. Execution Plain mysql> explain select hex(mac_bit), mac_char from testMAC where mac_char='00:24:1D:DC:55:48'; +----+-------------+----------+------+---------------+----------+---------+-------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+----------+------+---------------+----------+---------+-------+------+-------------+ | 1 | SIMPLE | testMAC2 | ref | mac_char | mac_char | 18 | const | 1 | Using where | +----+-------------+----------+------+---------------+----------+---------+-------+------+-------------+ mysql> explain select hex(mac_bit), mac_char from testMAC where mac_bit=x'00241DDC5548'; +----+-------------+----------+------+---------------+---------+---------+-------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+----------+------+---------------+---------+---------+-------+------+-------------+ | 1 | SIMPLE | testMAC2 | ref | mac_bit | mac_bit | 7 | const | 1 | Using where | +----+-------------+----------+------+---------------+---------+---------+-------+------+-------------+ 11
  • 12. Stored Function for MAC address ## create stored function ether_atob(), from ascii to bit ## must define "deterministic", or explain will not use index delimiter // drop function if exists ether_atob// create function ether_atob(sAscii char(17)) returns bit(48) deterministic Begin declare bReturn bit(48); set bReturn=unhex(replace(sAscii,':','')); return bReturn; end// delimiter ; 12
  • 13. Stored Function for MAC address (cont.) ## create stored function ether_btoa(), from bit to ascii ## must define "deterministic", or explain will not use index delimiter // drop function if exists ether_btoa// create function ether_btoa(sBit bit(48)) returns char(17) deterministic begin declare sReturn char(17); set sReturn=lpad(hex(sBit),12,'0'); set sReturn=concat_ws(':', substr(sReturn,1,2), substr(sReturn,3,2), substr(sReturn,5,2), substr(sReturn,7,2), substr(sReturn,9,2), substr(sReturn,11,2)); return sReturn; end// delimiter ; 13
  • 14. Stored Function for MAC address (cont.) mysql> create table ether_table (b bit(48), a char(17), index(b), index(a)); Query OK, 0 rows affected (0.67 sec) mysql> insert into ether_table values (ether_atob('00:CD:EF:00:CD:EF'),'00:CD:EF:00:CD:EF'); Query OK, 1 row affected (0.01 sec) mysql> select ether_btoa(b), a from ether_table where b=ether_atob('00:CD:EF:00:CD:EF'); +----------------+-------------------+ | ether_btoa(b) | a | +----------------+-------------------+ | 00:CD:EF:00:CD:EF | 00:CD:EF:00:CD:EF | +----------------+-------------------+ 1 rows in set (0.01 sec ) 14
  • 15. Stored Function for MAC address (cont.) mysql> explain select ether_btoa(b), a from ether_table where b=ether_atob('00:CD:EF:00:CD:EF'); +----+-------------+-------------+------+---------------+------+---------+-------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------------+------+---------------+------+---------+-------+------+-------------+ | 1 | SIMPLE | ether_table | ref | b |b |7 | const | 1 | Using where | +----+-------------+-------------+------+---------------+------+---------+-------+------+-------------+ 1 row in set (0.00 sec) 15
  • 17. Using UDF on MySQL Database Make sure your MySQL supports UDF. mysql> create function lib_mysqludf_log_info returns string soname 'lib_mysqludf_log.so'; ERROR 1126 (HY000): Can't open shared library 'lib_mysqludf_log.so' (errno: 0 feature disabled) 17
  • 18. Compile MySQL with UDF enable 1. Download source code 2. # ./configure --with-mysqld-ldflags=--rdynamic 3. # gcc -shared -o ./udf_example.so ./udf_example.c - I/usr/local/include/mysql -fPIC 4. # cp ./udf_example.so /usr/local/mysql/lib/mysql/plugin 5. mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so'; ERROR 1126 (HY000): Can't open shared library 'udf_example.so' (errno: 22 /usr/local/lib/mysql/plugin/udf_example.so: cannot restore segment prot after reloc: Permission denied) 6. # chcon -t texrel_shlib_t /usr/local/lib/mysql/plugin/udf_example.so 18
  • 19. Characters of Stored Function, UDF and Native Function Method Speed Language Development Maintenance Stored slow SQL ~minutes easy Function (for small functions) UDF fast C ~hour hard Native fast C Major pain hard Function 19
  • 20. Compare with UDF and Stored Functions Reference: Roland Bouman's blog http://rpbouman.blogspot.com/2008/03/ udfs-at-mysql-users-conference.html 20
  • 21. MySQL performance tuning ▪ Separate disk I/O ▪ Separate disk I/O of bin log files and data files to different disks ▪ MyISAM configuration ▪ key_buffer_size=128M # default is 8M ▪ bulk_insert_buffer_size=4194304 # default is 8M ▪ InnoDB configuration ▪ innodb_buffer_pool_size=32M # default ▪ 8Minnodb_log_buffer_size=8M # default 1M ▪ Prevent large single large file of InnoDB tablespace ▪ innodb_file_per_table 21
  • 22. MySQL upgrade from 5.0 to 5.1 ▪ In internal tests, MySQL 5.1 demonstrates, on average, a 15% gain in total performance over MySQL 5.0. (There really is the free lunch) 22
  • 23. Partitioning Sample SQL mysql> CREATE TABLE test_partition_np -> ( c1 int default NULL, -> c2 varchar(30) default NULL, -> c3 date default NULL -> ) engine=InnoDB; Query OK, 0 rows affected (0.00 sec) 23
  • 24. What's wrong with “my” SQL mysql> select count(1) from test_partition_wp where year(c3)=1995; +----------+ | count(1) | +----------+ | 47358 | +----------+ 1 row in set (0.58 sec) mysql> select count(1) from test_partition_np where year(c3)=1995; +----------+ | count(1) | +----------+ | 47358 | +----------+ 1 row in set (0.53 sec) -- Faster then partition table, why?? 24
  • 25. Execution Plan mysql> explain partitions select count(1) from test_partition_wp where year(c3)=1995G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: test_partition_wp partitions: p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11 type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 12006556 Extra: Using where 1 row in set (0.00 sec) 25
  • 26. The correct SQL mysql> select count(1) from test_partition_wp where c3 between '1995/01/01' and '1995/12/31'; +----------+ | count(1) | +----------+ | 47358 | +----------+ 1 row in set (0.04 sec) -- That's what I want!! mysql> select count(1) from test_partition_np where c3 between '1995/01/01' and '1995/12/31'; +----------+ | count(1) | +----------+ | 47358 | +----------+ 1 row in set (0.62 sec) 26
  • 27. Execution Plan mysql> explain partitions select count(1) from test_partition_wp where c3 between '1995/01/01' and '1995/12/31'G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: test_partition_wp partitions: p1 type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 12006556 Extra: Using where 1 row in set (0.00 sec) 27
  • 28. Performance Enhancement With Table Partitioning After we use partition on the large tables, the performance raise 11-45% up. 1. 5.1-partition 377.4146 tableA 5.1 687.4756 tableA (687.4756-377.4146) / 687.4756 = 0.45 2. 5.1-partition 171.7333 tableB 5.1 193.9878 tableB (193.9878-171.7333) / 193.9878 = 0.11 3. 5.1-partition 22.0741 tableC 5.1 34.4792 tableC (34.4792-22.0741) / 34.4792 = 0.36 4. 5.1-partition 1.8519 tableD 5.1 3.3750 tableD (3.3750-1.8519) / 3.3750 = 0.45 28
  • 29. MySQL Performance Tips Summary ▪ Use EXPLAIN to profile the query. ▪ Always have slow query log. ▪ Avoid using wildcards at the start of LIKE queries. ▪ Isolate the workloads. ▪ Using data partitions.. ▪ Don’t duplicate indexes. ▪ Use INET_ATON and INET_NTOA. ▪ Hire a MySQL Certified DBA. http://forge.mysql.com/wiki/Top10SQLPerformanceTips 29
  • 30. Q&A 30