1996-08-27 23:50:29 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* skey.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* POSTGRES scan key definitions.
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*
|
2010-01-02 17:58:17 +01:00
|
|
|
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
2010-01-02 17:58:17 +01:00
|
|
|
* $PostgreSQL: pgsql/src/include/access/skey.h,v 1.39 2010/01/02 16:58:00 momjian Exp $
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef SKEY_H
|
1996-08-27 23:50:29 +02:00
|
|
|
#define SKEY_H
|
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "access/attnum.h"
|
|
|
|
#include "fmgr.h"
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2001-06-09 20:16:59 +02:00
|
|
|
|
2003-11-09 22:30:38 +01:00
|
|
|
/*
|
|
|
|
* Strategy numbers identify the semantics that particular operators have
|
2003-11-12 22:15:59 +01:00
|
|
|
* with respect to particular operator classes. In some cases a strategy
|
|
|
|
* subtype (an OID) is used as further information.
|
2003-11-09 22:30:38 +01:00
|
|
|
*/
|
|
|
|
typedef uint16 StrategyNumber;
|
|
|
|
|
|
|
|
#define InvalidStrategy ((StrategyNumber) 0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We define the strategy numbers for B-tree indexes here, to avoid having
|
|
|
|
* to import access/nbtree.h into a lot of places that shouldn't need it.
|
|
|
|
*/
|
|
|
|
#define BTLessStrategyNumber 1
|
|
|
|
#define BTLessEqualStrategyNumber 2
|
|
|
|
#define BTEqualStrategyNumber 3
|
|
|
|
#define BTGreaterEqualStrategyNumber 4
|
|
|
|
#define BTGreaterStrategyNumber 5
|
|
|
|
|
|
|
|
#define BTMaxStrategyNumber 5
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A ScanKey represents the application of a comparison operator between
|
2004-08-29 07:07:03 +02:00
|
|
|
* a table or index column and a constant. When it's part of an array of
|
2003-11-09 22:30:38 +01:00
|
|
|
* 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.)
|
|
|
|
*
|
2003-11-12 22:15:59 +01:00
|
|
|
* 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.
|
2003-11-09 22:30:38 +01:00
|
|
|
*
|
2010-01-01 22:53:49 +01:00
|
|
|
* 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,
|
2007-04-07 00:33:43 +02:00
|
|
|
* and the sk_strategy, sk_subtype, and sk_func fields are not used (unless
|
2010-01-01 22:53:49 +01:00
|
|
|
* set by the index AM). Currently, SK_SEARCHNULL and SK_SEARCHNOTNULL are
|
|
|
|
* supported only for index scans, not heap scans; and not all index AMs
|
|
|
|
* support them.
|
2007-04-07 00:33:43 +02:00
|
|
|
*
|
2003-11-09 22:30:38 +01:00
|
|
|
* Note: in some places, ScanKeys are used as a convenient representation
|
|
|
|
* for the invocation of an access method support procedure. In this case
|
2003-11-12 22:15:59 +01:00
|
|
|
* sk_strategy/sk_subtype are not meaningful, and sk_func may refer to a
|
|
|
|
* function that returns something other than boolean.
|
2003-11-09 22:30:38 +01:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct ScanKeyData
|
|
|
|
{
|
2003-11-09 22:30:38 +01:00
|
|
|
int sk_flags; /* flags, see below */
|
|
|
|
AttrNumber sk_attno; /* table or index column number */
|
2004-08-29 07:07:03 +02:00
|
|
|
StrategyNumber sk_strategy; /* operator strategy number */
|
2003-11-12 22:15:59 +01:00
|
|
|
Oid sk_subtype; /* strategy subtype */
|
2003-11-09 22:30:38 +01:00
|
|
|
FmgrInfo sk_func; /* lookup info for function to call */
|
1997-09-08 04:41:22 +02:00
|
|
|
Datum sk_argument; /* data to compare */
|
1997-09-08 23:56:23 +02:00
|
|
|
} ScanKeyData;
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef ScanKeyData *ScanKey;
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2006-01-25 21:29:24 +01:00
|
|
|
/*
|
|
|
|
* About row comparisons:
|
|
|
|
*
|
|
|
|
* The ScanKey data structure also supports row comparisons, that is ordered
|
|
|
|
* tuple comparisons like (x, y) > (c1, c2), having the SQL-spec semantics
|
|
|
|
* "x > c1 OR (x = c1 AND y > c2)". Note that this is currently only
|
|
|
|
* implemented for btree index searches, not for heapscans or any other index
|
|
|
|
* type. A row comparison is represented by a "header" ScanKey entry plus
|
|
|
|
* a separate array of ScanKeys, one for each column of the row comparison.
|
|
|
|
* The header entry has these properties:
|
|
|
|
* sk_flags = SK_ROW_HEADER
|
|
|
|
* sk_attno = index column number for leading column of row comparison
|
|
|
|
* sk_strategy = btree strategy code for semantics of row comparison
|
|
|
|
* (ie, < <= > or >=)
|
|
|
|
* sk_subtype, sk_func: not used
|
|
|
|
* sk_argument: pointer to subsidiary ScanKey array
|
|
|
|
* If the header is part of a ScanKey array that's sorted by attno, it
|
|
|
|
* must be sorted according to the leading column number.
|
|
|
|
*
|
|
|
|
* The subsidiary ScanKey array appears in logical column order of the row
|
2006-10-04 02:30:14 +02:00
|
|
|
* comparison, which may be different from index column order. The array
|
2006-01-25 21:29:24 +01:00
|
|
|
* elements are like a normal ScanKey array except that:
|
|
|
|
* sk_flags must include SK_ROW_MEMBER, plus SK_ROW_END in the last
|
|
|
|
* element (needed since row header does not include a count)
|
|
|
|
* sk_func points to the btree comparison support function for the
|
|
|
|
* opclass, NOT the operator's implementation function.
|
|
|
|
* sk_strategy must be the same in all elements of the subsidiary array,
|
|
|
|
* that is, the same as in the header entry.
|
|
|
|
*/
|
|
|
|
|
2006-01-14 23:03:35 +01:00
|
|
|
/*
|
|
|
|
* ScanKeyData sk_flags
|
|
|
|
*
|
|
|
|
* sk_flags bits 0-15 are reserved for system-wide use (symbols for those
|
|
|
|
* bits should be defined here). Bits 16-31 are reserved for use within
|
|
|
|
* individual index access methods.
|
|
|
|
*/
|
2010-01-01 22:53:49 +01:00
|
|
|
#define SK_ISNULL 0x0001 /* sk_argument is NULL */
|
|
|
|
#define SK_UNARY 0x0002 /* unary operator (not supported!) */
|
|
|
|
#define SK_ROW_HEADER 0x0004 /* row comparison header (see above) */
|
|
|
|
#define SK_ROW_MEMBER 0x0008 /* row comparison member (see above) */
|
|
|
|
#define SK_ROW_END 0x0010 /* last row comparison member */
|
|
|
|
#define SK_SEARCHNULL 0x0020 /* scankey represents "col IS NULL" */
|
|
|
|
#define SK_SEARCHNOTNULL 0x0040 /* scankey represents "col IS NOT NULL" */
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes for functions in access/common/scankey.c
|
|
|
|
*/
|
2003-11-12 22:15:59 +01:00
|
|
|
extern void ScanKeyInit(ScanKey entry,
|
2004-08-29 07:07:03 +02:00
|
|
|
AttrNumber attributeNumber,
|
|
|
|
StrategyNumber strategy,
|
|
|
|
RegProcedure procedure,
|
|
|
|
Datum argument);
|
2003-11-09 22:30:38 +01:00
|
|
|
extern void ScanKeyEntryInitialize(ScanKey entry,
|
2004-08-29 07:07:03 +02:00
|
|
|
int flags,
|
|
|
|
AttrNumber attributeNumber,
|
|
|
|
StrategyNumber strategy,
|
|
|
|
Oid subtype,
|
|
|
|
RegProcedure procedure,
|
|
|
|
Datum argument);
|
2003-11-09 22:30:38 +01:00
|
|
|
extern void ScanKeyEntryInitializeWithInfo(ScanKey entry,
|
2004-08-29 07:07:03 +02:00
|
|
|
int flags,
|
|
|
|
AttrNumber attributeNumber,
|
|
|
|
StrategyNumber strategy,
|
|
|
|
Oid subtype,
|
|
|
|
FmgrInfo *finfo,
|
|
|
|
Datum argument);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* SKEY_H */
|