I decided to run some very basic performance test comparing the non-partitioned table with a primary key, and a partitioned table with a primary key and a unique constraint enforced via a secondary table explained in my previous post.Overall, it appears that with partitioning, as the data/rows scale, the inserts actually get faster :) This is what I would expect theoretically, so score one for
Lately, I've been trying to keep up with at least one of the MySQL Forums: Partitioning.It's a great way to keep on top of issues surrounding partitioning, and also get an idea of what people are trying to do with the new 5.1 feature. Richard came up with an interesting problem that I jumped into only to realize that I hadn't done my homework, and my initial suggestion wouldn't work at all due
As a follow up to the series of posts I've been making, I wanted to post what I ended up with. Thanks to everyone who posted comments, your help was extremely useful. To recap, I have a working pair of events to add and remove partitions to this table:
create table log ( logged datetime not null, id int not null auto_increment, text varchar(256), PRIMARY KEY ( logged, id ) ) PARTITION BY RANGE( TO_DAYS( logged ) ) ( PARTITION p20080206 VALUES LESS THAN (733444), PARTITION p20080207 VALUES LESS THAN (733445), PARTITION p20080208 VALUES LESS THAN (733446)
As a follow up to the series of posts I've been making, I wanted to post what I ended up with. Thanks to everyone who posted comments, your help was extremely useful. To recap, I have a working pair of events to add and remove partitions to this table:
create table log ( logged datetime not null, id int not null auto_increment, text varchar(256), PRIMARY KEY ( logged, id ) ) PARTITION BY RANGE( TO_DAYS( logged ) ) ( PARTITION p20080206 VALUES LESS THAN (733444), PARTITION p20080207 VALUES LESS THAN (733445), PARTITION p20080208 VALUES LESS THAN (733446)
Thanks all for the help on getting my log_addpartition event
running, dynamic SQL was just the ticket.
I'm now focusing on writing the sister event:
'log_removepartition', which will find and purge partitions older
than some time interval. The information schema comes in quite
handy here, as I can query the PARTITIONS table to see all
partitions.
I want to create a log table in 5.1 that is partitioned by day. I want to roll-off old data and create new partitions for each day automatically. Without writing a script and a cronjob, it seems like this should be possible with Events. Let's start with the table:
create table log ( logged datetime not null, id int not null auto_increment, text varchar(256), PRIMARY KEY ( logged, id ) ) PARTITION BY RANGE( TO_DAYS( logged ) ) ( PARTITION p20080206 VALUES LESS THAN (733444), PARTITION p20080207 VALUES LESS THAN (733445), PARTITION p20080208 VALUES LESS THAN (733446) );
This seems pretty straight-forward: I take my log entry time and convert it TO_DAYS and partition on that. I have tomorrow's partition all ready to go, just in case I don't get around to adding it today. Let's create an Event to do add tomorrow's partition for us automatically each day:
…
[Read more]Over the past four articles I've demonstrated cases where a denormalized data model is faster than a normalized one, but often not by that much, and a case where a normalized data model was a bit faster than a denormalized one. My general conclusion was with today's optimizers one should target a normalized data model and then denormalize where it makes sense, even for reporting. I'm not as much of a fan of the star schema, a heavily denormalized data model popularized by Ralph Kimball, as I used to be. Star schemas are costly to build and maintain and the the time spent creating them can often be spent better on more productive optimizations, such as the creation of summary tables and better indexing. I'm not saying the denormalization doesn't make sense in some cases, just that it doesn't make sense in all cases.
Time on move on to the topic of this article, partitioning.
There are many good …
[Read more]
Some of the bloggers on Planet MySQL are sharing their proposals for
the upcoming 2008 MySQL Conference & Expo. Hereby, I follow
their example and give you mine.
The first proposal I submitted is on PHPUnit and will
showcase Michael Lively
Jr.'s port of DbUnit:
Testing PHP/MySQL Applications with PHPUnit/DbUnit
In the last decade, PHP has developed from a niche language for
adding dynamic functionality to small websites to a powerful tool
making strong inroads into large-scale Web systems. Critical …
A customer issue has drawn my attention to this this pecularity: if partitioning is done by the value of some function, then partition pruning module will make use of comparisons of the partitioning column(s), but not of comparisons of the value of the partitioning function. Here is an example:
CREATE TABLE t1 ( recdate DATETIME NOT NULL, ... ) PARTITION BY RANGE( TO_DAYS(recdate) ) ( PARTITION p0 VALUES LESS THAN ( TO_DAYS('2007-01-01') ), PARTITION p1 VALUES LESS THAN ( TO_DAYS('2007-02-01') ), ... );
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE recdate='2007-01-15'; +----+-------------+-------+------------+------+-... | id | select_type | table | partitions | type | +----+-------------+-------+------------+------+-... | 1 | SIMPLE | t1 | p1 | ALL | +----+-------------+-------+------------+------+-... EXPLAIN PARTITIONS SELECT * FROM t1 WHERE TO_DAYS(recdate)=TO_DAYS('2007-01-15'); …[Read more]
When MySQL first came out and started popping up all over the web in the e-commerce arena, if you were like me you looked at it as a wannabe. 'Call me in a few years when you grow up'. Yea, sometimes the Oracle in us goes to our heads a little to fast...MySQL has really gone mainstream in the last few years. Companies that never would have considered MySQL in the past for critical database