PostgreSQL Source Code git master
Loading...
Searching...
No Matches
tsginidx.c File Reference
#include "postgres.h"
#include "access/gin.h"
#include "tsearch/ts_type.h"
#include "tsearch/ts_utils.h"
#include "utils/builtins.h"
#include "varatt.h"
Include dependency graph for tsginidx.c:

Go to the source code of this file.

Data Structures

struct  GinChkVal
 

Functions

Datum gin_cmp_tslexeme (PG_FUNCTION_ARGS)
 
Datum gin_cmp_prefix (PG_FUNCTION_ARGS)
 
Datum gin_extract_tsvector (PG_FUNCTION_ARGS)
 
Datum gin_extract_tsquery (PG_FUNCTION_ARGS)
 
static TSTernaryValue checkcondition_gin (void *checkval, QueryOperand *val, ExecPhraseData *data)
 
Datum gin_tsquery_consistent (PG_FUNCTION_ARGS)
 
Datum gin_tsquery_triconsistent (PG_FUNCTION_ARGS)
 
Datum gin_extract_tsvector_2args (PG_FUNCTION_ARGS)
 
Datum gin_extract_tsquery_5args (PG_FUNCTION_ARGS)
 
Datum gin_tsquery_consistent_6args (PG_FUNCTION_ARGS)
 
Datum gin_extract_tsquery_oldsig (PG_FUNCTION_ARGS)
 
Datum gin_tsquery_consistent_oldsig (PG_FUNCTION_ARGS)
 

Function Documentation

◆ checkcondition_gin()

static TSTernaryValue checkcondition_gin ( void checkval,
QueryOperand val,
ExecPhraseData data 
)
static

Definition at line 185 of file tsginidx.c.

186{
188 int j;
189 GinTernaryValue result;
190
191 /* convert item's number to corresponding entry's (operand's) number */
192 j = gcv->map_item_operand[((QueryItem *) val) - gcv->first_item];
193
194 /* determine presence of current entry in indexed value */
195 result = gcv->check[j];
196
197 /*
198 * If any val requiring a weight is used or caller needs position
199 * information then we must recheck, so replace TRUE with MAYBE.
200 */
201 if (result == GIN_TRUE)
202 {
203 if (val->weight != 0 || data != NULL)
204 result = GIN_MAYBE;
205 }
206
207 /*
208 * We rely on GinTernaryValue and TSTernaryValue using equivalent value
209 * assignments. We could use a switch statement to map the values if that
210 * ever stops being true, but it seems unlikely to happen.
211 */
212 return (TSTernaryValue) result;
213}
char GinTernaryValue
Definition gin.h:71
#define GIN_MAYBE
Definition gin.h:78
#define GIN_TRUE
Definition gin.h:77
long val
Definition informix.c:689
int j
Definition isn.c:78
const void * data
static int fb(int x)
int * map_item_operand
Definition tsginidx.c:178
TSTernaryValue
Definition ts_utils.h:133

References data, fb(), GIN_MAYBE, GIN_TRUE, j, GinChkVal::map_item_operand, and val.

Referenced by gin_tsquery_consistent(), and gin_tsquery_triconsistent().

◆ gin_cmp_prefix()

Datum gin_cmp_prefix ( PG_FUNCTION_ARGS  )

Definition at line 40 of file tsginidx.c.

41{
44
45#ifdef NOT_USED
46 StrategyNumber strategy = PG_GETARG_UINT16(2);
47 Pointer extra_data = PG_GETARG_POINTER(3);
48#endif
49 int cmp;
50
53 true);
54
55 if (cmp < 0)
56 cmp = 1; /* prevent continue scan */
57
61}
void * Pointer
Definition c.h:537
#define PG_FREE_IF_COPY(ptr, n)
Definition fmgr.h:260
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_GETARG_UINT16(n)
Definition fmgr.h:272
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
int b
Definition isn.c:74
int a
Definition isn.c:73
static int cmp(const chr *x, const chr *y, size_t len)
uint16 StrategyNumber
Definition stratnum.h:22
Definition c.h:706
int32 tsCompareString(char *a, int lena, char *b, int lenb, bool prefix)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
Definition varatt.h:472
static char * VARDATA_ANY(const void *PTR)
Definition varatt.h:486

