MySQL 5.1 and beyond

Post on 13-Dec-2014

3.502 views 1 download

description

MySQL 5.1 adds new features and more performance. And MySQL 5.4 is even faster. Some theory and practical tests

Transcript of MySQL 5.1 and beyond

MySQL 5.1 (and more)What's new

Giuseppe Maxia

MySQL Community Team Lead

MySQL 5.1 GA

MySQL 5.1 GA

MySQL 5.1 GA

MySQL 5.1 featuresPartitions performance

row-based replication stability

event scheduler ease of use

logs on demand ease of use

plugin interface extensibility

GENERAL PERFORMANCE performance

What exactly is this "partitions" thing? Logical splitting of tables Transparent to user

Remember the MERGE tables? separate tables risk of duplicates insert in each table no constraints

MERGE TABLE

It isn't a merge table! One table No risk of duplicates insert in one table constraints enforced

PARTITIONED TABLE

Partition pruning 1a - unpartitioned table - SINGLE RECORD

select * from table_name where colx = 120

Partition pruning 1b - unpartitioned table - SINGLE RECORD

select * from table_name where colx = 350

Partition pruning 1c - unpartitioned table - RANGE

select * from table_name where colx between 120 and 230

Partition pruning 2a - table partitioned by colx - SINGLE REC

select * from table_name where colx = 120

100-199

1-99

200-299

300-399

400-499

500-599

Partition pruning 2b - table partitioned by colx - SINGLE REC

select * from table_name where colx = 350

100-199

1-99

200-299

300-399

400-499

500-599

Partition pruning 2c - table partitioned by colx - RANGE

100-199

1-99

200-299

300-399

400-499

500-599

select * from table_name where colx between 120 and 230

Partition pruning

EXPLAINselect * from table_name where colx = 120

EXPLAIN PARTITIONSselect * from table_name where colx = 120

in 5.1

before

Partition pruning - unpartitioned tableexplain partitions select count(*) from table_name where colx=120\G***** 1. row **** id: 1 select_type: SIMPLE table: table_name partitions: p01,p02,p03,p04,p05,p06,p07,p08,p09,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19 type: index...

Partition pruning - unpartitioned tableexplain partitions select count(*) from table_name where colx between 120 and 230\G***** 1. row **** id: 1 select_type: SIMPLE table: table_name partitions: p01,p02,p03,p04,p05,p06,p07,p08,p09,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19 type: index...

Partition pruning - table partitioned by colxexplain partitions select count(*) from table_name where colx between 120 and 230\G***** 1. row **** id: 1 select_type: SIMPLE table: table_name partitions: p02,p03 type: index...

HOW TO MAKE PARTITIONS

HOW TO MAKE PARTITIONS

RTFM ...

HOW TO MAKE PARTITIONS

RTFM ... No, seriously, the manual has everything

HOW TO MAKE PARTITIONS

RTFM ... No, seriously, the manual has everything But if you absolutely insist ...

HOW TO MAKE PARTITIONSCREATE TABLE t1 ( id int ) ENGINE=InnoDB # or MyISAM, ARCHIVEPARTITION BY RANGE (id)( PARTITION P1 VALUES LESS THAN (10), PARTITION P2 VALUES LESS THAN (20))

20

HOW TO MAKE PARTITIONSCREATE TABLE t1 ( id int ) ENGINE=InnoDB PARTITION BY LIST (id)( PARTITION P1 VALUES IN (1,2,4), PARTITION P2 VALUES IN (3,5,9))

21

HOW TO MAKE PARTITIONSCREATE TABLE t1 ( id int not null primary key) ENGINE=InnoDB PARTITION BY HASH (id)PARTITIONS 10;

22

HOW TO MAKE PARTITIONSCREATE TABLE t1 ( id int not null primary key) ENGINE=InnoDB PARTITION BY KEY ()PARTITIONS 10;

23

Limitations• Can partition only by INTEGER columns• OR you can partition by an expression, which must

return an integer• Maximum 1024 partitions

• If you have a Unique Key or PK, the partition column must be part of that key

• No Foreign Key support• No Fulltext or GIS support

24

Benchmarking partitions Compare results Unpartitioned vs partitioned ISOLATION Repeatability Check your resources!

Partitions with InnoDB (laptop) Key points: Takes much more storage than other engines

engine storage (MB)

innodb 221myisam 181archive 74innodb partitioned (whole) 289innodb partitioned (file per table) 676myisam partitioned 182archive partitioned 72

Benchmarking results (laptop)engine query year

2000query year 2002

InnoDB 1.25 1.25

MyISAM 1.72 1.73

Archive 2.47 2.45

InnoDB partitioned whole

0.24 0.10

InnoDB Partitioned (file per table)

0.45 0.10

MyISAM partitioned 0.18 0.12

Archive partitioned 0.22 0.12

Partitions with InnoDB (huge server) Key points: Takes much more storage than other engines

engine storage (GB)

