PostgreSQL Source Code git master
Loading...
Searching...
No Matches
ts_type.h File Reference
#include "fmgr.h"
#include "utils/memutils.h"
Include dependency graph for ts_type.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  WordEntry
 
struct  WordEntryPosVector
 
struct  WordEntryPosVector1
 
struct  TSVectorData
 
struct  QueryOperand
 
struct  QueryOperator
 
union  QueryItem
 
struct  TSQueryData
 

Macros

#define MAXSTRLEN   ( (1<<11) - 1)
 
#define MAXSTRPOS   ( (1<<20) - 1)
 
#define WEP_GETWEIGHT(x)   ( (x) >> 14 )
 
#define WEP_GETPOS(x)   ( (x) & 0x3fff )
 
#define WEP_SETWEIGHT(x, v)   ( (x) = ( (v) << 14 ) | ( (x) & 0x3fff ) )
 
#define WEP_SETPOS(x, v)   ( (x) = ( (x) & 0xc000 ) | ( (v) & 0x3fff ) )
 
#define MAXENTRYPOS   (1<<14)
 
#define MAXNUMPOS   (256)
 
#define LIMITPOS(x)   ( ( (x) >= MAXENTRYPOS ) ? (MAXENTRYPOS-1) : (x) )
 
#define DATAHDRSIZE   (offsetof(TSVectorData, entries))
 
#define CALCDATASIZE(nentries, lenstr)   (DATAHDRSIZE + (nentries) * sizeof(WordEntry) + (lenstr) )
 
#define ARRPTR(x)   ( (x)->entries )
 
#define STRPTR(x)   ( (char *) &(x)->entries[(x)->size] )
 
#define _POSVECPTR(x, e)   ((WordEntryPosVector *)(STRPTR(x) + SHORTALIGN((e)->pos + (e)->len)))
 
#define POSDATALEN(x, e)   ( ( (e)->haspos ) ? (_POSVECPTR(x,e)->npos) : 0 )
 
#define POSDATAPTR(x, e)   (_POSVECPTR(x,e)->pos)
 
#define PG_GETARG_TSVECTOR(n)   DatumGetTSVector(PG_GETARG_DATUM(n))
 
#define PG_GETARG_TSVECTOR_COPY(n)   DatumGetTSVectorCopy(PG_GETARG_DATUM(n))
 
#define PG_RETURN_TSVECTOR(x)   return TSVectorGetDatum(x)
 
#define QI_VAL   1
 
#define QI_OPR   2
 
#define QI_VALSTOP
 
#define OP_NOT   1
 
#define OP_AND   2
 
#define OP_OR   3
 
#define OP_PHRASE   4 /* highest code, tsquery_cleanup.c */
 
#define OP_COUNT   4
 
#define OP_PRIORITY(x)   ( tsearch_op_priority[(x) - 1] )
 
#define QO_PRIORITY(x)   OP_PRIORITY(((QueryOperator *) (x))->oper)
 
#define HDRSIZETQ   ( VARHDRSZ + sizeof(int32) )
 
#define COMPUTESIZE(size, lenofoperand)   ( HDRSIZETQ + (size) * sizeof(QueryItem) + (lenofoperand) )
 
#define TSQUERY_TOO_BIG(size, lenofoperand)    ((size) > (MaxAllocSize - HDRSIZETQ - (lenofoperand)) / sizeof(QueryItem))
 
#define GETQUERY(x)   ((QueryItem*)( (char*)(x)+HDRSIZETQ ))
 
#define GETOPERAND(x)   ( (char*)GETQUERY(x) + ((TSQuery)(x))->size * sizeof(QueryItem) )
 
#define PG_GETARG_TSQUERY(n)   DatumGetTSQuery(PG_GETARG_DATUM(n))
 
#define PG_GETARG_TSQUERY_COPY(n)   DatumGetTSQueryCopy(PG_GETARG_DATUM(n))
 
#define PG_RETURN_TSQUERY(x)   return TSQueryGetDatum(x)
 