References a, b, cmp(), PG_FREE_IF_COPY, PG_GETARG_POINTER, PG_GETARG_TEXT_PP, PG_GETARG_UINT16, PG_RETURN_INT32, tsCompareString(), VARDATA_ANY(), and VARSIZE_ANY_EXHDR().

◆ gin_cmp_tslexeme()

◆ gin_extract_tsquery()

Datum gin_extract_tsquery ( PG_FUNCTION_ARGS  )

Definition at line 94 of file tsginidx.c.

95{
96 TSQuery query = PG_GETARG_TSQUERY(0);
97 int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
98#ifdef NOT_USED
99 StrategyNumber strategy = PG_GETARG_UINT16(2);
100#endif
101 bool **ptr_partialmatch = (bool **) PG_GETARG_POINTER(3);
102 Pointer **extra_data = (Pointer **) PG_GETARG_POINTER(4);
103#ifdef NOT_USED
104 bool **nullFlags = (bool **) PG_GETARG_POINTER(5);
105#endif
106 int32 *searchMode = (int32 *) PG_GETARG_POINTER(6);
107 Datum *entries = NULL;
108
109 *nentries = 0;
110
111 if (query->size > 0)
112 {
113 QueryItem *item = GETQUERY(query);
114 int32 i,
115 j;
116 bool *partialmatch;
117 int *map_item_operand;
118
119 /*
120 * If the query doesn't have any required positive matches (for
121 * instance, it's something like '! foo'), we have to do a full index
122 * scan.
123 */
124 if (tsquery_requires_match(item))
125 *searchMode = GIN_SEARCH_MODE_DEFAULT;
126 else
127 *searchMode = GIN_SEARCH_MODE_ALL;
128
129 /* count number of VAL items */
130 j = 0;
131 for (i = 0; i < query->size; i++)
132 {
133 if (item[i].type == QI_VAL)
134 j++;
135 }
136 *nentries = j;
137
138 entries = palloc_array(Datum, j);
140
141 /*
142 * Make map to convert item's number to corresponding operand's (the
143 * same, entry's) number. Entry's number is used in check array in
144 * consistent method. We use the same map for each entry.
145 */
146 *extra_data = palloc_array(Pointer, j);
147 map_item_operand = palloc0_array(int, query->size);
148
149 /* Now rescan the VAL items and fill in the arrays */
150 j = 0;
151 for (i = 0; i < query->size; i++)
152 {
153 if (item[i].type == QI_VAL)
154 {
155 QueryOperand *val = &item[i].qoperand;
156 text *txt;
157
158 txt = cstring_to_text_with_len(GETOPERAND(query) + val->distance,
159 val->length);
160 entries[j] = PointerGetDatum(txt);
161 partialmatch[j] = val->prefix;
162 (*extra_data)[j] = (Pointer) map_item_operand;
163 map_item_operand[i] = j;
164 j++;
165 }
166 }
167 }
168
169 PG_FREE_IF_COPY(query, 0);
170
171 PG_RETURN_POINTER(entries);
172}
#define GETQUERY(x)
Definition _int.h:157
int32_t int32
Definition c.h:542
#define palloc_array(type, count)
Definition fe_memutils.h:76
#define palloc0_array(type, count)
Definition fe_memutils.h:77
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
#define GIN_SEARCH_MODE_ALL
Definition gin.h:38
#define GIN_SEARCH_MODE_DEFAULT
Definition gin.h:36
int i
Definition isn.c:77
#define GETOPERAND(x)
Definition ltree.h:167
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
uint64_t Datum
Definition postgres.h:70
int32 size
Definition ts_type.h:221
#define PG_GETARG_TSQUERY(n)
Definition ts_type.h:266
#define QI_VAL
Definition ts_type.h:149
bool tsquery_requires_match(QueryItem *curitem)
QueryOperand qoperand
Definition ts_type.h:210
text * cstring_to_text_with_len(const char *s, int len)
Definition varlena.c:193
const char * type

