Swan(sea) Song – personal research during my six years at Swansea ... and bey...
MySQL 5.1 Features and Performance Improvements
1. MySQL 5.1 (and more)
What's new
Giuseppe Maxia
MySQL Community Team Lead
2. about me -Giuseppe Maxia
a.k.a. The Data Charmer
MySQL Community Team Lead
Long time hacking with MySQL features
Formerly, database consultant, designer, coder.
A passion for QA
An even greater passion for open source
... and community
Passionate blogger
http://datacharmer.blogspot.com
6. MySQL 5.1 features
Partitions performance
row-based replication stability
event scheduler ease of use
logs on demand ease of use
plugin interface extensibility
GENERAL PERFORMANCE performance
7. What exactly is this quot;partitionsquot; thing?
Logical splitting of tables
Transparent to user
8. Remember the MERGE tables?
MERGE TABLE separate tables
risk of duplicates
insert in each table
no constraints
9. It isn't a merge table!
PARTITIONED TABLE One table
No risk of duplicates
insert in one table
constraints enforced
10. Partition pruning
1a - unpartitioned table - SINGLE RECORD
select *
from
table_name
where colx =
120
11. Partition pruning
1b - unpartitioned table - SINGLE RECORD
select *
from
table_name
where colx =
350
12. Partition pruning
1c - unpartitioned table - RANGE
select *
from
table_name
where colx
between 120
and 230
13. Partition pruning
2a - table partitioned by colx - SINGLE REC
1-99
100-199
select *
from
200-299 table_name
where colx =
300-399 120
400-499
500-599
14. Partition pruning
2b - table partitioned by colx - SINGLE REC
1-99
100-199
select *
from
200-299 table_name
where colx =
300-399 350
400-499
500-599
15. Partition pruning
2c - table partitioned by colx - RANGE
1-99
select *
100-199 from
table_name
200-299
where colx
300-399 between 120
and 230
400-499
500-599
16. Partition pruning
EXPLAIN
select *
before from table_name
where colx = 120
EXPLAIN PARTITIONS
in 5.1 select *
from table_name
where colx = 120
22. HOW TO MAKE PARTITIONS
RTFM ...
No, seriously, the manual has everything
23. HOW TO MAKE PARTITIONS
RTFM ...
No, seriously, the manual has everything
But if you absolutely insist ...
24. HOW TO MAKE PARTITIONS
CREATE TABLE t1 (
id int
) ENGINE=InnoDB
# or MyISAM, ARCHIVE
PARTITION BY RANGE (id)
(
PARTITION P1 VALUES LESS THAN (10),
PARTITION P2 VALUES LESS THAN (20)
)
20
25. HOW TO MAKE PARTITIONS
CREATE 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
26. HOW TO MAKE PARTITIONS
CREATE TABLE t1 (
id int not null primary key
) ENGINE=InnoDB
PARTITION BY HASH (id)
PARTITIONS 10;
22
27. HOW TO MAKE PARTITIONS
CREATE TABLE t1 (
id int not null primary key
) ENGINE=InnoDB
PARTITION BY KEY ()
PARTITIONS 10;
23
28. 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
29. Benchmarking partitions
Compare results
Unpartitioned vs partitioned
ISOLATION
Repeatability
Check your resources!
30. Partitions with InnoDB (laptop)
Key points:
Takes much more storage than other engines
engine storage
(MB)
innodb 221
myisam 181
archive 74
innodb partitioned (whole) 289
innodb partitioned (file per table) 676
myisam partitioned 182
archive partitioned 72
32. Partitions with InnoDB (huge server)
Key points:
Takes much more storage than other engines
engine storage
(GB)
innodb (with PK) 330
myisam (with PK) 141
archive 13
innodb partitioned (no PK) 237
myisam partitioned (no PK) 107
archive partitioned 13
33. Benchmarking results (huge server)
engine 6 month range
InnoDB 4 min 30s
MyISAM 25.03s
Archive 22 min 25s
InnoDB partitioned by month 13.19
MyISAM partitioned by year 6.31
MyISAM partitioned by month 4.45
Archive partitioned by year 16.67
Archive partitioned by month 8.97
34. 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
35. How does it work?
event scheduler
thread
MySQL Server
event
time?
start
regular thread
regular thread
regular thread
regular thread
regular thread
event thread
36. Why using the event scheduler?
Cross platform scheduler
No external applications needed
No overhead
37. How to use the event scheduler
1. Enable the event scheduler
A. in the option file
• event-scheduler=1
B. online
• SET GLOBAL event_scheduler=ON;
2. Create an event
3. Check the effects
38. Event creation syntax
CREATE EVENT event_name
ON SCHEDULE
AT {DATE AND TIME}
DO
{SQL COMMAND};
CREATE EVENT event_name
ON SCHEDULE
EVERY {X}
{SECOND|MINUTE|HOUR|DAY|MONTH|YEAR|WEEK}
DO
{SQL COMMAND};
40. Creating an event at a given time
CREATE EVENT event_name
ON SCHEDULE AT '2009-04-21 15:55:00'
DO
INSERT INTO some_table VALUES
('gotcha', now());
CREATE EVENT event_name
ON SCHEDULE AT now() + interval 20 minute
DO
CALL smart_procedure()
41. Creating a recurring event
CREATE EVENT event_name
ON SCHEDULE EVERY 20 MINUTE
DO
INSERT INTO some_table VALUES
('gotcha', now());
CREATE EVENT event_name
ON SCHEDULE every 7 DAY
DO
CALL smart_procedure()
42. Creating a recurring event
CREATE EVENT event_name
ON SCHEDULE EVERY 10 MINUTE
STARTS NOW() + INTERVAL 2 HOUR
ENDS NOW() + INTERVAL 4 HOUR
DO
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
43. MySQL 5.1 and 5.4
in practice
Giuseppe Maxia
MySQL Community Team Lead