MySQL partitioning performance
-
Upload
tommy-dot -
Category
Technology
-
view
248 -
download
3
Transcript of MySQL partitioning performance
![Page 1: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/1.jpg)
March 19, 2009Giuseppe MaxiaMySQL Community Team LeadSun Microsystems
Boost performance with MySQL 5.1 partitions
![Page 2: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/2.jpg)
Who's this guy?
about me2
![Page 3: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/3.jpg)
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 3
![Page 4: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/4.jpg)
MySQL 5.1 GA
4
![Page 5: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/5.jpg)
MySQL 5.1 GA
5
![Page 6: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/6.jpg)
MySQL 5.1 GA
5
![Page 7: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/7.jpg)
Defining the problem
YOURNEEDS
6
![Page 8: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/8.jpg)
The problem(s)• Too much data• Not enough RAM• Historical data• Growing data• Rotating data
7
![Page 9: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/9.jpg)
Too much data
8
data
![Page 10: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/10.jpg)
Not enough RAM
9
data
RAM
INDEXESINDEXES
![Page 11: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/11.jpg)
Not enough RAM
10
dataRAMINDEXES
INDEXES
![Page 12: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/12.jpg)
MySQL 5.1 partitions
WHAT11
![Page 13: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/13.jpg)
What is it?• Logical splitting of tables• Transparent to user
12
![Page 14: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/14.jpg)
Logical splitting• No need to create separate tables• No need to move chunks of data across files
13
![Page 15: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/15.jpg)
MySQL 5.1 partitions
TRANSPARENT
14
SQL
![Page 16: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/16.jpg)
MERGE TABLE
COMPARED TO MERGE TABLES
15
• separate tables• risk of duplicates• insert in each table• no constraints
![Page 17: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/17.jpg)
PARTITIONED TABLE
COMPARED TO MERGE TABLES
16
• One table• No risk of duplicates• insert in one table• constraints enforced
![Page 18: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/18.jpg)
Wait a minute ...• WHAT THE HELL DOES "LOGICAL SPLIT"
REALLY MEANS?• LET ME EXPLAIN ...
17
![Page 19: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/19.jpg)
Physical partitioning (1)• Take a map
18
![Page 20: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/20.jpg)
Physical partitioning (2)• cut it into pieces
19
![Page 21: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/21.jpg)
Physical partitioning (3)• What you have, is several different pieces
20
![Page 22: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/22.jpg)
Physical partitioning (4)• If you want the map back, you need some
application (adhesive tape) and you may get it wrong
21
![Page 23: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/23.jpg)
Logical partitioning (1)• Take a map
22
![Page 24: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/24.jpg)
Logical partitioning (2)• fold it to show the piece you need
23
![Page 25: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/25.jpg)
Logical partitioning (3)• what you have is still a map, even if you see only
one part.
24
![Page 26: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/26.jpg)
Logical partitioning (4)• if you unfold the map, you still have the whole thing
25
![Page 27: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/27.jpg)
What partitions can do• logical split• but you can also split the data physically• granular partition (subpartitioning)• different methods (range, list, hash, key)
26
![Page 28: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/28.jpg)
MySQL 5.1 partitions
WHY27
![Page 29: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/29.jpg)
4 main reasons to use partitions• To make single inserts and selects faster• To make range selects faster• To help split the data across different paths• To store historical data efficiently• If you need to delete large chunks of data
INSTANTLY
28
![Page 30: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/30.jpg)
MySQL 5.1 partitions
HOW29
![Page 31: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/31.jpg)
HOW TO MAKE PARTITIONS
30
![Page 32: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/32.jpg)
HOW TO MAKE PARTITIONS
•RTFM ...
30
![Page 33: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/33.jpg)
HOW TO MAKE PARTITIONS
•RTFM ...• No, seriously, the manual has everything
30
![Page 34: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/34.jpg)
HOW TO MAKE PARTITIONS
•RTFM ...• No, seriously, the manual has everything• But if you absolutely insist ...
30
![Page 35: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/35.jpg)
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)) 31
![Page 36: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/36.jpg)
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))
32
![Page 37: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/37.jpg)
HOW TO MAKE PARTITIONSCREATE TABLE t1 ( id int not null primary key) ENGINE=InnoDB PARTITION BY HASH (id)PARTITIONS 10;
33
![Page 38: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/38.jpg)
HOW TO MAKE PARTITIONSCREATE TABLE t1 ( id int not null primary key) ENGINE=InnoDB PARTITION BY KEY ()PARTITIONS 10;
34
![Page 39: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/39.jpg)
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
35
![Page 40: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/40.jpg)
PARTITIONING BY DATECREATE TABLE t1 ( d date) ENGINE=InnoDB PARTITION BY RANGE (year(d))( PARTITION P1 VALUES LESS THAN (1999), PARTITION P2 VALUES LESS THAN (2000))
36
![Page 41: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/41.jpg)
PARTITIONING BY DATECREATE TABLE t1 ( d date) ENGINE=InnoDB PARTITION BY RANGE (to_days(d))( PARTITION P1 VALUES LESS THAN (to_days('1999-01-01')), PARTITION P2 VALUES LESS THAN (to_days('2000-01-01')))
37
![Page 42: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/42.jpg)
MySQL 5.1 partitions
WHEN38
![Page 43: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/43.jpg)
When to use partitions?• if you have large tables• if you know that you will always query for the
partitioning column• if you have historical tables that you want to purge
quickly• if your indexes are larger than the available RAM
39
![Page 44: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/44.jpg)
MySQL 5.1 partitions
HANDS ON
40
![Page 45: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/45.jpg)
components used for testing
41
![Page 46: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/46.jpg)
components used for testing• MySQL Sandbox
> created MySQL instances in seconds> http://launchpad.net/mysql-sandbox
41
![Page 47: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/47.jpg)
components used for testing• MySQL Sandbox
> created MySQL instances in seconds> http://launchpad.net/mysql-sandbox
• MySQL Employees Test Database> has ~ 4 mil records in 6 tables> http://launchpad.net/test-db
41
![Page 48: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/48.jpg)
components used for testing• MySQL Sandbox
> created MySQL instances in seconds> http://launchpad.net/mysql-sandbox
• MySQL Employees Test Database> has ~ 4 mil records in 6 tables> http://launchpad.net/test-db
• Command line ability> fingers> ingenuity
41
![Page 49: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/49.jpg)
42
employees test database
![Page 50: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/50.jpg)
How many partitionsfrom information_schema.partitions +-------+-----------------+----------+| pname | expr | descr | +-------+-----------------+----------+| p01 | year(from_date) | 1985 | | p02 | year(from_date) | 1986 |
... | p13 | year(from_date) | 1997 | | p14 | year(from_date) | 1998 | | p15 | year(from_date) | 1999 | | p16 | year(from_date) | 2000 | ...| p19 | year(from_date) | MAXVALUE | +-------+-----------------+----------+
43
![Page 51: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/51.jpg)
How many recordsselect count(*) from salaries; +----------+ | count(*) | +----------+ | 2844047 | +----------+1 row in set (0.01 sec)
44
![Page 52: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/52.jpg)
How many records in 1998 not partitionedselect count(*) from salaries where from_date between '1998-01-01' and '1998-12-31';+----------+| count(*) |+----------+| 247489 | +----------+1 row in set (1.52 sec)
# NOT PARTITIONED 45
![Page 53: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/53.jpg)
How many records in 1998PARTITIONEDselect count(*) from salaries where from_date between '1998-01-01' and '1998-12-31';+----------+| count(*) |+----------+| 247489 | +----------+1 row in set (0.41 sec)
# partition p1546
![Page 54: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/54.jpg)
How many records in 1999not partitionedselect count(*) from salaries where from_date between '1999-01-01' and '1999-12-31';+----------+| count(*) |+----------+| 260957 |+----------+1 row in set (1.54 sec)
# NOT PARTITIONED47
![Page 55: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/55.jpg)
How many records in 1999PARTITIONEDselect count(*) from salaries where from_date between '1999-01-01' and '1999-12-31';+----------+| count(*) |+----------+| 260957 |+----------+1 row in set (0.17 sec)
# partition p1648
![Page 56: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/56.jpg)
Deleting 1998 records not partitioneddelete from salaries where from_date between '1998-01-01' and '1998-12-31';Query OK, 247489 rows affected (19.13 sec)
# NOT PARTITIONED
49
![Page 57: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/57.jpg)
Deleting 1998 records partitionedalter table salaries drop partition p15;Query OK, 0 rows affected (1.35 sec)
50
![Page 58: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/58.jpg)
MySQL 5.1 partitions
LEVERAGINGREPLICATION
51
![Page 59: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/59.jpg)
Replication schemes
52
SLAVESLAVE
MASTER
INNODBNOTPARTITIONED
INNODBPARTITIONEDBY RANGE
MyISAMPARTITIONEDBY RANGE
concurrent insert
concurrent batch processing large batch processing
SLAVE
INNODBNOTPARTITIONED
concurrent read
![Page 60: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/60.jpg)
Replication schemes
53
SLAVESLAVE
MASTER
INNODBPARTITIONED
MyISAMPARTITIONED
INNODBNONPARTITIONED
concurrent insert
concurrent readsbatch processing
![Page 61: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/61.jpg)
MySQL 5.1 partitions
PITFALLS54
![Page 62: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/62.jpg)
Expressions• Partition by function• Search by column
55
![Page 63: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/63.jpg)
WRONG
56
PARTITION BY RANGE(year(from_date))
select count(*) from salaries where year(from_date) = 1998;+----------+| count(*) |+----------+| 247489 | +----------+1 row in set (2.25 sec)
![Page 64: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/64.jpg)
RIGHT
57
PARTITION BY RANGE(year(from_date))
select count(*) from salaries where from_date between '1998-01-01' and '1998-12-31';+----------+| count(*) |+----------+| 247489 | +----------+1 row in set (0.46 sec)
![Page 65: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/65.jpg)
EXPLAIN
58
explain partitions select count(*) from salaries where year(from_date) = 1998\G***** 1. row **** id: 1 select_type: SIMPLE table: salaries partitions: p01,p02,p03,p04,p05,p06,p07,p08,p09,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19 type: index...
![Page 66: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/66.jpg)
EXPLAIN
59
explain partitions select count(*) from salaries where from_date between '1998-01-01' and '1998-12-31'\G***** 1. row **** id: 1 select_type: SIMPLE table: salaries partitions: p14,p15...
![Page 67: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/67.jpg)
MySQL 5.1 partitions
BENCHMARKS
60
![Page 68: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/68.jpg)
Partitions benchmarks (laptop)
engine storage (MB)
innodb 221myisam 181archive 74innodb partitioned (whole) 289innodb partitioned (file per table) 676myisam partitioned 182archive partitioned 72
![Page 69: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/69.jpg)
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
![Page 70: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/70.jpg)
Partitioning storage (huge server)
engine storage (GB)
innodb (with PK) 330myisam (with PK) 141archive 13innodb partitioned (no PK) 237myisam partitioned (no PK) 107archive partitioned 13
![Page 71: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/71.jpg)
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
![Page 72: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/72.jpg)
MySQL 5.1 partitions
TOOLS65
![Page 73: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/73.jpg)
The partition helper• The INFORMATION_SCHEMA.PARTITIONS table• The partition helper
> http://datacharmer.blogspot.com/2008/12/partition-helper-improving-usability.html
> A Perl script that creates partitioning statements
• ... anything you are creating right now :)
66
![Page 74: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/74.jpg)
MySQL 5.1 partitions
TIPS67
![Page 75: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/75.jpg)
TIPS• For large table ( indexes > available RAM)
> DO NOT USE INDEXES> PARTITIONS ARE MORE EFFICIENT
68
![Page 76: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/76.jpg)
TIPS• Before adopting partitions in production, benchmark!• you can create partitions of different sizes
> in historical tables, you can partition – current data by day– recent data by month– distant past data by year
> ALL IN THE SAME TABLE!• If you want to enforce a constraint on a integer
column, you may set a partition by list, with only the values you want to admit.
69
![Page 77: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/77.jpg)
TIPS• For large historical tables, consider using ARCHIVE
+ partitions> You see benefits for very large amounts of data ( > 500
MB)> Very effective when you run statistics> Almost the same performance of MyISAM> but 1/10 of storage
70
![Page 79: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/79.jpg)
MySQL 5.1 partitions
BONUS SLIDES
72
![Page 80: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/80.jpg)
MySQL 5.1 partitions
ANNOYANCES73
![Page 81: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/81.jpg)
Annoyances with partitions
74
• CREATE TABLE STATEMENT hard to read
![Page 82: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/82.jpg)
Annoyances with partitions
74
• CREATE TABLE STATEMENT hard to read
![Page 83: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/83.jpg)
Annoyances with partitions• hard to read (FIXED!! in 5.1.31)
75
![Page 84: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/84.jpg)
Annoyances with partitions• hard to read (FIXED!! in 5.1.31)
75
![Page 85: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/85.jpg)
Annoyances with partitions• CREATE TABLE only keeps the result of the
expression for each partition.• (you can use the information_schema to ease the
pain in this case)
76
![Page 86: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/86.jpg)
Annoyances with partitions
77
CREATE TABLE t1 ( d date) ENGINE=InnoDB PARTITION BY RANGE (to_days(d))( PARTITION P1 VALUES LESS THAN (to_days('1999-01-01')), PARTITION P2 VALUES LESS THAN (to_days('2000-01-01')))
![Page 87: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/87.jpg)
Annoyances with partitions
78
CREATE TABLE `t1` ( `d` date DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1/*!50100 PARTITION BY RANGE (to_days(d))(PARTITION P1 VALUES LESS THAN (730120) ENGINE = InnoDB, PARTITION P2 VALUES LESS THAN (730485) ENGINE = InnoDB) */
![Page 88: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/88.jpg)
Fixing annoyances with partitions
79
select partition_name part, partition_expression expr, partition_description val from information_schema.partitions where table_name='t1';+------+------------+--------+| part | expr | val |+------+------------+--------+| P1 | to_days(d) | 730120 | | P2 | to_days(d) | 730485 | +------+------------+--------+
![Page 89: MySQL partitioning performance](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a4e6201a28ab4b748b476d/html5/thumbnails/89.jpg)
fixing annoyances with partitions
80
select partition_name part , partition_expression expr, from_days(partition_description) val from information_schema.partitions where table_name='t1';+------+------------+------------+| part | expr | val |+------+------------+------------+| P1 | to_days(d) | 1999-01-01 | | P2 | to_days(d) | 2000-01-01 | +------+------------+------------+