References cstring_to_text_with_len(), fb(), GETOPERAND, GETQUERY, GIN_SEARCH_MODE_ALL, GIN_SEARCH_MODE_DEFAULT, i, j, palloc0_array, palloc_array, PG_FREE_IF_COPY, PG_GETARG_POINTER, PG_GETARG_TSQUERY, PG_GETARG_UINT16, PG_RETURN_POINTER, PointerGetDatum(), QI_VAL, QueryItem::qoperand, TSQueryData::size, tsquery_requires_match(), type, and val.

Referenced by gin_extract_tsquery_5args(), and gin_extract_tsquery_oldsig().

◆ gin_extract_tsquery_5args()

Datum gin_extract_tsquery_5args ( PG_FUNCTION_ARGS  )

Definition at line 322 of file tsginidx.c.

323{
324 if (PG_NARGS() < 7) /* should not happen */
325 elog(ERROR, "gin_extract_tsquery requires seven arguments");
326 return gin_extract_tsquery(fcinfo);
327}
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define PG_NARGS()
Definition fmgr.h:203
Datum gin_extract_tsquery(PG_FUNCTION_ARGS)
Definition tsginidx.c:94

References elog, ERROR, gin_extract_tsquery(), and PG_NARGS.

◆ gin_extract_tsquery_oldsig()

Datum gin_extract_tsquery_oldsig ( PG_FUNCTION_ARGS  )

Definition at line 346 of file tsginidx.c.

347{
348 return gin_extract_tsquery(fcinfo);
349}

References gin_extract_tsquery().

◆ gin_extract_tsvector()

Datum gin_extract_tsvector ( PG_FUNCTION_ARGS  )

Definition at line 64 of file tsginidx.c.

65{
66 TSVector vector = PG_GETARG_TSVECTOR(0);
67 int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
68 Datum *entries = NULL;
69
70 *nentries = vector->size;
71 if (vector->size > 0)
72 {
73 int i;
74 WordEntry *we = ARRPTR(vector);
75
76 entries = palloc_array(Datum, vector->size);
77
78 for (i = 0; i < vector->size; i++)
79 {
80 text *txt;
81
82 txt = cstring_to_text_with_len(STRPTR(vector) + we->pos, we->len);
83 entries[i] = PointerGetDatum(txt);
84
85 we++;
86 }
87 }
88
89 PG_FREE_IF_COPY(vector, 0);
90 PG_RETURN_POINTER(entries);
91}
#define ARRPTR(x)
Definition cube.c:28
#define STRPTR(x)
Definition hstore.h:76
int32 size
Definition ts_type.h:93
#define PG_GETARG_TSVECTOR(n)
Definition ts_type.h:135

References ARRPTR, cstring_to_text_with_len(), fb(), i, palloc_array, PG_FREE_IF_COPY, PG_GETARG_POINTER, PG_GETARG_TSVECTOR, PG_RETURN_POINTER, PointerGetDatum(), TSVectorData::size, and STRPTR.

Referenced by gin_extract_tsvector_2args().

◆ gin_extract_tsvector_2args()

Datum gin_extract_tsvector_2args ( PG_FUNCTION_ARGS  )

Definition at line 310 of file tsginidx.c.

311{
312 if (PG_NARGS() < 3) /* should not happen */
313 elog(ERROR, "gin_extract_tsvector requires three arguments");
314 return gin_extract_tsvector(fcinfo);
315}
Datum gin_extract_tsvector(PG_FUNCTION_ARGS)
Definition tsginidx.c:64

References elog, ERROR, gin_extract_tsvector(), and PG_NARGS.

◆ gin_tsquery_consistent()

Datum gin_tsquery_consistent ( PG_FUNCTION_ARGS  )

Definition at line 216 of file tsginidx.c.