Typedefs

typedef uint16 WordEntryPos
 
typedef TSVectorDataTSVector
 
typedef int8 QueryItemType
 
typedef TSQueryDataTSQuery
 

Functions

int compareWordEntryPos (const void *a, const void *b)
 
static TSVector DatumGetTSVector (Datum X)
 
static TSVector DatumGetTSVectorCopy (Datum X)
 
static Datum TSVectorGetDatum (const TSVectorData *X)
 
static TSQuery DatumGetTSQuery (Datum X)
 
static TSQuery DatumGetTSQueryCopy (Datum X)
 
static Datum TSQueryGetDatum (const TSQueryData *X)
 

Variables

PGDLLIMPORT const int tsearch_op_priority [OP_COUNT]
 

Macro Definition Documentation

◆ _POSVECPTR

#define _POSVECPTR (   x,
  e 
)    ((WordEntryPosVector *)(STRPTR(x) + SHORTALIGN((e)->pos + (e)->len)))

Definition at line 109 of file ts_type.h.

◆ ARRPTR

#define ARRPTR (   x)    ( (x)->entries )

Definition at line 104 of file ts_type.h.

◆ CALCDATASIZE

#define CALCDATASIZE (   nentries,
  lenstr 
)    (DATAHDRSIZE + (nentries) * sizeof(WordEntry) + (lenstr) )

Definition at line 101 of file ts_type.h.

◆ COMPUTESIZE

#define COMPUTESIZE (   size,
  lenofoperand 
)    ( HDRSIZETQ + (size) * sizeof(QueryItem) + (lenofoperand) )

Definition at line 232 of file ts_type.h.

◆ DATAHDRSIZE

#define DATAHDRSIZE   (offsetof(TSVectorData, entries))

Definition at line 100 of file ts_type.h.

◆ GETOPERAND

#define GETOPERAND (   x)    ( (char*)GETQUERY(x) + ((TSQuery)(x))->size * sizeof(QueryItem) )

Definition at line 240 of file ts_type.h.

◆ GETQUERY

#define GETQUERY (   x)    ((QueryItem*)( (char*)(x)+HDRSIZETQ ))

Definition at line 237 of file ts_type.h.

◆ HDRSIZETQ

#define HDRSIZETQ   ( VARHDRSZ + sizeof(int32) )

Definition at line 227 of file ts_type.h.

◆ LIMITPOS

#define LIMITPOS (   x)    ( ( (x) >= MAXENTRYPOS ) ? (MAXENTRYPOS-1) : (x) )

Definition at line 87 of file ts_type.h.

◆ MAXENTRYPOS

#define MAXENTRYPOS   (1<<14)

Definition at line 85 of file ts_type.h.

◆ MAXNUMPOS

#define MAXNUMPOS   (256)

Definition at line 86 of file ts_type.h.

◆ MAXSTRLEN

#define MAXSTRLEN   ( (1<<11) - 1)

Definition at line 49 of file ts_type.h.

◆ MAXSTRPOS

#define MAXSTRPOS   ( (1<<20) - 1)

Definition at line 50 of file ts_type.h.

◆ OP_AND

#define OP_AND   2

Definition at line 180 of file ts_type.h.

◆ OP_COUNT

#define OP_COUNT   4

Definition at line 183 of file ts_type.h.

◆ OP_NOT

#define OP_NOT   1

Definition at line 179 of file ts_type.h.

◆ OP_OR

#define OP_OR   3

Definition at line 181 of file ts_type.h.

◆ OP_PHRASE

#define OP_PHRASE   4 /* highest code, tsquery_cleanup.c */

Definition at line 182 of file ts_type.h.

◆ OP_PRIORITY

#define OP_PRIORITY (   x)    ( tsearch_op_priority[(x) - 1] )

Definition at line 188 of file ts_type.h.

◆ PG_GETARG_TSQUERY

#define PG_GETARG_TSQUERY (   n)    DatumGetTSQuery(PG_GETARG_DATUM(n))

Definition at line 266 of file ts_type.h.

◆ PG_GETARG_TSQUERY_COPY

#define PG_GETARG_TSQUERY_COPY (   n)    DatumGetTSQueryCopy(PG_GETARG_DATUM(n))

Definition at line 267 of file ts_type.h.

◆ PG_GETARG_TSVECTOR

#define PG_GETARG_TSVECTOR (   n)    DatumGetTSVector(PG_GETARG_DATUM(n))

Definition at line 135 of file ts_type.h.

◆ PG_GETARG_TSVECTOR_COPY

#define PG_GETARG_TSVECTOR_COPY (   n)    DatumGetTSVectorCopy(PG_GETARG_DATUM(n))

Definition at line 136 of file ts_type.h.

◆ PG_RETURN_TSQUERY

#define PG_RETURN_TSQUERY (   x)    return TSQueryGetDatum(x)

Definition at line 268 of file ts_type.h.

◆ PG_RETURN_TSVECTOR

#define PG_RETURN_TSVECTOR (   x)    return TSVectorGetDatum(x)

Definition at line 137 of file ts_type.h.

◆ POSDATALEN

#define POSDATALEN (   x,
  e 
)    ( ( (e)->haspos ) ? (_POSVECPTR(x,e)->npos) : 0 )

Definition at line 110 of file ts_type.h.

◆ POSDATAPTR

#define POSDATAPTR (   x,
  e 
)    (_POSVECPTR(x,e)->pos)

Definition at line 111 of file ts_type.h.

◆ QI_OPR

#define QI_OPR   2

Definition at line 150 of file ts_type.h.

◆ QI_VAL

#define QI_VAL   1

Definition at line 149 of file ts_type.h.

◆ QI_VALSTOP

#define QI_VALSTOP
Value:
3 /* This is only used in an intermediate stack
* representation in parse_tsquery. It's not a
* legal type elsewhere. */

Definition at line 151 of file ts_type.h.

