diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-08-29 09:14:08 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-08-29 09:21:20 +0300 |
commit | c82dedb7a8a953785f24a3b10de376760d60c24c (patch) | |
tree | fd8ed66d5fc40431790f971e442c5f16cd9ddaa3 /src/backend/access/spgist/spgutils.c | |
parent | 9df55c8c3f0eba77de57006999d5700292fa9d33 (diff) | |
download | postgresql-c82dedb7a8a953785f24a3b10de376760d60c24c.tar.gz postgresql-c82dedb7a8a953785f24a3b10de376760d60c24c.zip |
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.
Diffstat (limited to 'src/backend/access/spgist/spgutils.c')
-rw-r--r-- | src/backend/access/spgist/spgutils.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/backend/access/spgist/spgutils.c b/src/backend/access/spgist/spgutils.c index 72aae02b450..675c80eb39b 100644 --- a/src/backend/access/spgist/spgutils.c +++ b/src/backend/access/spgist/spgutils.c @@ -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; + } } /* |