Commit be0c3ea2 authored by Tom Lane's avatar Tom Lane

Update contrib/pg_trgm for new GIN extractQuery API.

No actual change in functionality ... just get rid of uselessly complex
code to pass the number of keys via extra_data.
parent ba398969
...@@ -19,6 +19,9 @@ Datum gin_extract_trgm(PG_FUNCTION_ARGS); ...@@ -19,6 +19,9 @@ Datum gin_extract_trgm(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(gin_trgm_consistent); PG_FUNCTION_INFO_V1(gin_trgm_consistent);
Datum gin_trgm_consistent(PG_FUNCTION_ARGS); Datum gin_trgm_consistent(PG_FUNCTION_ARGS);
/*
* This function is used as both extractValue and extractQuery
*/
Datum Datum
gin_extract_trgm(PG_FUNCTION_ARGS) gin_extract_trgm(PG_FUNCTION_ARGS)
{ {
...@@ -26,7 +29,7 @@ gin_extract_trgm(PG_FUNCTION_ARGS) ...@@ -26,7 +29,7 @@ gin_extract_trgm(PG_FUNCTION_ARGS)
int32 *nentries = (int32 *) PG_GETARG_POINTER(1); int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
Datum *entries = NULL; Datum *entries = NULL;
TRGM *trg; TRGM *trg;
int4 trglen; int32 trglen;
*nentries = 0; *nentries = 0;
...@@ -36,31 +39,19 @@ gin_extract_trgm(PG_FUNCTION_ARGS) ...@@ -36,31 +39,19 @@ gin_extract_trgm(PG_FUNCTION_ARGS)
if (trglen > 0) if (trglen > 0)
{ {
trgm *ptr; trgm *ptr;
int4 i = 0, int32 i;
item;
*nentries = (int32) trglen; *nentries = trglen;
entries = (Datum *) palloc(sizeof(Datum) * trglen); entries = (Datum *) palloc(sizeof(Datum) * trglen);
ptr = GETARR(trg); ptr = GETARR(trg);
while (ptr - GETARR(trg) < ARRNELEM(trg)) for (i = 0; i < trglen; i++)
{ {
item = trgm2int(ptr); int32 item = trgm2int(ptr);
entries[i++] = Int32GetDatum(item);
entries[i] = Int32GetDatum(item);
ptr++; ptr++;
} }
if (PG_NARGS() > 4)
{
/*
* Function called from query extracting
*/
Pointer **extra_data = (Pointer **) PG_GETARG_POINTER(4);
*extra_data = (Pointer *) palloc0(sizeof(Pointer) * (*nentries));
*(int32 *) (*extra_data) = trglen;
}
} }
PG_RETURN_POINTER(entries); PG_RETURN_POINTER(entries);
...@@ -70,30 +61,29 @@ Datum ...@@ -70,30 +61,29 @@ Datum
gin_trgm_consistent(PG_FUNCTION_ARGS) gin_trgm_consistent(PG_FUNCTION_ARGS)
{ {
bool *check = (bool *) PG_GETARG_POINTER(0); bool *check = (bool *) PG_GETARG_POINTER(0);
/* StrategyNumber strategy = PG_GETARG_UINT16(1); */ /* StrategyNumber strategy = PG_GETARG_UINT16(1); */
/* text *query = PG_GETARG_TEXT_P(2); */ /* text *query = PG_GETARG_TEXT_P(2); */
/* int32 nkeys = PG_GETARG_INT32(3); */ int32 nkeys = PG_GETARG_INT32(3);
Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); /* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
bool *recheck = (bool *) PG_GETARG_POINTER(5); bool *recheck = (bool *) PG_GETARG_POINTER(5);
bool res = FALSE; bool res = FALSE;
int4 i, int32 i,
trglen,
ntrue = 0; ntrue = 0;
/* All cases served by this function are inexact */ /* All cases served by this function are inexact */
*recheck = true; *recheck = true;
trglen = *(int32 *) extra_data; /* Count the matches */
for (i = 0; i < nkeys; i++)
for (i = 0; i < trglen; i++) {
if (check[i]) if (check[i])
ntrue++; ntrue++;
}
#ifdef DIVUNION #ifdef DIVUNION
res = (trglen == ntrue) ? true : ((((((float4) ntrue) / ((float4) (trglen - ntrue)))) >= trgm_limit) ? true : false); res = (nkeys == ntrue) ? true : ((((((float4) ntrue) / ((float4) (nkeys - ntrue)))) >= trgm_limit) ? true : false);
#else #else
res = (trglen == 0) ? false : ((((((float4) ntrue) / ((float4) trglen))) >= trgm_limit) ? true : false); res = (nkeys == 0) ? false : ((((((float4) ntrue) / ((float4) nkeys))) >= trgm_limit) ? true : false);
#endif #endif
PG_RETURN_BOOL(res); PG_RETURN_BOOL(res);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment