F.50. pg_visibility
Модуль pg_visibility
даёт возможность исследовать для определённой таблицы карту видимости (Visibility Map, VM) и информацию о видимости на уровне страниц. Он также предоставляет функции для проверки целостности карты видимости и принудительного её пересоздания.
Для хранения информации о видимости на уровне страниц применяются по три различных бита. Бит полной видимости в карте показывает, что каждый кортеж в соответствующей странице отношения является видимым для всех текущих и будущих транзакций. Бит полной заморозки в карте видимости показывает, что все кортежи в данной странице являются замороженными; то есть никакой операции очистки в будущем не придётся обрабатывать эту страницу, пока в ней не будет добавлен, изменён, удалён или заблокирован кортеж. Бит PD_ALL_VISIBLE
в заголовке страницы имеет то же значение, что и бит полной видимости в карте видимости, но он хранится в самой странице данных, а не в отдельной структуре данных. В обычной ситуации эти два бита будут согласованы, но бит полной видимости в странице иногда может быть установлен, тогда как в карте видимости он оказывается сброшенным при восстановлении после сбоя. Считываемые значения могут также различаться, если они подвергаются изменению в промежутке между обращениями pg_visibility
к карте видимости и к странице данных. Разумеется, эти биты также могут различаться при событиях, приводящих к разрушению данных.
Функции, выдающие информацию о битах PD_ALL_VISIBLE
, более дорогостоящие, чем те, что обращаются только к карте видимости, так как они должны читать блоки отношения, а не только карту видимости (которая намного меньше). Дорогостоящими являются также и функции, проверяющие блоки данных отношения.
F.50.1. Функции
pg_visibility_map(relation regclass, blkno bigint, all_visible OUT boolean, all_frozen OUT boolean) returns record
Возвращает биты полной видимости и полной заморозки в карте видимости для указанного блока заданного отношения.
pg_visibility(relation regclass, blkno bigint, all_visible OUT boolean, all_frozen OUT boolean, pd_all_visible OUT boolean) returns record
Возвращает биты полной видимости и полной заморозки в карте видимости для указанного блока заданного отношения, а также бит
PD_ALL_VISIBLE
этого блока.pg_visibility_map(relation regclass, blkno OUT bigint, all_visible OUT boolean, all_frozen OUT boolean) returns setof record
Возвращает биты полной видимости и полной заморозки в карте видимости для каждого блока заданного отношения.
pg_visibility(relation regclass, blkno OUT bigint, all_visible OUT boolean, all_frozen OUT boolean, pd_all_visible OUT boolean) returns setof record
Возвращает биты полной видимости и полной заморозки в карте видимости для каждого блока заданного отношения, а также бит
PD_ALL_VISIBLE
каждого блока.pg_visibility_map_summary(relation regclass, all_visible OUT bigint, all_frozen OUT bigint) returns record
Возвращает число полностью видимых страниц и полностью замороженных страниц в отношении, согласно карте видимости.
pg_check_frozen(relation regclass, t_ctid OUT tid) returns setof tid
Возвращает идентификаторы TID незамороженных кортежей в страницах, помеченных как полностью замороженные в карте видимости. Если эта функция возвращает непустой набор TID, карта видимости испорчена.
pg_check_visible(relation regclass, t_ctid OUT tid) returns setof tid
Возвращает идентификаторы TID не полностью видимых кортежей в страницах, помеченных как полностью видимые в карте видимости. Если эта функция возвращает непустой набор TID, карта видимости испорчена.
pg_truncate_visibility_map(relation regclass) returns void
Аннулирует карту видимости для заданного отношения. Эта функция полезна, если вы считаете, что карта видимости для указанного отношения испорчена, и хотите принудительно пересоздать её. Первая же команда
VACUUM
, выполняемая с данным отношением после этой функции, просканирует все страницы в отношении и пересоздаст карту видимости. (Пока это не произойдёт, для запросов карта видимости будет выглядеть как полностью нулевая.)
По умолчанию эти функции разрешено выполнять только суперпользователям и ролям с правами роли pg_stat_scan_tables
, за исключением pg_truncate_visibility_map(relation regclass)
, которую могут выполнять только суперпользователи.
9.19. Array Functions and Operators #
Table 9.54 shows the specialized operators available for array types. In addition to those, the usual comparison operators shown in Table 9.1 are available for arrays. The comparison operators compare the array contents element-by-element, using the default B-tree comparison function for the element data type, and sort based on the first difference. In multidimensional arrays the elements are visited in row-major order (last subscript varies most rapidly). If the contents of two arrays are equal but the dimensionality is different, the first difference in the dimensionality information determines the sort order.
Table 9.54. Array Operators
Operator Description Example(s) |
---|
Does the first array contain the second, that is, does each element appearing in the second array equal some element of the first array? (Duplicates are not treated specially, thus
|
Is the first array contained by the second?
|
Do the arrays overlap, that is, have any elements in common?
|
Concatenates the two arrays. Concatenating a null or empty array is a no-op; otherwise the arrays must have the same number of dimensions (as illustrated by the first example) or differ in number of dimensions by one (as illustrated by the second). If the arrays are not of identical element types, they will be coerced to a common type (see Section 10.5).
|
Concatenates an element onto the front of an array (which must be empty or one-dimensional).
|
Concatenates an element onto the end of an array (which must be empty or one-dimensional).
|
See Section 8.15 for more details about array operator behavior. See Section 11.2 for more details about which operators support indexed operations.
Table 9.55 shows the functions available for use with array types. See Section 8.15 for more information and examples of the use of these functions.
Table 9.55. Array Functions
Function Description Example(s) |
---|
Appends an element to the end of an array (same as the
|
Concatenates two arrays (same as the
|
Returns a text representation of the array's dimensions.
|
Returns an array filled with copies of the given value, having dimensions of the lengths specified by the second argument. The optional third argument supplies lower-bound values for each dimension (which default to all
|
Returns the length of the requested array dimension. (Produces NULL instead of 0 for empty or missing array dimensions.)
|
Returns the lower bound of the requested array dimension.
|
Returns the number of dimensions of the array.
|
Returns the subscript of the first occurrence of the second argument in the array, or
|
Returns an array of the subscripts of all occurrences of the second argument in the array given as first argument. The array must be one-dimensional. Comparisons are done using
|
Prepends an element to the beginning of an array (same as the
|
Removes all elements equal to the given value from the array. The array must be one-dimensional. Comparisons are done using
|
Replaces each array element equal to the second argument with the third argument.
|
Returns an array of
|
Randomly shuffles the first dimension of the array.
|
Converts each array element to its text representation, and concatenates those separated by the
|
Returns the upper bound of the requested array dimension.
|
Returns the total number of elements in the array, or 0 if the array is empty.
|
Trims an array by removing the last
|
Expands an array into a set of rows. The array's elements are read out in storage order.
1 2
foo bar baz quux |
Expands multiple arrays (possibly of different data types) into a set of rows. If the arrays are not all the same length then the shorter ones are padded with
a | b ---+----- 1 | foo 2 | bar | baz |
See also Section 9.21 about the aggregate function array_agg
for use with arrays.