innodb (with PK) 330myisam (with PK) 141archive 13innodb partitioned (no PK) 237myisam partitioned (no PK) 107archive partitioned 13

Benchmarking results (huge server)engine 6 month rangeInnoDB 4 min 30sMyISAM 25.03sArchive 22 min 25sInnoDB partitioned by month 13.19MyISAM partitioned by year 6.31MyISAM partitioned by month 4.45Archive partitioned by year 16.67Archive partitioned by month 8.97

What is the event scheduler Temporal triggers NOT related to a specific table Execute SQL code

at a given time or at given intervals

Created by Andrey Hristov First released with MySQL 5.1

How does it work?

MySQL Server

event scheduler thread

regular threadregular threadregular threadregular threadregular thread

event time?

event thread

start

Why using the event scheduler? Cross platform scheduler No external applications needed No overhead

How to use the event scheduler1. Enable the event scheduler

A. in the option file• event-scheduler=1B. online • SET GLOBAL event_scheduler=ON;

2. Create an event3. Check the effects

Event creation syntaxCREATE EVENT event_nameON SCHEDULE AT {DATE AND TIME}DO {SQL COMMAND};

CREATE EVENT event_nameON SCHEDULE EVERY {X} {SECOND|MINUTE|HOUR|DAY|MONTH|YEAR|WEEK}DO {SQL COMMAND};

Event creation syntaxCREATE EVENT event_nameON SCHEDULE {schedule clause}

[ON COMPLETION [NOT] PRESERVE][STARTS {DATE TIME}][ENDS {DATE TIME} ][ENABLE|DISABLE]

DO {SQL COMMAND};

Creating an event at a given timeCREATE EVENT event_nameON SCHEDULE AT '2009-04-21 15:55:00'DO INSERT INTO some_table VALUES ('gotcha', now());

CREATE EVENT event_nameON SCHEDULE AT now() + interval 20 minuteDOCALL smart_procedure()

Creating a recurring eventCREATE EVENT event_nameON SCHEDULE EVERY 20 MINUTEDO INSERT INTO some_table VALUES ('gotcha', now());

CREATE EVENT event_nameON SCHEDULE every 7 DAYDOCALL smart_procedure()

Creating a recurring eventCREATE EVENT event_nameON SCHEDULE EVERY 10 MINUTESTARTS NOW() + INTERVAL 2 HOURENDS NOW() + INTERVAL 4 HOURDO CALL some_procedure();

# creates an event that runs every# 10 minutes, but does not start now.# It will start in 2 hours# and end two hours later

MySQL 5.1 and 5.4in practice

Giuseppe Maxia

MySQL Community Team Lead

5.4 ?This release is very special for

two reasons

Tight team work

1MySQL architects, top MySQL coders, Sun

performance engineers, all worked together to

create this release

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

How to improve performancemethod efficacy difficulty

Schema optimization ***** #####Server tuning ** #### Query tuning *** ####Hardware upgrade *** # Replication ** #####Partitioning ***** #####Server Upgrade (5.4) ***** #

2

5.4 = 5.1 +

performance patches

Practical experience

sysbench preparetime sysbench \ --test=oltp \ --oltp-table-size=1000000 \ --mysql-db=test \ --mysql-user=msandbox \ --mysql-password=msandbox \ --mysql-host=127.0.0.1 \ --mysql-port=$PORT \ --num-threads=8 prepare

sysbench r/osysbench \ --test=oltp \ --oltp-table-size=1000000 \ --mysql-db=test \ --mysql-user=msandbox \ --mysql-password=msandbox \ --mysql-host=127.0.0.1 \ --mysql-port=$PORT \ --max-time=60 \ --oltp-read-only=on \ --max-requests=0 \ --num-threads=8 run

sysbench r/wsysbench \ --test=oltp \ --oltp-table-size=1000000 \ --mysql-db=test \ --mysql-user=msandbox \ --mysql-password=msandbox \ --mysql-host=127.0.0.1 \ --mysql-port=$PORT \ --max-time=60 \ --oltp-read-only=off \ --max-requests=0 \ --num-threads=8 run

sysbench resultsMySQL 5.0 read-only

sysbench resultsMySQL 5.1 read-only

sysbench resultsMySQL 5.0 R/W

sysbench resultsMySQL 5.1 R/W

sysbench resultsMySQL 5.4 R/O

sysbench resultsMySQL 5.4 R/W

sysbench results graphMySQL 5.0 read-only

sysbench results graphMySQL 5.1 R/O

sysbench results graph - read only

5.0

5.1

sysbench results graphMySQL 5.0 R/W

sysbench results graphMySQL 5.1 R/W

sysbench results graph - R/W

5.0

5.1

sysbench results graphMySQL 5.4 R/O

sysbench results graph - read only

5.0

5.1/5.4

sysbench results graph - read only

sysbench results graphMySQL 5.4 R/W

sysbench results graph - R/W

5.0

5.1/5.4

sysbench results graph - R/W

QUESTIONS?

Slides in my bloghttp://datacharmer.blogspot.com

THANKS