Question

As I am a MySQL newbie. What does PARTITION mean in this MySQL statement?

CREATE TABLE employees (
    id INT NOT NULL,
    fname VARCHAR(30),
    lname VARCHAR(30),
    hired DATE NOT NULL DEFAULT '1970-01-01',
    separated DATE NOT NULL DEFAULT '9999-12-31',
    job_code INT NOT NULL,
    store_id INT NOT NULL
)
PARTITION BY RANGE (store_id) (
    PARTITION p0 VALUES LESS THAN (6),
    PARTITION p1 VALUES LESS THAN (11),
    PARTITION p2 VALUES LESS THAN (16),
    PARTITION p3 VALUES LESS THAN (21)
);
Was it helpful?

Solution

Partitioning is a way of pre-organizing table storage. You can say "some of the table's rows will go here, some will go there, still others will go to to still other places". Often, depending on the storage engine, the effect is to spread the table's rows over different files or even different disks.

From: MySQL 5.1 New Features: MySQL Partitions


You may also be interested in seeking further information on "horizontal partitioning", in order to better understand the scenarios where this is particularly useful.

OTHER TIPS

Partitioning helps in organize the data stored in the table by splitting across different buckets.

This is analogous to how a library has separate sections of shelves for different subjects, while the catalogue/index card drawers are usually separated alphabetically.

This helps in two ways:

  1. It is easier to manage the physical storage using partitioning. For instance, one strategy could be to have separate disks for each partition's storage. This usually helps spread the data in a balanced manner across multiple physical disks.
  2. The database can optimize the retrieval and delivery of the data by identifying limited partitions that need to be retrieved. Partitioning is usually done keeping in mind the physical storage characteristics. Thus, even while retrieving, the database engine will typically need to read only from a specific partition and so can read entire blocks of data from the physical storage.

Here are a few links where you can get many more details:

Wikipedia article: http://en.wikipedia.org/wiki/Partition_(database)

MySQL documentation regarding partitions: http://dev.mysql.com/doc/refman/5.5/en/partitioning.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top