|
1 | 1 | /*
|
2 |
| - * $PostgreSQL: pgsql/contrib/pg_trgm/trgm_gin.c,v 1.6 2008/11/12 13:43:54 teodor Exp $ |
| 2 | + * $PostgreSQL: pgsql/contrib/pg_trgm/trgm_gin.c,v 1.7 2009/03/25 22:19:01 tgl Exp $ |
3 | 3 | */
|
4 | 4 | #include"trgm.h"
|
5 | 5 |
|
@@ -47,53 +47,40 @@ gin_extract_trgm(PG_FUNCTION_ARGS)
|
47 | 47 |
|
48 | 48 | ptr++;
|
49 | 49 | }
|
| 50 | +if (PG_NARGS()>4) |
| 51 | +{ |
| 52 | +/* |
| 53 | + * Function called from query extracting |
| 54 | + */ |
| 55 | +Pointer**extra_data= (Pointer**)PG_GETARG_POINTER(4); |
| 56 | + |
| 57 | +*extra_data= (Pointer*)palloc0(sizeof(Pointer)*(*nentries)); |
| 58 | + |
| 59 | +*(int32*)(*extra_data)=trglen; |
| 60 | +} |
50 | 61 | }
|
51 | 62 |
|
52 | 63 | PG_RETURN_POINTER(entries);
|
53 | 64 | }
|
54 | 65 |
|
55 |
| -/* |
56 |
| - * Per call strage for consistent functions to |
57 |
| - * cache computed value from query |
58 |
| - */ |
59 |
| -typedefstructPerCallConsistentStorage { |
60 |
| -inttrglen; |
61 |
| -textdata[1];/* query */ |
62 |
| -}PerCallConsistentStorage; |
63 |
| -#definePCCSHDR_SZ offsetof(PerCallConsistentStorage, data) |
64 |
| - |
65 | 66 | Datum
|
66 | 67 | gin_trgm_consistent(PG_FUNCTION_ARGS)
|
67 | 68 | {
|
68 | 69 | bool*check= (bool*)PG_GETARG_POINTER(0);
|
69 | 70 | /* StrategyNumber strategy = PG_GETARG_UINT16(1); */
|
70 |
| -text*query=PG_GETARG_TEXT_P(2); |
71 |
| -bool*recheck= (bool*)PG_GETARG_POINTER(3); |
| 71 | +/* text *query = PG_GETARG_TEXT_P(2); */ |
| 72 | +/* int32nkeys = PG_GETARG_INT32(3); */ |
| 73 | +Pointer*extra_data= (Pointer*)PG_GETARG_POINTER(4); |
| 74 | +bool*recheck= (bool*)PG_GETARG_POINTER(5); |
72 | 75 | boolres= FALSE;
|
73 | 76 | int4i,
|
74 | 77 | trglen,
|
75 | 78 | ntrue=0;
|
76 |
| -PerCallConsistentStorage*pccs= (PerCallConsistentStorage*)fcinfo->flinfo->fn_extra; |
77 | 79 |
|
78 | 80 | /* All cases served by this function are inexact */
|
79 | 81 | *recheck= true;
|
80 | 82 |
|
81 |
| -if (pccs==NULL||VARSIZE(pccs->data)!=VARSIZE(query)||memcmp(pccs->data,query,VARSIZE(query) )!=0 ) |
82 |
| -{ |
83 |
| -TRGM*trg=generate_trgm(VARDATA(query),VARSIZE(query)-VARHDRSZ); |
84 |
| - |
85 |
| -if (pccs ) |
86 |
| -pfree(pccs); |
87 |
| - |
88 |
| -fcinfo->flinfo->fn_extra=MemoryContextAlloc(fcinfo->flinfo->fn_mcxt, |
89 |
| -VARSIZE(query)+PCCSHDR_SZ); |
90 |
| -pccs= (PerCallConsistentStorage*)fcinfo->flinfo->fn_extra; |
91 |
| - |
92 |
| -pccs->trglen=ARRNELEM(trg); |
93 |
| -memcpy(pccs->data,query,VARSIZE(query) ); |
94 |
| -} |
95 |
| - |
96 |
| -trglen=pccs->trglen; |
| 83 | +trglen=*(int32*)extra_data; |
97 | 84 |
|
98 | 85 | for (i=0;i<trglen;i++)
|
99 | 86 | if (check[i])
|
|