static int32 gbt_textcmp(const bytea *a, const bytea *b) { return DatumGetInt32(DirectFunctionCall2Coll(bttextcmp, DEFAULT_COLLATION_OID, PointerGetDatum(a), PointerGetDatum(b))); }
static bool gbt_textlt(const void *a, const void *b) { return DatumGetBool(DirectFunctionCall2Coll(text_lt, DEFAULT_COLLATION_OID, PointerGetDatum(a), PointerGetDatum(b))); }
static int32 gbt_textcmp(const void *a, const void *b, Oid collation) { return DatumGetInt32(DirectFunctionCall2Coll(bttextcmp, collation, PointerGetDatum(a), PointerGetDatum(b))); }
static bool gbt_textlt(const void *a, const void *b, Oid collation) { return DatumGetBool(DirectFunctionCall2Coll(text_lt, collation, PointerGetDatum(a), PointerGetDatum(b))); }
/* * Datum a is a value from extract_query method and for BTLess* * strategy it is a left-most value. So, use original datum from QueryInfo * to decide to stop scanning or not. Datum b is always from index. */ static Datum gin_btree_compare_prefix(FunctionCallInfo fcinfo) { Datum a = PG_GETARG_DATUM(0); Datum b = PG_GETARG_DATUM(1); QueryInfo *data = (QueryInfo *) PG_GETARG_POINTER(3); int32 res, cmp; cmp = DatumGetInt32(DirectFunctionCall2Coll( data->typecmp, PG_GET_COLLATION(), (data->strategy == BTLessStrategyNumber || data->strategy == BTLessEqualStrategyNumber) ? data->datum : a, b)); switch (data->strategy) { case BTLessStrategyNumber: /* If original datum > indexed one then return match */ if (cmp > 0) res = 0; else res = 1; break; case BTLessEqualStrategyNumber: /* The same except equality */ if (cmp >= 0) res = 0; else res = 1; break; case BTEqualStrategyNumber: if (cmp != 0) res = 1; else res = 0; break; case BTGreaterEqualStrategyNumber: /* If original datum <= indexed one then return match */ if (cmp <= 0) res = 0; else res = 1; break; case BTGreaterStrategyNumber: /* If original datum <= indexed one then return match */ /* If original datum == indexed one then continue scan */ if (cmp < 0) res = 0; else if (cmp == 0) res = -1; else res = 1; break; default: elog(ERROR, "unrecognized strategy number: %d", data->strategy); res = 0; } PG_RETURN_INT32(res); }