Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7bfb490

Browse files
author
Vladlen Popolitov
committed
gin triconsistent class support function added
1 parentebf7f14 commit7bfb490

File tree

2 files changed

+161
-0
lines changed

2 files changed

+161
-0
lines changed

‎anyarray--1.0.sql‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,11 @@ CREATE OR REPLACE FUNCTION ginanyarray_consistent(internal, internal, anyarray)
571571
AS'MODULE_PATHNAME'
572572
LANGUAGE C IMMUTABLE;
573573

574+
CREATE OR REPLACEFUNCTIONginanyarray_triconsistent(internal, internal, anyarray,internal,internal,internal,internal,internal)
575+
RETURNS internal
576+
AS'MODULE_PATHNAME'
577+
LANGUAGE C IMMUTABLE;
578+
574579
--gin opclasses
575580

576581
CREATEOPERATOR CLASS_int2_aa_ops
@@ -612,6 +617,37 @@ AS
612617
FUNCTION2 ginanyarray_extract(anyarray, internal),
613618
FUNCTION3 ginanyarray_queryextract(anyarray, internal, internal),
614619
FUNCTION4 ginanyarray_consistent(internal, internal, anyarray),
620+
--FUNCTION 6 ginanyarray_triconsistent(internal, internal, anyarray,internal,internal,internal,internal,internal),
621+
STORAGE int8;
622+
623+
CREATEOPERATOR CLASS_int8_aa_ops_beta
624+
FOR TYPE _int8 USING gin
625+
AS
626+
OPERATOR3&&(anyarray, anyarray),
627+
OPERATOR6=(anyarray, anyarray),
628+
OPERATOR7@>(anyarray, anyarray),
629+
OPERATOR8<@(anyarray, anyarray),
630+
OPERATOR16%(anyarray, anyarray),
631+
FUNCTION1 btint8cmp(int8,int8),
632+
FUNCTION2 ginanyarray_extract(anyarray, internal),
633+
FUNCTION3 ginanyarray_queryextract(anyarray, internal, internal),
634+
-- FUNCTION 4 ginanyarray_consistent(internal, internal, anyarray),
635+
FUNCTION6 ginanyarray_triconsistent(internal, internal, anyarray,internal,internal,internal,internal,internal),
636+
STORAGE int8;
637+
638+
CREATEOPERATOR CLASS_int8_aa_ops_beta2
639+
FOR TYPE _int8 USING gin
640+
AS
641+
OPERATOR3&&(anyarray, anyarray),
642+
OPERATOR6=(anyarray, anyarray),
643+
OPERATOR7@>(anyarray, anyarray),
644+
OPERATOR8<@(anyarray, anyarray),
645+
OPERATOR16%(anyarray, anyarray),
646+
FUNCTION1 btint8cmp(int8,int8),
647+
FUNCTION2 ginanyarray_extract(anyarray, internal),
648+
FUNCTION3 ginanyarray_queryextract(anyarray, internal, internal),
649+
FUNCTION4 ginanyarray_consistent(internal, internal, anyarray),
650+
FUNCTION6 ginanyarray_triconsistent(internal, internal, anyarray,internal,internal,internal,internal,internal),
615651
STORAGE int8;
616652

617653
CREATEOPERATOR CLASS_float4_aa_ops

‎anyarray_gin.c‎

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,128 @@ ginanyarray_consistent(PG_FUNCTION_ARGS)
194194

195195
PG_RETURN_BOOL(res);
196196
}
197+
198+
PG_FUNCTION_INFO_V1(ginanyarray_triconsistent);
199+
Datum
200+
ginanyarray_triconsistent(PG_FUNCTION_ARGS)
201+
{
202+
GinTernaryValue*check= (GinTernaryValue*)PG_GETARG_POINTER(0);
203+
StrategyNumberstrategy=PG_GETARG_UINT16(1);
204+
int32nkeys=PG_GETARG_INT32(3);
205+
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
206+
GinTernaryValueres=GIN_MAYBE;
207+
int32i;
208+
209+
switch (strategy)
210+
{
211+
caseRTOverlapStrategyNumber:
212+
/* if at least one element in check[] is GIN_TRUE, so result = GIN_TRUE
213+
* otherwise if at least one element in check[] is GIN_MAYBE, so result = GIN_MAYBE
214+
* otherwise result = GIN_FALSE
215+
*/
216+
res=GIN_FALSE;
217+
for (i=0;i<nkeys;i++)
218+
{
219+
if (check[i]==GIN_TRUE)
220+
{
221+
res=GIN_TRUE;
222+
break;
223+
}elseif (check[i]==GIN_MAYBE)
224+
{
225+
res=GIN_MAYBE;
226+
}
227+
}
228+
break;
229+
caseRTContainedByStrategyNumber:
230+
/* at least one element in check[] is GIN_TRUE or GIN_MAYBE, so result = GIN_MAYBE (we will need recheck in any case) */
231+
res=GIN_MAYBE;
232+
break;
233+
caseRTSameStrategyNumber:
234+
/* if at least one element in check[] is GIN_FALSE, so result = GIN_FALSE
235+
* otherwise result = GIN_MAYBE
236+
*/
237+
res=GIN_MAYBE;
238+
for (i=0;i<nkeys;i++)
239+
{
240+
if (check[i]==GIN_FALSE)
241+
{
242+
res=GIN_FALSE;
243+
break;
244+
}
245+
}
246+
break;
247+
caseRTContainsStrategyNumber:
248+
/* if at least one element in check[] is GIN_FALSE, so result = GIN_FALSE
249+
* otherwise if at least one element in check[] is GIN_MAYBE, so result = GIN_MAYBE
250+
* otherwise result = GIN_TRUE
251+
*/
252+
res=GIN_TRUE;
253+
for (i=0;i<nkeys;i++)
254+
{
255+
if (check[i]==GIN_FALSE)
256+
{
257+
res=GIN_FALSE;
258+
break;
259+
}elseif (check[i]==GIN_MAYBE)
260+
{
261+
res=GIN_MAYBE;
262+
}
263+
}
264+
break;
265+
caseAnyAarraySimilarityStrategy:
266+
{
267+
int32nIntersectionMin=0;
268+
int32nIntersectionMax=0;
269+
270+
res=GIN_FALSE;
271+
for (i=0;i<nkeys;i++)
272+
{
273+
if (check[i]==GIN_TRUE)
274+
{
275+
nIntersectionMin++;
276+
nIntersectionMax++;
277+
}elseif (check[i]==GIN_MAYBE)
278+
{
279+
nIntersectionMax++;
280+
res=GIN_MAYBE;
281+
}
282+
}
283+
284+
switch(SmlType)
285+
{
286+
caseAA_Cosine:
287+
/* nIntersection / sqrt(nkeys * nIntersection) */
288+
if(sqrt(((double)nIntersectionMax) / (double)nkeys)<SmlLimit){
289+
res=GIN_FALSE;
290+
}else {
291+
res=GIN_MAYBE;
292+
}
293+
break;
294+
caseAA_Jaccard:
295+
if((((double)nIntersectionMax) / (double)nkeys)<SmlLimit){
296+
res=GIN_FALSE;
297+
}else {
298+
res=GIN_MAYBE;
299+
}
300+
break;
301+
caseAA_Overlap:
302+
/* if nIntersection >= SmlLimit, so result = GIN_TRUE
303+
* otherwise if at least one element in check[] is GIN_MAYBE, so result = GIN_MAYBE
304+
* otherwise result = GIN_FALSE
305+
*/
306+
if(((double)nIntersectionMin) >=SmlLimit)
307+
{
308+
res=GIN_TRUE;
309+
}
310+
break;
311+
default:
312+
elog(ERROR,"unknown similarity type");
313+
}
314+
}
315+
break;
316+
default:
317+
elog(ERROR,"ginanyarray_consistent: unknown strategy number: %d",
318+
strategy);
319+
}
320+
PG_RETURN_GIN_TERNARY_VALUE(res);
321+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp