aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/gist/gistbuild.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access/gist/gistbuild.c')
-rw-r--r--src/backend/access/gist/gistbuild.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/backend/access/gist/gistbuild.c b/src/backend/access/gist/gistbuild.c
index 7a6d93bb879..57fe553a5c9 100644
--- a/src/backend/access/gist/gistbuild.c
+++ b/src/backend/access/gist/gistbuild.c
@@ -901,6 +901,19 @@ gistBuildCallback(Relation index,
true);
itup->t_tid = *tid;
+ /* Update tuple count and total size. */
+ buildstate->indtuples += 1;
+ buildstate->indtuplesSize += IndexTupleSize(itup);
+
+ /*
+ * XXX In buffering builds, the tempCxt is also reset down inside
+ * gistProcessEmptyingQueue(). This is not great because it risks
+ * confusion and possible use of dangling pointers (for example, itup
+ * might be already freed when control returns here). It's generally
+ * better that a memory context be "owned" by only one function. However,
+ * currently this isn't causing issues so it doesn't seem worth the amount
+ * of refactoring that would be needed to avoid it.
+ */
if (buildstate->buildMode == GIST_BUFFERING_ACTIVE)
{
/* We have buffers, so use them. */
@@ -916,10 +929,6 @@ gistBuildCallback(Relation index,
buildstate->giststate, buildstate->heaprel, true);
}
- /* Update tuple count and total size. */
- buildstate->indtuples += 1;
- buildstate->indtuplesSize += IndexTupleSize(itup);
-
MemoryContextSwitchTo(oldCtx);
MemoryContextReset(buildstate->giststate->tempCxt);