159{
160 QueryItemType type; /* operand or kind of operator (ts_tokentype) */
161 uint8 weight; /* weights of operand to search. It's a
162 * bitmask of allowed weights. if it =0 then
163 * any weight are allowed. Weights and bit
164 * map: A: 1<<3 B: 1<<2 C: 1<<1 D: 1<<0 */
165 bool prefix; /* true if it's a prefix search */
166 int32 valcrc; /* XXX: pg_crc32 would be a more appropriate
167 * data type, but we use comparisons to signed
168 * integers in the code. They would need to be
169 * changed as well. */
170
171 /* pointer to text value of operand, must correlate with WordEntry */
172 uint32
173 length:12,
174 distance:20;
176
177
178/*
179 * Legal values for QueryOperator.operator.
180 */
181#define OP_NOT 1
182#define OP_AND 2
183#define OP_OR 3
184#define OP_PHRASE 4 /* highest code, tsquery_cleanup.c */
185#define OP_COUNT 4
186
188
189/* get operation priority by its code */
190#define OP_PRIORITY(x) ( tsearch_op_priority[(x) - 1] )
191/* get QueryOperator priority */
192#define QO_PRIORITY(x) OP_PRIORITY(((QueryOperator *) (x))->oper)
193
194typedef struct
195{
197 int8 oper; /* see above */
198 int16 distance; /* distance between agrs for OP_PHRASE */
199 uint32 left; /* pointer to left operand. Right operand is
200 * item + 1, left operand is placed
201 * item+item->left */
203
204/*
205 * Note: TSQuery is 4-bytes aligned, so make sure there's no fields
206 * inside QueryItem requiring 8-byte alignment, like int64.
207 */
208typedef union
209{
211 QueryOperator qoperator;
212 QueryOperand qoperand;
213} QueryItem;
214
215/*
216 * Storage:
217 * (len)(size)(array of QueryItem)(operands as '\0'-terminated c-strings)
218 */
219
220typedef struct
221{
222 int32 vl_len_; /* varlena header (do not touch directly!) */
223 int32 size; /* number of QueryItems */
224 char data[FLEXIBLE_ARRAY_MEMBER]; /* data starts here */
226
227typedef TSQueryData *TSQuery;
228
229#define HDRSIZETQ ( VARHDRSZ + sizeof(int32) )
230
231/* Computes the size of header and all QueryItems. size is the number of
232 * QueryItems, and lenofoperand is the total length of all operands
233 */
234#define COMPUTESIZE(size, lenofoperand) ( HDRSIZETQ + (size) * sizeof(QueryItem) + (lenofoperand) )
235#define TSQUERY_TOO_BIG(size, lenofoperand) \
236 ((size) > (MaxAllocSize - HDRSIZETQ - (lenofoperand)) / sizeof(QueryItem))
237
238/* Returns a pointer to the first QueryItem in a TSQuery */
239#define GETQUERY(x) ((QueryItem*)( (char*)(x)+HDRSIZETQ ))
240
241/* Returns a pointer to the beginning of operands in a TSQuery */
242#define GETOPERAND(x) ( (char*)GETQUERY(x) + ((TSQuery)(x))->size * sizeof(QueryItem) )
243
244/*
245 * fmgr interface functions
246 * Note, TSQuery type marked as plain storage, so it can't be toasted
247 * but PG_DETOAST_DATUM_COPY is used for simplicity
248 */
249
250static inline TSQuery
252{
253 return (TSQuery) DatumGetPointer(X);
254}
255
256static inline TSQuery
258{
260}
261
262static inline Datum
264{
265 return PointerGetDatum(X);
266}
267
268#define PG_GETARG_TSQUERY(n) DatumGetTSQuery(PG_GETARG_DATUM(n))
269#define PG_GETARG_TSQUERY_COPY(n) DatumGetTSQueryCopy(PG_GETARG_DATUM(n))
270#define PG_RETURN_TSQUERY(x) return TSQueryGetDatum(x)
271
272#endif /* _PG_TSTYPE_H_ */
#define PGDLLIMPORT
Definition c.h:1334
uint8_t uint8
Definition c.h:544
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:480
int16_t int16
Definition c.h:541
int8_t int8
Definition c.h:540
int32_t int32
Definition c.h:542
uint32_t uint32
Definition c.h:546
#define PG_DETOAST_DATUM_COPY(datum)
Definition fmgr.h:242
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition parse_oper.c:371
const void * data
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
uint64_t Datum
Definition postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:342
static int fb(int x)
#define OP_COUNT
Definition ts_type.h:183
static TSQuery DatumGetTSQuery(Datum X)
Definition ts_type.h:249
TSQueryData * TSQuery
Definition ts_type.h:225
int8 QueryItemType
Definition ts_type.h:146
PGDLLIMPORT const int tsearch_op_priority[OP_COUNT]
Definition tsquery.c:29
static TSQuery DatumGetTSQueryCopy(Datum X)
Definition ts_type.h:255
static Datum TSQueryGetDatum(const TSQueryData *X)
Definition ts_type.h:261
const char * type

◆ QO_PRIORITY

#define QO_PRIORITY (   x)    OP_PRIORITY(((QueryOperator *) (x))->oper)

Definition at line 190 of file ts_type.h.

◆ STRPTR

#define STRPTR (   x)    ( (char *) &(x)->entries[(x)->size] )

Definition at line 107 of file ts_type.h.

◆ TSQUERY_TOO_BIG

#define TSQUERY_TOO_BIG (   size,
  lenofoperand 
)     ((size) > (MaxAllocSize - HDRSIZETQ - (lenofoperand)) / sizeof(QueryItem))

Definition at line 233 of file ts_type.h.

◆ WEP_GETPOS

#define WEP_GETPOS (   x)    ( (x) & 0x3fff )

Definition at line 80 of file ts_type.h.

◆ WEP_GETWEIGHT

#define WEP_GETWEIGHT (   x)    ( (x) >> 14 )

Definition at line 79 of file ts_type.h.

◆ WEP_SETPOS

#define WEP_SETPOS (   x,
 
)    ( (x) = ( (x) & 0xc000 ) | ( (v) & 0x3fff ) )

Definition at line 83 of file ts_type.h.

◆ WEP_SETWEIGHT

#define WEP_SETWEIGHT (   x,
 
)    ( (x) = ( (v) << 14 ) | ( (x) & 0x3fff ) )

