2 * contrib/pg_trgm/trgm_gin.c
19 * This function can only be called if a pre-9.1 version of the GIN operator
20 * class definition is present in the catalogs (probably as a consequence
21 * of upgrade-in-place). Cope.
30 elog(
ERROR,
"unexpected number of arguments to gin_extract_trgm");
39 Datum *entries = NULL;
57 for (
i = 0;
i < trglen;
i++)
76 /* bool **pmatch = (bool **) PG_GETARG_POINTER(3); */
79 /* bool **nullFlags = (bool **) PG_GETARG_POINTER(5); */
81 Datum *entries = NULL;
98 elog(
ERROR,
"cannot handle ~~* with case-sensitive trigrams");
104 * For wildcard search we extract all the trigrams that every
105 * potentially-matching string must include.
112 elog(
ERROR,
"cannot handle ~* with case-sensitive trigrams");
121 * Successful regex processing: store NFA-like graph as
122 * extra_data. GIN API requires an array of nentries
123 * Pointers, but we just put the same value in each element.
127 for (
i = 0;
i < trglen;
i++)
132 /* No result: have to do full index scan. */
139 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
140 trg = NULL;
/* keep compiler quiet */
151 for (
i = 0;
i < trglen;
i++)
161 * If no trigram was extracted then we have to scan all the index.
175 /* text *query = PG_GETARG_TEXT_PP(2); */
184 /* All cases served by this function are inexact */
194 /* Count the matches */
196 for (
i = 0;
i < nkeys;
i++)
202 /*--------------------
203 * If DIVUNION is defined then similarity formula is:
204 * c / (len1 + len2 - c)
205 * where c is number of common trigrams and it stands as ntrue in
206 * this code. Here we don't know value of len2 but we can assume
207 * that c (ntrue) is a lower bound of len2, so upper bound of
209 * c / (len1 + c - c) => c / len1
210 * If DIVUNION is not defined then similarity formula is:
211 * c / max(len1, len2)
212 * And again, c (ntrue) is a lower bound of len2, but c <= len1
213 * just by definition and, consequently, upper bound of
214 * similarity is just c / len1.
215 * So, independently on DIVUNION the upper bound formula is the same.
217 res = (nkeys == 0) ?
false :
222 elog(
ERROR,
"cannot handle ~~* with case-sensitive trigrams");
227 /* Check if all extracted trigrams are presented. */
229 for (
i = 0;
i < nkeys;
i++)
240 elog(
ERROR,
"cannot handle ~* with case-sensitive trigrams");
246 /* Regex processing gave no result: do full index scan */
254 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
255 res =
false;
/* keep compiler quiet */
263 * In all cases, GIN_TRUE is at least as favorable to inclusion as
264 * GIN_MAYBE. If no better option is available, simply treat
265 * GIN_MAYBE as if it were GIN_TRUE and apply the same test as the binary
266 * consistent function.
274 /* text *query = PG_GETARG_TEXT_PP(2); */
290 /* Count the matches */
292 for (
i = 0;
i < nkeys;
i++)
299 * See comment in gin_trgm_consistent() about * upper bound
308 elog(
ERROR,
"cannot handle ~~* with case-sensitive trigrams");
313 /* Check if all extracted trigrams are presented. */
315 for (
i = 0;
i < nkeys;
i++)
326 elog(
ERROR,
"cannot handle ~* with case-sensitive trigrams");
332 /* Regex processing gave no result: do full index scan */
338 * As trigramsMatchGraph implements a monotonic boolean
339 * function, promoting all GIN_MAYBE keys to GIN_TRUE will
340 * give a conservative result.
342 boolcheck = (
bool *)
palloc(
sizeof(
bool) * nkeys);
343 for (
i = 0;
i < nkeys;
i++)
352 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
353 res =
GIN_FALSE;
/* keep compiler quiet */
357 /* All cases served by this function are inexact */
#define PG_GETARG_TEXT_PP(n)
#define PG_GETARG_POINTER(n)
#define PG_GETARG_UINT16(n)
#define PG_GETARG_INT32(n)
#define PG_RETURN_POINTER(x)
#define PG_GET_COLLATION()
#define PG_RETURN_BOOL(x)
#define PG_RETURN_GIN_TERNARY_VALUE(x)
#define GIN_SEARCH_MODE_ALL
Assert(PointerIsAligned(start, uint64))
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
static Datum Int32GetDatum(int32 X)
#define RegExpICaseStrategyNumber
#define WordSimilarityStrategyNumber
TRGM * generate_trgm(char *str, int slen)
#define StrictWordSimilarityStrategyNumber
uint32 trgm2int(trgm *ptr)
double index_strategy_get_limit(StrategyNumber strategy)
TRGM * createTrgmNFA(text *text_re, Oid collation, TrgmPackedGraph **graph, MemoryContext rcontext)
#define SimilarityStrategyNumber
bool trigramsMatchGraph(TrgmPackedGraph *graph, bool *check)
#define ILikeStrategyNumber
TRGM * generate_wildcard_trgm(const char *str, int slen)
#define LikeStrategyNumber
#define EqualStrategyNumber
#define RegExpStrategyNumber
Datum gin_trgm_consistent(PG_FUNCTION_ARGS)
Datum gin_trgm_triconsistent(PG_FUNCTION_ARGS)
Datum gin_extract_value_trgm(PG_FUNCTION_ARGS)
Datum gin_extract_query_trgm(PG_FUNCTION_ARGS)
Datum gin_extract_trgm(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(gin_extract_trgm)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static char * VARDATA_ANY(const void *PTR)