mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Optimize SP-GiST insertions.
This includes two micro-optimizations to the tight inner loop in descending the SP-GiST tree: 1. avoid an extra function call to index_getprocinfo when calling user-defined choose function, and 2. avoid a useless palloc+pfree when node labels are not used.
This commit is contained in:
@ -743,27 +743,32 @@ Datum *
|
||||
spgExtractNodeLabels(SpGistState *state, SpGistInnerTuple innerTuple)
|
||||
{
|
||||
Datum *nodeLabels;
|
||||
int nullcount = 0;
|
||||
int i;
|
||||
SpGistNodeTuple node;
|
||||
|
||||
nodeLabels = (Datum *) palloc(sizeof(Datum) * innerTuple->nNodes);
|
||||
SGITITERATE(innerTuple, i, node)
|
||||
{
|
||||
if (IndexTupleHasNulls(node))
|
||||
nullcount++;
|
||||
else
|
||||
nodeLabels[i] = SGNTDATUM(node, state);
|
||||
}
|
||||
if (nullcount == innerTuple->nNodes)
|
||||
/* Either all the labels must be NULL, or none. */
|
||||
node = SGITNODEPTR(innerTuple);
|
||||
if (IndexTupleHasNulls(node))
|
||||
{
|
||||
SGITITERATE(innerTuple, i, node)
|
||||
{
|
||||
if (!IndexTupleHasNulls(node))
|
||||
elog(ERROR, "some but not all node labels are null in SPGiST inner tuple");
|
||||
}
|
||||
/* They're all null, so just return NULL */
|
||||
pfree(nodeLabels);
|
||||
return NULL;
|
||||
}
|
||||
if (nullcount != 0)
|
||||
elog(ERROR, "some but not all node labels are null in SPGiST inner tuple");
|
||||
return nodeLabels;
|
||||
else
|
||||
{
|
||||
nodeLabels = (Datum *) palloc(sizeof(Datum) * innerTuple->nNodes);
|
||||
SGITITERATE(innerTuple, i, node)
|
||||
{
|
||||
if (IndexTupleHasNulls(node))
|
||||
elog(ERROR, "some but not all node labels are null in SPGiST inner tuple");
|
||||
nodeLabels[i] = SGNTDATUM(node, state);
|
||||
}
|
||||
return nodeLabels;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user