Definition at line 82 of file ts_type.h.

Typedef Documentation

◆ QueryItemType

Definition at line 146 of file ts_type.h.

◆ TSQuery

Definition at line 225 of file ts_type.h.

◆ TSVector

Definition at line 98 of file ts_type.h.

◆ WordEntryPos

Definition at line 63 of file ts_type.h.

Function Documentation

◆ compareWordEntryPos()

int compareWordEntryPos ( const void a,
const void b 
)
extern

Definition at line 36 of file tsvector.c.

37{
38 int apos = WEP_GETPOS(*(const WordEntryPos *) a);
39 int bpos = WEP_GETPOS(*(const WordEntryPos *) b);
40
41 return pg_cmp_s32(apos, bpos);
42}
static int pg_cmp_s32(int32 a, int32 b)
Definition int.h:713
int b
Definition isn.c:74
int a
Definition isn.c:73
#define WEP_GETPOS(x)
Definition ts_type.h:80
uint16 WordEntryPos
Definition ts_type.h:63

References a, b, fb(), pg_cmp_s32(), and WEP_GETPOS.

Referenced by checkcondition_str(), and uniquePos().

◆ DatumGetTSQuery()

static TSQuery DatumGetTSQuery ( Datum  X)
inlinestatic

Definition at line 249 of file ts_type.h.

252{

References DatumGetPointer(), and fb().

Referenced by gtsquery_compress(), ts_match_tt(), tsquery_rewrite_query(), and tsquerysel().

◆ DatumGetTSQueryCopy()

static TSQuery DatumGetTSQueryCopy ( Datum  X)
inlinestatic

Definition at line 255 of file ts_type.h.

258{

References fb(), and PG_DETOAST_DATUM_COPY.

◆ DatumGetTSVector()

static TSVector DatumGetTSVector ( Datum  X)
inlinestatic

Definition at line 118 of file ts_type.h.

119{
120 return (TSVector) PG_DETOAST_DATUM(X);
121}
#define PG_DETOAST_DATUM(datum)
Definition fmgr.h:240

References fb(), and PG_DETOAST_DATUM.

Referenced by compute_tsvector_stats(), gtsvector_compress(), ts_accum(), ts_match_tq(), and ts_match_tt().

◆ DatumGetTSVectorCopy()

static TSVector DatumGetTSVectorCopy ( Datum  X)
inlinestatic

Definition at line 124 of file ts_type.h.

125{
127}

References fb(), and PG_DETOAST_DATUM_COPY.

◆ TSQueryGetDatum()

static Datum TSQueryGetDatum ( const TSQueryData X)
inlinestatic

Definition at line 261 of file ts_type.h.

264{

References fb(), and PointerGetDatum().

Referenced by ts_match_tq(), and ts_match_tt().

◆ TSVectorGetDatum()

static Datum TSVectorGetDatum ( const TSVectorData X)
inlinestatic

Definition at line 130 of file ts_type.h.

131{
132 return PointerGetDatum(X);
133}

References fb(), and PointerGetDatum().

Referenced by compute_tsvector_stats(), ts_match_tq(), ts_match_tt(), and tsvector_update_trigger().

Variable Documentation

◆ tsearch_op_priority

PGDLLIMPORT const int tsearch_op_priority[OP_COUNT]
extern

Definition at line 29 of file tsquery.c.

30{
31 4, /* OP_NOT */
32 2, /* OP_AND */
33 1, /* OP_OR */
34 3 /* OP_PHRASE */
35};