Postgresql 中文操作指南

ALTER OPERATOR FAMILY

ALTER OPERATOR FAMILY — 更改操作符族定义

ALTER OPERATOR FAMILY — change the definition of an operator family

Synopsis

ALTER OPERATOR FAMILY name USING index_method ADD
  {  OPERATOR strategy_number operator_name ( op_type, op_type )
              [ FOR SEARCH | FOR ORDER BY sort_family_name ]
   | FUNCTION support_number [ ( op_type [ , op_type ] ) ]
              function_name [ ( argument_type [, ...] ) ]
  } [, ... ]

ALTER OPERATOR FAMILY name USING index_method DROP
  {  OPERATOR strategy_number ( op_type [ , op_type ] )
   | FUNCTION support_number ( op_type [ , op_type ] )
  } [, ... ]

ALTER OPERATOR FAMILY name USING index_method
    RENAME TO new_name

ALTER OPERATOR FAMILY name USING index_method
    OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }

ALTER OPERATOR FAMILY name USING index_method
    SET SCHEMA new_schema

Description

ALTER OPERATOR FAMILY 更改操作符族的定义。您可以在族中添加操作符和支持函数,从族中移除操作符和支持函数,或更改族的名称或所有者。

ALTER OPERATOR FAMILY changes the definition of an operator family. You can add operators and support functions to the family, remove them from the family, or change the family’s name or owner.

当在使用 ALTER OPERATOR FAMILY 向一个族中添加操作符和支持函数时,它们并不属于族中的任何特定操作符类,而是仅为族中的“松散”成员。这表明这些操作符和函数与族的语义兼容,但不是任何特定索引正确工作的必要条件。(如此要求的操作符和函数应该作为操作符类的一部分声明;参见 CREATE OPERATOR CLASS 。)PostgreSQL 将允许族中的松散成员在任何时候从族中被删除,但操作符类的成员不能被删除,而不删除整个类和依赖于该类的任何索引。通常,单一数据类型操作符和函数属于操作符类,因为需要它们来支持特定数据类型的索引,而跨数据类型操作符和函数则成为族的松散成员。

When operators and support functions are added to a family with ALTER OPERATOR FAMILY, they are not part of any specific operator class within the family, but are just “loose” within the family. This indicates that these operators and functions are compatible with the family’s semantics, but are not required for correct functioning of any specific index. (Operators and functions that are so required should be declared as part of an operator class, instead; see CREATE OPERATOR CLASS.) PostgreSQL will allow loose members of a family to be dropped from the family at any time, but members of an operator class cannot be dropped without dropping the whole class and any indexes that depend on it. Typically, single-data-type operators and functions are part of operator classes because they are needed to support an index on that specific data type, while cross-data-type operators and functions are made loose members of the family.

您必须是超级用户才能使用 ALTER OPERATOR FAMILY 。(此限制原因在于,错误的操作符族定义可能会使服务器混淆或崩溃。)

You must be a superuser to use ALTER OPERATOR FAMILY. (This restriction is made because an erroneous operator family definition could confuse or even crash the server.)

ALTER OPERATOR FAMILY 目前不检查操作符族定义是否包括索引方法所需的所有操作符和函数,也不检查操作符和函数是否形成自洽集。定义有效操作符族是用户的责任。

ALTER OPERATOR FAMILY does not presently check whether the operator family definition includes all the operators and functions required by the index method, nor whether the operators and functions form a self-consistent set. It is the user’s responsibility to define a valid operator family.

有关更多信息,请参阅 Section 38.16

Refer to Section 38.16 for further information.

Parameters

  • name

    • The name (optionally schema-qualified) of an existing operator family.

  • index_method

    • The name of the index method this operator family is for.

  • strategy_number

    • The index method’s strategy number for an operator associated with the operator family.

  • operator_name

    • The name (optionally schema-qualified) of an operator associated with the operator family.

  • op_type

    • In an OPERATOR clause, the operand data type(s) of the operator, or NONE to signify a prefix operator. Unlike the comparable syntax in CREATE OPERATOR CLASS, the operand data types must always be specified.

    • In an ADD FUNCTION clause, the operand data type(s) the function is intended to support, if different from the input data type(s) of the function. For B-tree comparison functions and hash functions it is not necessary to specify op_type since the function’s input data type(s) are always the correct ones to use. For B-tree sort support functions, B-Tree equal image functions, and all functions in GiST, SP-GiST and GIN operator classes, it is necessary to specify the operand data type(s) the function is to be used with.

    • In a DROP FUNCTION clause, the operand data type(s) the function is intended to support must be specified.

  • sort_family_name

    • The name (optionally schema-qualified) of an existing btree operator family that describes the sort ordering associated with an ordering operator.

    • If neither FOR SEARCH nor FOR ORDER BY is specified, FOR SEARCH is the default.

  • support_number

    • The index method’s support function number for a function associated with the operator family.

  • function_name

    • The name (optionally schema-qualified) of a function that is an index method support function for the operator family. If no argument list is specified, the name must be unique in its schema.

  • argument_type

    • The parameter data type(s) of the function.

  • new_name

    • The new name of the operator family.

  • new_owner

    • The new owner of the operator family.

  • new_schema

    • The new schema for the operator family.

