Skip to content

Commit be0c3ea

Browse files
committed
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.
1 parent ba39896 commit be0c3ea

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

contrib/pg_trgm/trgm_gin.c

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ Datum gin_extract_trgm(PG_FUNCTION_ARGS);
1919
PG_FUNCTION_INFO_V1(gin_trgm_consistent);
2020
Datum gin_trgm_consistent(PG_FUNCTION_ARGS);
2121

22+
/*
23+
* This function is used as both extractValue and extractQuery
24+
*/
2225
Datum
2326
gin_extract_trgm(PG_FUNCTION_ARGS)
2427
{
2528
text *val = (text *) PG_GETARG_TEXT_P(0);
2629
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
2730
Datum *entries = NULL;
2831
TRGM *trg;
29-
int4 trglen;
32+
int32 trglen;
3033

3134
*nentries = 0;
3235

@@ -36,31 +39,19 @@ gin_extract_trgm(PG_FUNCTION_ARGS)
3639
if (trglen > 0)
3740
{
3841
trgm *ptr;
39-
int4 i = 0,
40-
item;
42+
int32 i;
4143

42-
*nentries = (int32) trglen;
44+
*nentries = trglen;
4345
entries = (Datum *) palloc(sizeof(Datum) * trglen);
4446

4547
ptr = GETARR(trg);
46-
while (ptr - GETARR(trg) < ARRNELEM(trg))
48+
for (i = 0; i < trglen; i++)
4749
{
48-
item = trgm2int(ptr);
49-
entries[i++] = Int32GetDatum(item);
50+
int32 item = trgm2int(ptr);
5051

52+
entries[i] = Int32GetDatum(item);
5153
ptr++;
5254
}
53-
if (PG_NARGS() > 4)
54-
{
55-
/*
56-
* Function called from query extracting
57-
*/
58-
Pointer **extra_data = (Pointer **) PG_GETARG_POINTER(4);
59-
60-
*extra_data = (Pointer *) palloc0(sizeof(Pointer) * (*nentries));
61-
62-
*(int32 *) (*extra_data) = trglen;
63-
}
6455
}
6556

6657
PG_RETURN_POINTER(entries);
@@ -70,30 +61,29 @@ Datum
7061
gin_trgm_consistent(PG_FUNCTION_ARGS)
7162
{
7263
bool *check = (bool *) PG_GETARG_POINTER(0);
73-
7464
/* StrategyNumber strategy = PG_GETARG_UINT16(1); */
7565
/* text *query = PG_GETARG_TEXT_P(2); */
76-
/* int32 nkeys = PG_GETARG_INT32(3); */
77-
Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4);
66+
int32 nkeys = PG_GETARG_INT32(3);
67+
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
7868
bool *recheck = (bool *) PG_GETARG_POINTER(5);
7969
bool res = FALSE;
80-
int4 i,
81-
trglen,
70+
int32 i,
8271
ntrue = 0;
8372

8473
/* All cases served by this function are inexact */
8574
*recheck = true;
8675

87-
trglen = *(int32 *) extra_data;
88-
89-
for (i = 0; i < trglen; i++)
76+
/* Count the matches */
77+
for (i = 0; i < nkeys; i++)
78+
{
9079
if (check[i])
9180
ntrue++;
81+
}
9282

9383
#ifdef DIVUNION
94-
res = (trglen == ntrue) ? true : ((((((float4) ntrue) / ((float4) (trglen - ntrue)))) >= trgm_limit) ? true : false);
84+
res = (nkeys == ntrue) ? true : ((((((float4) ntrue) / ((float4) (nkeys - ntrue)))) >= trgm_limit) ? true : false);
9585
#else
96-
res = (trglen == 0) ? false : ((((((float4) ntrue) / ((float4) trglen))) >= trgm_limit) ? true : false);
86+
res = (nkeys == 0) ? false : ((((((float4) ntrue) / ((float4) nkeys))) >= trgm_limit) ? true : false);
9787
#endif
9888

9989
PG_RETURN_BOOL(res);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy