47#include "utils/fmgrprotos.h"
70#define SPGIST_MAX_PREFIX_LENGTH Max((int) (BLCKSZ - 258 * 16 - 100), 32)
82#define SPG_STRATEGY_ADDITION (10)
83#define SPG_IS_COLLATION_AWARE_STRATEGY(s) ((s) > SPG_STRATEGY_ADDITION \
84 && (s) != RTPrefixStrategyNumber)
142 while (
i < lena &&
i < lenb && *
a == *
b)
163 while (StopLow < StopHigh)
165 int StopMiddle = (StopLow + StopHigh) >> 1;
169 StopHigh = StopMiddle;
171 StopLow = StopMiddle + 1;
191 char *prefixStr = NULL;
210 if (commonLen == prefixSize)
212 if (inSize - in->
level > commonLen)
213 nodeChar = *(
unsigned char *) (inStr + in->
level + commonLen);
240 if (prefixSize - commonLen == 1)
249 prefixSize - commonLen - 1);
255 else if (inSize > in->
level)
257 nodeChar = *(
unsigned char *) (inStr + in->
level);
277 levelAdd = commonLen;
281 if (inSize - in->
level - levelAdd > 0)
284 inSize - in->
level - levelAdd);
344 for (
i = 1;
i < in->
nTuples && commonLen > 0;
i++)
381 nodes[
i].
c = *(
unsigned char *) (
VARDATA_ANY(texti) + commonLen);
406 if (
i == 0 || nodes[
i].
c != nodes[
i - 1].
c)
431 text *reconstructedValue;
434 text *prefixText = NULL;
450 Assert(reconstructedValue == NULL ? in->
level == 0 :
453 maxReconstrLen = in->
level + 1;
458 maxReconstrLen += prefixSize;
493 thisLen = maxReconstrLen - 1;
496 ((
unsigned char *)
VARDATA(reconstrText))[maxReconstrLen - 1] = nodeChar;
497 thisLen = maxReconstrLen;
527 Min(inSize, thisLen));
537 if (r != 0 || inSize < thisLen)
550 elog(
ERROR,
"unrecognized strategy number: %d",
578 int level = in->
level;
580 *reconstrValue = NULL;
595 Assert(reconstrValue == NULL ? level == 0 :
602 fullValue =
VARDATA(reconstrValue);
612 memcpy(fullValue,
VARDATA(reconstrValue), level);
634 res = (level >= queryLen) ||
661 r = memcmp(fullValue,
VARDATA_ANY(query),
Min(queryLen, fullLen));
665 if (queryLen > fullLen)
667 else if (queryLen < fullLen)
690 elog(
ERROR,
"unrecognized strategy number: %d",
#define Assert(condition)
Datum datumCopy(Datum value, bool typByVal, int typLen)
static void PGresult * res
Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2)
#define DatumGetTextPP(X)
#define PG_GETARG_POINTER(n)
#define PG_GET_COLLATION()
#define PG_RETURN_BOOL(x)
static int pg_cmp_s16(int16 a, int16 b)
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
pg_locale_t pg_newlocale_from_collation(Oid collid)
#define qsort(a, b, c, d)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Datum Int16GetDatum(int16 X)
static Pointer DatumGetPointer(Datum X)
static int16 DatumGetInt16(Datum X)
Datum spg_text_config(PG_FUNCTION_ARGS)
static int commonPrefix(const char *a, const char *b, int lena, int lenb)
#define SPG_IS_COLLATION_AWARE_STRATEGY(s)
static int cmpNodePtr(const void *a, const void *b)
#define SPGIST_MAX_PREFIX_LENGTH
struct spgNodePtr spgNodePtr
#define SPG_STRATEGY_ADDITION
Datum spg_text_leaf_consistent(PG_FUNCTION_ARGS)
Datum spg_text_inner_consistent(PG_FUNCTION_ARGS)
static Datum formTextDatum(const char *data, int datalen)
Datum spg_text_choose(PG_FUNCTION_ARGS)
static bool searchChar(Datum *nodeLabels, int nNodes, int16 c, int *i)
Datum spg_text_picksplit(PG_FUNCTION_ARGS)
#define RTPrefixStrategyNumber
#define BTGreaterStrategyNumber
#define BTLessStrategyNumber
#define BTEqualStrategyNumber
#define BTLessEqualStrategyNumber
#define BTGreaterEqualStrategyNumber
StrategyNumber sk_strategy
spgChooseResultType resultType
struct spgChooseOut::@51::@54 splitTuple
struct spgChooseOut::@51::@53 addNode
struct spgChooseOut::@51::@52 matchNode
union spgChooseOut::@51 result
Datum * reconstructedValues
#define SET_VARSIZE_SHORT(PTR, len)
#define SET_VARSIZE(PTR, len)
#define VARSIZE_ANY_EXHDR(PTR)
int varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid)
Datum text_starts_with(PG_FUNCTION_ARGS)