OPERATORFUNCTION 子句可以按任意顺序显示。

The OPERATOR and FUNCTION clauses can appear in any order.

Notes

请注意, DROP 语法仅按策略或支持编号和输入数据类型指定运算符系列的“槽”。未提及占用槽的运算符或函数的名称。此外,对于 DROP FUNCTION ,要指定支持该函数的输入数据类型;对于 GiST、SP-GiST 和 GIN 索引,输入数据类型可能与该函数的实际输入参数类型无关。

Notice that the DROP syntax only specifies the “slot” in the operator family, by strategy or support number and input data type(s). The name of the operator or function occupying the slot is not mentioned. Also, for DROP FUNCTION the type(s) to specify are the input data type(s) the function is intended to support; for GiST, SP-GiST and GIN indexes this might have nothing to do with the actual input argument types of the function.

由于索引机制在使用函数之前不会检查函数的访问权限,因此在运算符系列中包含函数或运算符等同于授予该函数或运算符公共执行权限。对于在运算符系列中有用的函数类别,通常这不是问题。

Because the index machinery does not check access permissions on functions before using them, including a function or operator in an operator family is tantamount to granting public execute permission on it. This is usually not an issue for the sorts of functions that are useful in an operator family.

运算符不应由 SQL 函数定义。SQL 函数可能会内联到调用查询中,这将阻止优化器识别查询是否匹配某个索引。

The operators should not be defined by SQL functions. An SQL function is likely to be inlined into the calling query, which will prevent the optimizer from recognizing that the query matches an index.

在 PostgreSQL 8.4 之前, OPERATOR 子句可以包含 RECHECK 选项。不再支持此选项,因为索引运算符是“有损”的,现在在运行时动态确定。这允许高效处理运算符可能是有损或无损的情况。

Before PostgreSQL 8.4, the OPERATOR clause could include a RECHECK option. This is no longer supported because whether an index operator is “lossy” is now determined on-the-fly at run time. This allows efficient handling of cases where an operator might or might not be lossy.

Examples

以下示例命令将跨数据类型运算符和支持函数添加到已包含数据类型 int4int2 的 B 树运算符类的运算符系列中。

The following example command adds cross-data-type operators and support functions to an operator family that already contains B-tree operator classes for data types int4 and int2.

ALTER OPERATOR FAMILY integer_ops USING btree ADD

  -- int4 vs int2
  OPERATOR 1 < (int4, int2) ,
  OPERATOR 2 <= (int4, int2) ,
  OPERATOR 3 = (int4, int2) ,
  OPERATOR 4 >= (int4, int2) ,
  OPERATOR 5 > (int4, int2) ,
  FUNCTION 1 btint42cmp(int4, int2) ,

  -- int2 vs int4
  OPERATOR 1 < (int2, int4) ,
  OPERATOR 2 <= (int2, int4) ,
  OPERATOR 3 = (int2, int4) ,
  OPERATOR 4 >= (int2, int4) ,
  OPERATOR 5 > (int2, int4) ,
  FUNCTION 1 btint24cmp(int2, int4) ;

要再次删除这些条目:

To remove these entries again:

ALTER OPERATOR FAMILY integer_ops USING btree DROP

  -- int4 vs int2
  OPERATOR 1 (int4, int2) ,
  OPERATOR 2 (int4, int2) ,
  OPERATOR 3 (int4, int2) ,
  OPERATOR 4 (int4, int2) ,
  OPERATOR 5 (int4, int2) ,
  FUNCTION 1 (int4, int2) ,

  -- int2 vs int4
  OPERATOR 1 (int2, int4) ,
  OPERATOR 2 (int2, int4) ,
  OPERATOR 3 (int2, int4) ,
  OPERATOR 4 (int2, int4) ,
  OPERATOR 5 (int2, int4) ,
  FUNCTION 1 (int2, int4) ;

Compatibility

SQL 标准中没有 ALTER OPERATOR FAMILY 语句。

There is no ALTER OPERATOR FAMILY statement in the SQL standard.