Postgresql - Table Partitioning (二)

官档里对分区表的说明,继续划重点啦。

#######################################################

PostgreSQL offers a way to specify how to divide a table into pieces called partitions. The table that is divided is referred to as a  partitioned table . The specification consists of the  partitioning method  and a list of columns or expressions to be used as the   partition key .
# 规范由分区方法和要用作分区键的列或表达式的列表组成。

All rows inserted into a partitioned table will be routed to one of the  partitions  based on the value of the partition key. Each partition has a subset of the data defined by its  partition bounds . Currently supported partitioning methods include range and list, where each partition is assigned a range of keys and a list of keys , respectively.
# 插入到分区表中的所有行将根据分区键的值路由到分区中的一个分区。每个分区都有一个由其分区界限定义的数据子集。当前支持的分区方法包括范围和列表,其中每个分区分别分配了一系列值和一个列表。

Partitions may themselves be defined as partitioned tables , using what is called  sub-partitioning . Partitions may have their own indexes, constraints and default values, distinct from those of other partitions . Indexes must be created separately for each partition .
# 分区本身可以被定义为分区表,使用所谓的子分区。分区可有自己的索引、约束和默认值,与其他分区不同。必须为每个分区分别创建索引。

It is not possible to turn a regular table into a partitioned table or vice versa . However, it is possible to add a regular or partitioned table containing data as a partition of a partitioned table, or remove a partition from a partitioned table turning it into a standalone table;
# 不可能将常规表转换成分区表,反之亦然。但是,可以将包含数据的规则或分区表添加为分区表的分区,或者从分区表中移除分区,将其转换为独立表;

Individual partitions are linked to the partitioned table with inheritance behind-the-scenes ; however, it is not possible to use some of the inheritance features discussed in the previous section with partitioned tables and partitions. For example, a partition cannot have any parents other than the partitioned table it is a partition of, nor can a regular table inherit from a partitioned table making the latter its parent. That means partitioned tables and partitions do not participate in inheritance with regular tables. Since a partition hierarchy consisting of the partitioned table and its partitions is still an inheritance hierarchy, all the normal rules of inheritance apply as described in  Section 5.9  with some exceptions, most notably:
# 单独的分区被链接到具有后台继承的分区表;但是,不可能使用前一部分中讨论的一些具有分区表和分区的继承特性。例如,分区除了分区表之外,除了分区表之外,不能有任何父级,也不能从分区表继承正则表,使后者成为父级。这意味着分区表和分区不参与常规表的继承。由于由分区表及其分区组成的分区层次结构仍然是继承层次结构,所以所有正常的继承规则都适用于第5.9节中所述的一些例外情况,最明显的是:

  • Both CHECK and NOT NULL constraints of a partitioned table are always inherited by all its partitionsCHECK constraints that are marked NO INHERIT are not allowed to be created on partitioned tables.
# 分区表的CHECK和NULL约束都由其所有分区继承。不允许在分区表上创建标记为 NO INHERIT的检查约束。

  • Using ONLY to add or drop a constraint on only the partitioned table is supported when there are no partitions. Once partitions exist, using ONLY will result in an error as adding or dropping constraints on only the partitioned table, when partitions exist, is not supported. Instead, constraints can be added or dropped, when they are not present in the parent table, directly on the partitions. As a partitioned table does not have any data directly, attempts to use TRUNCATE ONLY on a partitioned table will always return an error.
# 在没有分区的情况下,使用ONLY增加或删除约束只对被分区的表支持。一旦存在分区,使用ONLY将导致错误,因为仅在分区表上添加或删除约束,当存在分区时,不支持。相反,当它们不存在于父表中时,可以直接添加或删除约束。由于分区表没有任何数据直接,所以尝试仅在分区表上使用 TRUNCATE   ONLY将始终返回错误。

  • Partitions cannot have columns that are not present in the parent. It is neither possible to specify columns when creating partitions with CREATE TABLEnor is it possible to add columns to partitions after-the-fact using ALTER TABLE. Tables may be added as a partition with ALTER TABLE ... ATTACH PARTITION only if their columns exactly match the parent, including any oid column.
# 分区不能具有父项中不存在的列。在创建带有创建表的分区时,既不可能指定列,也不可能在使用ALTE表的事实之后将列添加到分区。表可以添加为具有ALTE表的分区…如果分区与父级匹配,包括任何OID列时, 使用ALTER TABLE ... ATTACH PARTITION 表才附加分区。

  • You cannot drop the NOT NULL constraint on a partition's column if the constraint is present in the parent table.
# 如果在父表中存在约束,则不能将NULL NULL约束删除到分区的列上。
Partitions can also be foreign tables, although these have some limitations that normal tables do not. For example, data inserted into the partitioned table is not routed to foreign table partitions.

猜你喜欢

转载自blog.csdn.net/chuckchen1222/article/details/80784446