217{
218 bool *check = (bool *) PG_GETARG_POINTER(0);
219#ifdef NOT_USED
220 StrategyNumber strategy = PG_GETARG_UINT16(1);
221#endif
222 TSQuery query = PG_GETARG_TSQUERY(2);
223#ifdef NOT_USED
224 int32 nkeys = PG_GETARG_INT32(3);
225#endif
226 Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4);
227 bool *recheck = (bool *) PG_GETARG_POINTER(5);
228 bool res = false;
229
230 /* Initially assume query doesn't require recheck */
231 *recheck = false;
232
233 if (query->size > 0)
234 {
236
237 /*
238 * check-parameter array has one entry for each value (operand) in the
239 * query.
240 */
241 gcv.first_item = GETQUERY(query);
242 gcv.check = (GinTernaryValue *) check;
243 gcv.map_item_operand = (int *) (extra_data[0]);
244
245 switch (TS_execute_ternary(GETQUERY(query),
246 &gcv,
249 {
250 case TS_NO:
251 res = false;
252 break;
253 case TS_YES:
254 res = true;
255 break;
256 case TS_MAYBE:
257 res = true;
258 *recheck = true;
259 break;
260 }
261 }
262
263 PG_RETURN_BOOL(res);
264}
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
QueryItem * first_item
Definition tsginidx.c:176
#define TS_EXEC_PHRASE_NO_POS
Definition ts_utils.h:202
@ TS_MAYBE
Definition ts_utils.h:136
@ TS_NO
Definition ts_utils.h:134
@ TS_YES
Definition ts_utils.h:135
static TSTernaryValue checkcondition_gin(void *checkval, QueryOperand *val, ExecPhraseData *data)
Definition tsginidx.c:185
TSTernaryValue TS_execute_ternary(QueryItem *curitem, void *arg, uint32 flags, TSExecuteCallback chkcond)

References checkcondition_gin(), fb(), GinChkVal::first_item, GETQUERY, PG_GETARG_INT32, PG_GETARG_POINTER, PG_GETARG_TSQUERY, PG_GETARG_UINT16, PG_RETURN_BOOL, TSQueryData::size, TS_EXEC_PHRASE_NO_POS, TS_execute_ternary(), TS_MAYBE, TS_NO, and TS_YES.

Referenced by gin_tsquery_consistent_6args(), and gin_tsquery_consistent_oldsig().

◆ gin_tsquery_consistent_6args()

Datum gin_tsquery_consistent_6args ( PG_FUNCTION_ARGS  )

Definition at line 334 of file tsginidx.c.

335{
336 if (PG_NARGS() < 8) /* should not happen */
337 elog(ERROR, "gin_tsquery_consistent requires eight arguments");
338 return gin_tsquery_consistent(fcinfo);
339}
Datum gin_tsquery_consistent(PG_FUNCTION_ARGS)
Definition tsginidx.c:216

References elog, ERROR, gin_tsquery_consistent(), and PG_NARGS.

◆ gin_tsquery_consistent_oldsig()

Datum gin_tsquery_consistent_oldsig ( PG_FUNCTION_ARGS  )

Definition at line 356 of file tsginidx.c.

357{
358 return gin_tsquery_consistent(fcinfo);
359}

References gin_tsquery_consistent().

◆ gin_tsquery_triconsistent()

Datum gin_tsquery_triconsistent ( PG_FUNCTION_ARGS  )

Definition at line 267 of file tsginidx.c.

268{
270#ifdef NOT_USED
271 StrategyNumber strategy = PG_GETARG_UINT16(1);
272#endif
273 TSQuery query = PG_GETARG_TSQUERY(2);
274#ifdef NOT_USED
275 int32 nkeys = PG_GETARG_INT32(3);
276#endif
277 Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4);
279
280 if (query->size > 0)
281 {
283
284 /*
285 * check-parameter array has one entry for each value (operand) in the
286 * query.
287 */
288 gcv.first_item = GETQUERY(query);
289 gcv.check = check;
290 gcv.map_item_operand = (int *) (extra_data[0]);
291
292 res = TS_execute_ternary(GETQUERY(query),
293 &gcv,
296 }
297
299}
#define PG_RETURN_GIN_TERNARY_VALUE(x)
Definition gin.h:92
#define GIN_FALSE
Definition gin.h:76

References checkcondition_gin(), fb(), GinChkVal::first_item, GETQUERY, GIN_FALSE, PG_GETARG_INT32, PG_GETARG_POINTER, PG_GETARG_TSQUERY, PG_GETARG_UINT16, PG_RETURN_GIN_TERNARY_VALUE, TSQueryData::size, TS_EXEC_PHRASE_NO_POS, and TS_execute_ternary().