in src/backend/utils/adt/agtype_gin.c [408:464]
Datum gin_triconsistent_agtype(PG_FUNCTION_ARGS)
{
GinTernaryValue *check;
StrategyNumber strategy;
int32 nkeys;
GinTernaryValue res = GIN_MAYBE;
int32 i;
if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(3))
{
PG_RETURN_NULL();
}
check = (GinTernaryValue *)PG_GETARG_POINTER(0);
strategy = PG_GETARG_UINT16(1);
nkeys = PG_GETARG_INT32(3);
/*
* Note that we never return GIN_TRUE, only GIN_MAYBE or GIN_FALSE; this
* corresponds to always forcing recheck in the regular consistent
* function, for the reasons listed there.
*/
if (strategy == AGTYPE_CONTAINS_STRATEGY_NUMBER ||
strategy == AGTYPE_CONTAINS_TOP_LEVEL_STRATEGY_NUMBER ||
strategy == AGTYPE_EXISTS_ALL_STRATEGY_NUMBER)
{
/* All extracted keys must be present */
for (i = 0; i < nkeys; i++)
{
if (check[i] == GIN_FALSE)
{
res = GIN_FALSE;
break;
}
}
}
else if (strategy == AGTYPE_EXISTS_STRATEGY_NUMBER ||
strategy == AGTYPE_EXISTS_ANY_STRATEGY_NUMBER)
{
/* At least one extracted key must be present */
res = GIN_FALSE;
for (i = 0; i < nkeys; i++)
{
if (check[i] == GIN_TRUE || check[i] == GIN_MAYBE)
{
res = GIN_MAYBE;
break;
}
}
}
else
{
elog(ERROR, "unrecognized strategy number: %d", strategy);
}
PG_RETURN_GIN_TERNARY_VALUE(res);
}