/* Look up nodeChar in the node label array */ if (searchChar(in->nodeLabels, in->nNodes, nodeChar, &i))
{ /* *Descendtoexistingnode.(Ifin->allTheSame,thecorecodewill *ignoreournodeNspecificationhere,butthat'sOK.Westillhave *toprovidethecorrectlevelAddandrestDatumvalues,andthoseare *thesameregardlessofwhichnodegetschosenbycore.)
*/ int levelAdd;
Datum
spg_text_picksplit(PG_FUNCTION_ARGS)
{
spgPickSplitIn *in = (spgPickSplitIn *) PG_GETARG_POINTER(0);
spgPickSplitOut *out = (spgPickSplitOut *) PG_GETARG_POINTER(1);
text *text0 = DatumGetTextPP(in->datums[0]); int i,
commonLen;
spgNodePtr *nodes;
/* Identify longest common prefix, if any */
commonLen = VARSIZE_ANY_EXHDR(text0); for (i = 1; i < in->nTuples && commonLen > 0; i++)
{
text *texti = DatumGetTextPP(in->datums[i]); int tmp = commonPrefix(VARDATA_ANY(text0),
VARDATA_ANY(texti),
VARSIZE_ANY_EXHDR(text0),
VARSIZE_ANY_EXHDR(texti));
/* Set node prefix to be that string, if it's not empty */ if (commonLen == 0)
{
out->hasPrefix = false;
} else
{
out->hasPrefix = true;
out->prefixDatum = formTextDatum(VARDATA_ANY(text0), commonLen);
}
/* Extract the node label (first non-common byte) from each value */
nodes = (spgNodePtr *) palloc(sizeof(spgNodePtr) * in->nTuples);
for (i = 0; i < in->nTuples; i++)
{
text *texti = DatumGetTextPP(in->datums[i]);
if (commonLen < VARSIZE_ANY_EXHDR(texti))
nodes[i].c = *(unsignedchar *) (VARDATA_ANY(texti) + commonLen); else
nodes[i].c = -1; /* use -1 if string is all common */
nodes[i].i = i;
nodes[i].d = in->datums[i];
}
Datum
spg_text_inner_consistent(PG_FUNCTION_ARGS)
{
spgInnerConsistentIn *in = (spgInnerConsistentIn *) PG_GETARG_POINTER(0);
spgInnerConsistentOut *out = (spgInnerConsistentOut *) PG_GETARG_POINTER(1); bool collate_is_c = pg_newlocale_from_collation(PG_GET_COLLATION())->collate_is_c;
text *reconstructedValue;
text *reconstrText; int maxReconstrLen;
text *prefixText = NULL; int prefixSize = 0; int i;
if (in->level)
memcpy(VARDATA(reconstrText),
VARDATA(reconstructedValue),
in->level); if (prefixSize)
memcpy(((char *) VARDATA(reconstrText)) + in->level,
VARDATA_ANY(prefixText),
prefixSize); /* last byte of reconstrText will be filled in below */
for (i = 0; i < in->nNodes; i++)
{
int16 nodeChar = DatumGetInt16(in->nodeLabels[i]); int thisLen; bool res = true; int j;
/* If nodeChar is a dummy value, don't include it in data */ if (nodeChar <= 0)
thisLen = maxReconstrLen - 1; else
{
((unsignedchar *) VARDATA(reconstrText))[maxReconstrLen - 1] = nodeChar;
thisLen = maxReconstrLen;
}
for (j = 0; j < in->nkeys; j++)
{
StrategyNumber strategy = in->scankeys[j].sk_strategy;
text *inText; int inSize; int r;
/* *Ifit'sacollation-awareoperator,butthecollationisC,we *cantreatitasnon-collation-aware.Withnon-Ccollationwe *needtotraversewholetree:-(sothere'snopointinmaking *anycheckhere.(Notealsothatourreconstructedvaluemay *wellendwithapartialmultibytecharacter,sothatapplying *anyencoding-sensitivetesttoitwouldberiskyanyhow.)
*/ if (SPG_IS_COLLATION_AWARE_STRATEGY(strategy))
{ if (collate_is_c)
strategy -= SPG_STRATEGY_ADDITION; else continue;
}
r = memcmp(VARDATA(reconstrText), VARDATA_ANY(inText),
Min(inSize, thisLen));
switch (strategy)
{ case BTLessStrategyNumber: case BTLessEqualStrategyNumber: if (r > 0)
res = false; break; case BTEqualStrategyNumber: if (r != 0 || inSize < thisLen)
res = false; break; case BTGreaterEqualStrategyNumber: case BTGreaterStrategyNumber: if (r < 0)
res = false; break; case RTPrefixStrategyNumber: if (r != 0)
res = false; break; default:
elog(ERROR, "unrecognized strategy number: %d",
in->scankeys[j].sk_strategy); break;
}
if (!res) break; /* no need to consider remaining conditions */
}
/* Perform the required comparison(s) */
res = true; for (j = 0; j < in->nkeys; j++)
{
StrategyNumber strategy = in->scankeys[j].sk_strategy;
text *query = DatumGetTextPP(in->scankeys[j].sk_argument); int queryLen = VARSIZE_ANY_EXHDR(query); int r;
if (strategy == RTPrefixStrategyNumber)
{ /* *iflevel>=lengthofquerythenreconstrValuemustbeginwith *query(prefix)string,sowedon'tneedtocheckitagain.
*/
res = (level >= queryLen) ||
DatumGetBool(DirectFunctionCall2Coll(text_starts_with,
PG_GET_COLLATION(),
out->leafValue,
PointerGetDatum(query)));
if (!res) /* no need to consider remaining conditions */ break;
continue;
}
if (SPG_IS_COLLATION_AWARE_STRATEGY(strategy))
{ /* Collation-aware comparison */
strategy -= SPG_STRATEGY_ADDITION;
/* If asserts enabled, verify encoding of reconstructed string */
Assert(pg_verifymbstr(fullValue, fullLen, false));
r = varstr_cmp(fullValue, fullLen,
VARDATA_ANY(query), queryLen,
PG_GET_COLLATION());
} else
{ /* Non-collation-aware comparison */
r = memcmp(fullValue, VARDATA_ANY(query), Min(queryLen, fullLen));
if (r == 0)
{ if (queryLen > fullLen)
r = -1; elseif (queryLen < fullLen)
r = 1;
}
}
switch (strategy)
{ case BTLessStrategyNumber:
res = (r < 0); break; case BTLessEqualStrategyNumber:
res = (r <= 0); break; case BTEqualStrategyNumber:
res = (r == 0); break; case BTGreaterEqualStrategyNumber:
res = (r >= 0); break; case BTGreaterStrategyNumber:
res = (r > 0); break; default:
elog(ERROR, "unrecognized strategy number: %d",
in->scankeys[j].sk_strategy);
res = false; break;
}
if (!res) break; /* no need to consider remaining conditions */
}
PG_RETURN_BOOL(res);
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.21Bemerkung:
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.