What is MYSQL Partitioning?

Viewed 23751

I have read the documentation (http://dev.mysql.com/doc/refman/5.1/en/partitioning.html), but I would like, in your own words, what it is and why it is used.

  1. Is it mainly used for multiple servers so it doesn't drag down one server?
  2. So, part of the data will be on server1, and part of the data will be on server2. And server 3 will "point" to server1 or server2...is that how it works?
  3. Why does MYSQL documentation focus on partitioning within the same server...if the purpose is to spread it across servers?
3 Answers

A partitioned table is a single logical table that’s composed of multiple physical subtables. The partitioning code is really just a wrapper around a set of Handler objects that represent the underlying partitions, and it forwards requests to the storage engine through the Handler objects. Partitioning is a kind of black box that hides the underlying partitions from you at the SQL layer, although you can see them quite easily by looking at the filesystem, where you’ll see the component tables with a hash-delimited naming convention.

For example, here’s a simple way to place each year’s worth of sales into a separate partition:

CREATE TABLE sales (
 order_date DATETIME NOT NULL,
 -- Other columns omitted
) ENGINE=InnoDB PARTITION BY RANGE(YEAR(order_date)) (
 PARTITION p_2010 VALUES LESS THAN (2010),
 PARTITION p_2011 VALUES LESS THAN (2011),
 PARTITION p_2012 VALUES LESS THAN (2012),
 PARTITION p_catchall VALUES LESS THAN MAXVALUE );

read more here.

It is not really about using different server instances (although that is sometimes a possibility), it is more about dividing your tables in different physical partitions.

It's dividing your tables and indexes into smaller pieces, and even subdivide it into even smaller pieces. Think of it as having several million different magazines of different topics and different years (say 2000-2019) all in one big warehouse (one big table). Partitioning would mean that you would put them organized in different rooms inside that big warehouse. They still belong together inside the one warehouse, but now you group them on a logical level, depending on your database partitioning strategy.

Indexing is actually like keeping a table of which magazine is where in your warehouse, or in your rooms inside your warehouse. As you can see, there is a big difference between database partitioning and indexing, and they can be very well used together.

You can read more about it on my website on this article about Database Partitioning

Related