53.4. pg_amop

В каталоге pg_amop хранится информация об операторах, связанных с семействами операторов методов доступа. Каждая строка в нём описывает оператор, являющийся членом семейства операторов. Членом семейства может быть либо оператор поиска, либо оператор упорядочивания. Оператор может относиться к нескольким семействам, но он не может находиться в одном семействе в более чем одной позиции поиска или позиции упорядочивания. (Допустимо, хотя и маловероятно, что оператор будет использоваться и для поиска, и для упорядочивания.)

Таблица 53.4. Столбцы pg_amop

ИмяТипСсылкиОписание
oidoid Идентификатор строки (скрытый атрибут; должен выбираться явно)
amopfamilyoidpg_opfamily.oidСемейство операторов, к которому относится эта запись
amoplefttypeoidpg_type.oidТип данных левого операнда оператора
amoprighttypeoidpg_type.oidТип данных правого операнда оператора
amopstrategyint2 Номер стратегии оператора
amoppurposechar Предназначение оператора: s — поиск (search), o — упорядочивание (ordering)
amopoproidpg_operator.oidOID оператора
amopmethodoidpg_am.oidИндексный метод доступа, для которого предназначено семейство операторов
amopsortfamilyoidpg_opfamily.oidСемейство операторов B-дерева, в соответствии с которым сортирует данный оператор, если это оператор упорядочивания; ноль, если это оператор поиска

Запись оператора «поиска» указывает, что по индексу этого семейства операторов можно производить поиск и найти все строки, удовлетворяющие условию WHERE столбец_индекса оператор константа. Очевидно, такой оператор должен возвращать тип boolean, а тип его левого операнда должен соответствовать типу данных столбца индекса.

Запись оператора «упорядочивания» указывает, что по индексу этого семейства операторов можно провести сканирование и получить строки в порядке, заданном предложением ORDER BY столбец_индекса оператор константа. Такой оператор может возвращать любой сортируемый тип данных, хотя тип левого операнда должен так же соответствовать типу данных столбца индекса. Точная семантика ORDER BY определяется столбцом amopsortfamily, который должна указывать на семейство операторов B-дерева для типа, возвращаемого оператором.

Примечание

В настоящее время предполагается, что порядком сортировки для упорядочивающего оператора будет порядок по умолчанию для соответствующего семейства операторов, то есть, ASC NULLS LAST. Когда-нибудь для большей гибкости могут быть добавлены дополнительные столбцы, позволяющие явно задавать параметры сортировки.

Поле amopmethod в записи оператора должно соответствовать полю opfmethod содержащего его семейства (amopmethod добавлен сюда намеренно, эта денормализация структуры каталога объясняется соображениями производительности). Также, поля amoplefttype и amoprighttype должны соответствовать полям oprleft и oprright в записи pg_operator, на которую ссылается данная.

53.4. pg_amop

The catalog pg_amop stores information about operators associated with access method operator families. There is one row for each operator that is a member of an operator family. A family member can be either a search operator or an ordering operator. An operator can appear in more than one family, but cannot appear in more than one search position nor more than one ordering position within a family. (It is allowed, though unlikely, for an operator to be used for both search and ordering purposes.)

Table 53.4. pg_amop Columns

NameTypeReferencesDescription
oidoid Row identifier (hidden attribute; must be explicitly selected)
amopfamilyoidpg_opfamily.oidThe operator family this entry is for
amoplefttypeoidpg_type.oidLeft-hand input data type of operator
amoprighttypeoidpg_type.oidRight-hand input data type of operator
amopstrategyint2 Operator strategy number
amoppurposechar Operator purpose, either s for search or o for ordering
amopoproidpg_operator.oidOID of the operator
amopmethodoidpg_am.oidIndex access method operator family is for
amopsortfamilyoidpg_opfamily.oidThe B-tree operator family this entry sorts according to, if an ordering operator; zero if a search operator

A search operator entry indicates that an index of this operator family can be searched to find all rows satisfying WHERE indexed_column operator constant. Obviously, such an operator must return boolean, and its left-hand input type must match the index's column data type.

An ordering operator entry indicates that an index of this operator family can be scanned to return rows in the order represented by ORDER BY indexed_column operator constant. Such an operator could return any sortable data type, though again its left-hand input type must match the index's column data type. The exact semantics of the ORDER BY are specified by the amopsortfamily column, which must reference a B-tree operator family for the operator's result type.

Note

At present, it's assumed that the sort order for an ordering operator is the default for the referenced operator family, i.e., ASC NULLS LAST. This might someday be relaxed by adding additional columns to specify sort options explicitly.

An entry's amopmethod must match the opfmethod of its containing operator family (including amopmethod here is an intentional denormalization of the catalog structure for performance reasons). Also, amoplefttype and amoprighttype must match the oprleft and oprright fields of the referenced pg_operator entry.

FAQ