Postgresql 中文操作指南

5.5. System Columns #

每个表都有多个由系统隐式定义的_system columns_。因此,这些名称不可用作用户定义列的名称。(请注意,这些限制与该名称是否是关键字无关;对名称加引号不会让你绕开这些限制。)你不用真正关注这些列,只需知道它们的存在即可。

Every table has several system columns that are implicitly defined by the system. Therefore, these names cannot be used as names of user-defined columns. (Note that these restrictions are separate from whether the name is a key word or not; quoting a name will not allow you to escape these restrictions.) You do not really need to be concerned about these columns; just know they exist.

  • tableoid #

    • The OID of the table containing this row. This column is particularly handy for queries that select from partitioned tables (see Section 5.11) or inheritance hierarchies (see Section 5.10), since without it, it’s difficult to tell which individual table a row came from. The tableoid can be joined against the oid column of pg_class to obtain the table name.

  • xmin #

    • The identity (transaction ID) of the inserting transaction for this row version. (A row version is an individual state of a row; each update of a row creates a new row version for the same logical row.)

  • cmin #

    • The command identifier (starting at zero) within the inserting transaction.

  • xmax #

    • The identity (transaction ID) of the deleting transaction, or zero for an undeleted row version. It is possible for this column to be nonzero in a visible row version. That usually indicates that the deleting transaction hasn’t committed yet, or that an attempted deletion was rolled back.

  • cmax #

    • The command identifier within the deleting transaction, or zero.

  • ctid #

    • The physical location of the row version within its table. Note that although the ctid can be used to locate the row version very quickly, a row’s ctid will change if it is updated or moved by VACUUM FULL. Therefore ctid is useless as a long-term row identifier. A primary key should be used to identify logical rows.

事务标识符也是 32 位量。在长期存在的数据库中,事务 ID 可能会环绕。如果采用适当的维护程序,这不是一个致命的问题;有关详细内容,请参见 Chapter 25。但是,不应长期(超过十亿个事务)依赖事务 ID 的唯一性。

Transaction identifiers are also 32-bit quantities. In a long-lived database it is possible for transaction IDs to wrap around. This is not a fatal problem given appropriate maintenance procedures; see Chapter 25 for details. It is unwise, however, to depend on the uniqueness of transaction IDs over the long term (more than one billion transactions).

命令标识符也是32位量。这在单个事务中生成了232(40亿)个SQL命令的硬性上限。实际上,这个上限并不是问题——请注意,这个上限针对的是SQL命令数量,而不是处理的行数量。此外,只有真正修改数据库内容的命令才会占用命令标识符。

Command identifiers are also 32-bit quantities. This creates a hard limit of 232 (4 billion) SQL commands within a single transaction. In practice this limit is not a problem — note that the limit is on the number of SQL commands, not the number of rows processed. Also, only commands that actually modify the database contents will consume a command identifier.