6
#include "access/gin.h"
7
#include "access/itup.h"
8
#include "access/tuptoaster.h"
9
#include "storage/bufpage.h"
10
#include "utils/array.h"
11
#include "utils/builtins.h"
13
PG_FUNCTION_INFO_V1(gin_extract_trgm);
14
Datum gin_extract_trgm(PG_FUNCTION_ARGS);
16
PG_FUNCTION_INFO_V1(gin_trgm_consistent);
17
Datum gin_trgm_consistent(PG_FUNCTION_ARGS);
20
gin_extract_trgm(PG_FUNCTION_ARGS)
22
text *val = (text *) PG_GETARG_TEXT_P(0);
23
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
24
Datum *entries = NULL;
30
trg = generate_trgm(VARDATA(val), VARSIZE(val) - VARHDRSZ);
31
trglen = ARRNELEM(trg);
39
*nentries = (int32) trglen;
40
entries = (Datum *) palloc(sizeof(Datum) * trglen);
43
while (ptr - GETARR(trg) < ARRNELEM(trg))
46
entries[i++] = Int32GetDatum(item);
53
* Function called from query extracting
55
Pointer **extra_data = (Pointer **) PG_GETARG_POINTER(4);
57
*extra_data = (Pointer*) palloc0(sizeof(Pointer)*(*nentries));
59
*(int32*)(*extra_data) = trglen;
63
PG_RETURN_POINTER(entries);
67
gin_trgm_consistent(PG_FUNCTION_ARGS)
69
bool *check = (bool *) PG_GETARG_POINTER(0);
70
/* StrategyNumber strategy = PG_GETARG_UINT16(1); */
71
/* text *query = PG_GETARG_TEXT_P(2); */
72
/* int32 nkeys = PG_GETARG_INT32(3); */
73
Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4);
74
bool *recheck = (bool *) PG_GETARG_POINTER(5);
80
/* All cases served by this function are inexact */
83
trglen = *(int32*)extra_data;
85
for (i = 0; i < trglen; i++)
90
res = (trglen == ntrue) ? true : ((((((float4) ntrue) / ((float4) (trglen - ntrue)))) >= trgm_limit) ? true : false);
92
res = (trglen == 0) ? false : ((((((float4) ntrue) / ((float4) trglen))) >= trgm_limit) ? true : false);