“分区”有什么用? MySQL 中的关键字?

发布于 2024-08-27 00:46:26 字数 526 浏览 13 评论 0原文

因为我是 MySQL 新手。这个 MySQL 语句中的 PARTITION 是什么意思?

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)
);

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)
);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北斗星光 2024-09-03 00:46:26

分区是一种方法
预组织表存储。你可以
说“表中的一些行将会消失
这里,有些人会去那里,还有一些人
还会去其他地方”。
通常,取决于存储
引擎,效果是传播
不同文件上的表行或
甚至不同的磁盘。

来自: MySQL 5.1 新功能:MySQL 分区


您还可以有兴趣寻求有关“水平分区”的更多信息,以便更好地了解此功能特别有用的场景。

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.

提笔书几行 2024-09-03 00:46:26

分区通过拆分到不同的存储桶来帮助组织存储在表中的数据。

这类似于图书馆为不同主题设置单独的书架部分,而目录/索引卡抽屉通常按字母顺序分开。

这有两个好处:

  1. 使用分区更容易管理物理存储。例如,一种策略可能是为每个分区的存储使用单独的磁盘。这通常有助于将数据以平衡的方式分布在多个物理磁盘上。
  2. 数据库可以通过识别需要检索的有限分区来优化数据的检索和传递。分区通常是在考虑物理存储特性的情况下完成的。因此,即使在检索时,数据库引擎通常也只需要从特定分区读取,因此可以从物理存储读取整个数据块。

您可以通过以下几个链接获取更多详细信息:

维基百科文章: http://en.wikipedia .org/wiki/Partition_(database)

有关分区的 MySQL 文档: http://dev.mysql.com/doc/refman/5.5/en/partitioning.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文