ScanKeyData
翻譯
ScanKey描述了表或者索引以及常量之間比較操作的應用。 當它是ScanKeys的一部分時,它默認爲AND。如果是一個二進制操作時,索引列爲左操作數
(數據結構也可以支持一元索引操作符,在這種情況下,sk_argument會被省略,但是它現在沒有被實現)
對於一個索引掃描來說,sk_strategy和sk_subtype必須被設置爲正確。但是在一個heap掃描中使用ScanKye時,這兩個參數不會被使用,他們可能會被設置爲InvalidStrategy和InvalidOid。
如果操作運算是collation-sensitive時,sk_collation 必須被正確設置
在 “column op ANY(ARRAY[…])”這種情況下,ScanKey也可以描述爲ScalarArrayOpExpr,它被SK_SEARCHARRAY標識符標識
sk_argument 不是運算符的右側參數類型的值,而是這樣值的數組,並且每個元素比較要用OR連接起來。
ScanKey也可以描述 “column IS NULL” 或者 “column IS NOT NULL”,
這些情況下會通過 SK_SEARCHNULL 和SK_SEARCHNOTNULL 各自標識
參數爲null時 sk_strategy, sk_subtype, sk_collation, 以及sk_func 經常不被使用(除非被 index AM設置)。
只有在索引掃描情況下 SK_SEARCHARRAY, SK_SEARCHNULL 和 SK_SEARCHNOTNULL 才被支持
而且並不是所有的 index AMs 都支持他們,只有分別設置amsearcharray 或者 amsearchnulls時。.
ScanKey 也可以描述一個順序操作符,例如 “ORDER BY indexedcol op constant”的調用,除了(通常)不產生bool運算符,它看起來跟比較運算符是相同的。我們會標識ScanKeys 爲SK_ORDER_BY,但是這裏不能使用 SK_SEARCHARRAY, SK_SEARCHNULL, SK_SEARCHNOTNULL
注意:
一些情況下,ScanKeys 被用來方便的調用程序支持的函數,在這種情況下sk_strategy/sk_subtype 是沒有意義的,(但是sk_collation 可以有)
並且 sk_func 可能會引用一些函數,返回不是bool的其他值。
typedef struct ScanKeyData
{
int sk_flags; /* 標識符 */
AttrNumber sk_attno; /* 表或者索引列 */
StrategyNumber sk_strategy; /* 操作符策略值 */
Oid sk_subtype; /* strategy subtype */
Oid sk_collation; /* 如果需要,會使用校驗值 */
FmgrInfo sk_func; /* 查找函數調用 */
Datum sk_argument; /* 比較的數據 */
} ScanKeyData;
typedef ScanKeyData *ScanKey;
原版
/*
* A ScanKey represents the application of a comparison operator between
* a table or index column and a constant. When it's part of an array of
* ScanKeys, the comparison conditions are implicitly ANDed. The index
* column is the left argument of the operator, if it's a binary operator.
* (The data structure can support unary indexable operators too; in that
* case sk_argument would go unused. This is not currently implemented.)
*
* For an index scan, sk_strategy and sk_subtype must be set correctly for
* the operator. When using a ScanKey in a heap scan, these fields are not
* used and may be set to InvalidStrategy/InvalidOid.
*
* If the operator is collation-sensitive, sk_collation must be set
* correctly as well.
*
* A ScanKey can also represent a ScalarArrayOpExpr, that is a condition
* "column op ANY(ARRAY[...])". This is signaled by the SK_SEARCHARRAY
* flag bit. The sk_argument is not a value of the operator's right-hand
* argument type, but rather an array of such values, and the per-element
* comparisons are to be ORed together.
*
* A ScanKey can also represent a condition "column IS NULL" or "column
* IS NOT NULL"; these cases are signaled by the SK_SEARCHNULL and
* SK_SEARCHNOTNULL flag bits respectively. The argument is always NULL,
* and the sk_strategy, sk_subtype, sk_collation, and sk_func fields are
* not used (unless set by the index AM).
*
* SK_SEARCHARRAY, SK_SEARCHNULL and SK_SEARCHNOTNULL are supported only
* for index scans, not heap scans; and not all index AMs support them,
* only those that set amsearcharray or amsearchnulls respectively.
*
* A ScanKey can also represent an ordering operator invocation, that is
* an ordering requirement "ORDER BY indexedcol op constant". This looks
* the same as a comparison operator, except that the operator doesn't
* (usually) yield boolean. We mark such ScanKeys with SK_ORDER_BY.
* SK_SEARCHARRAY, SK_SEARCHNULL, SK_SEARCHNOTNULL cannot be used here.
*
* Note: in some places, ScanKeys are used as a convenient representation
* for the invocation of an access method support procedure. In this case
* sk_strategy/sk_subtype are not meaningful (but sk_collation can be); and
* sk_func may refer to a function that returns something other than boolean.
*/
typedef struct ScanKeyData
{
int sk_flags; /* flags, see below */
AttrNumber sk_attno; /* table or index column number */
StrategyNumber sk_strategy; /* operator strategy number */
Oid sk_subtype; /* strategy subtype */
Oid sk_collation; /* collation to use, if needed */
FmgrInfo sk_func; /* lookup info for function to call */
Datum sk_argument; /* data to compare */
} ScanKeyData;
typedef ScanKeyData *ScanKey;