8.19. Object Identifier Types

8.19. Object Identifier Types
8.19.对象标识类型
Object identifiers (OIDs) are used internally by PostgreSQL as primary keys for various system tables. OIDs are not added to user-created tables, unless WITH OIDS is specified when the table is created,or the default_with_oids configuration variable is enabled. Type oid represents an object identifier.There are also several alias types for oid: regproc, regprocedure, regoper, regoperator,regclass, regtype, regrole, regnamespace, regconfig, and regdictionary.Table 8.24 shows an overview.
PostgreSQL内部使用对象标识符(OID)作为各种系统表的主键。除非在创建表时指定了WITH OIDS或启用了default_with_oids配置变量,否则OID不会添加到用户创建的表中。类型oid表示对象标识符.oid的别名也有几种:regproc,regprocedure,regoper,regoperator,regclass,regtype,regrole,regnamespace,regconfig和regdictionary。综述见表8.24。
 
The oid type is currently implemented as an unsigned four-byte integer. Therefore, it is not large enough to provide database-wide uniqueness in large databases, or even in large individual tables. So,using a user-created table's OID column as a primary key is discouraged. OIDs are best used only for references to system tables.
oid类型当前为无符号的四字节整数。因此,它不足以在大型数据库甚至大型单个表中提供数据库范围的唯一性。因此,不建议将用户创建的表的OID列用作主键。 OID最好仅用于系统表。
 
The oid type itself has few operations beyond comparison. It can be cast to integer, however, and then manipulated using the standard integer operators. (Beware of possible signed-versus-unsigned confusion if you do this.)
oid类型本身无法比较。 但是,可以将其强制转换为整数,然后使用标准整数运算符对其进行操作。 (如果要这样做,请当心可能的签名与未签名的混淆。)
 
The OID alias types have no operations of their own except for specialized input and output routines.These routines are able to accept and display symbolic names for system objects, rather than the raw numeric value that type oid would use. The alias types allow simplified lookup of OID values for objects. For example, to examine the pg_attribute rows related to a table mytable, one could write:
除了专用的输入和输出例程外,OID别名类型没有自己的操作符。这些例程能够接受和显示系统对象的符号名称,而不是oid类型将使用的原始数值。 别名类型允许简化对象的OID值查找。 例如,要检查与表mytable相关的pg_attribute行,可以编写:
 
SELECT * FROM pg_attribute WHERE attrelid = 'mytable'::regclass;
 
rather than:
而不用:
 
SELECT * FROM pg_attribute
WHERE attrelid = (SELECT oid FROM pg_class WHERE relname =
'mytable');
 
While that doesn't look all that bad by itself, it's still oversimplified. A far more complicated subselect would be needed to select the right OID if there are multiple tables named mytable in different schemas. The regclass input converter handles the table lookup according to the schema path setting, and so it does the “right thing” automatically. Similarly, casting a table's OID to regclass is handy for symbolic display of a numeric OID.
虽然这看上去还不错,但仍然过于简化了。 如果在不同模式中有多个名为mytable的表,则需要更复杂的子查询来选择正确的OID。 regclass输入转换器根据架构路径设置处理表查找顺序,因此它会自动执行“正确的事情”。 同样,将表的OID强制转换为regclass对于数字OID的符号显示很方便。
 
8.19. Object Identifier Types
All of the OID alias types for objects grouped by namespace accept schema-qualified names, and will display schema-qualified names on output if the object would not be found in the current search path without being qualified. The regproc and regoper alias types will only accept input names that are unique (not overloaded), so they are of limited use; for most uses regprocedure or regoperator are more appropriate. For regoperator, unary operators are identified by writing NONE for the unused operand.
按命名空间分组的对象的所有OID别名类型都接受模式限定的名称,如果在当前搜索路径中没有限定模式的情况下找不到对象,则将在输出中显示带模式限定的名称。regproc和regoper别名类型将仅接受唯一的输入名称(不重载),因此它们的使用受到限制;在大多数情况下,更适合使用procprocedure或regoperator。对于regoperator,通过为未使用的操作数写入NONE来标识一元运算符。
 
An additional property of most of the OID alias types is the creation of dependencies. If a constant of one of these types appears in a stored expression (such as a column default expression or view),it creates a dependency on the referenced object. For example, if a column has a default expression nextval('my_seq'::regclass), PostgreSQL understands that the default expression depends on the sequence my_seq; the system will not let the sequence be dropped without first removing the default expression. regrole is the only exception for the property. Constants of this type are not allowed in such expressions.
大多数OID别名类型的另一个属性是依赖关系的创建。如果这些类型之一的常量出现在存储的表达式(例如列默认表达式或视图)中,则它将创建对引用对象的依赖关系。例如,如果一列具有默认表达式nextval('my_seq':: regclass),则PostgreSQL理解默认表达式取决于序列my_seq;在不先删除默认表达式的情况下,系统不会删除该序列。 regrole是该属性的唯一例外。在此类表达式中不允许使用此类常量。
 
Note
The OID alias types do not completely follow transaction isolation rules. The planner also treats them as simple constants, which may result in sub-optimal planning.
OID别名类型不完全遵循事务隔离规则。执行计划还将它们视为简单常数,这可能会导致次优的执行计划。
 
Another identifier type used by the system is xid, or transaction (abbreviated xact) identifier. This is the data type of the system columns xmin and xmax. Transaction identifiers are 32-bit quantities.A third identifier type used by the system is cid, or command identifier. This is the data type of the system columns cmin and cmax. Command identifiers are also 32-bit quantities.
系统使用的另一种标识符类型是xid或事务(缩写为xact)标识符。 这是系统列xmin和xmax的数据类型。 事务标识符是32位的。系统使用的第三种标识符类型是cid或命令标识符。 这是系统列cmin和cmax的数据类型。 命令标识符也是32位。
 
A final identifier type used by the system is tid, or tuple identifier (row identifier). This is the data type of the system column ctid. A tuple ID is a pair (block number, tuple index within block) that identifies the physical location of the row within its table.
系统使用的最终标识符类型是tid或元组标识符(行标识符)。 这是系统列ctid的数据类型。 行ID是一对(块号,块内的行索引),用于标识表中行的物理位置。
 
(The system columns are further explained in Section 5.4.)
(系统列的更多信息,参见5.4节。)