aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 0d2184f7309..69bbeaf0fb0 100644
--- a/src/backend/access/gist/gistbuild.c
+++ b/src/backend/access/gist/gistbuild.c
@@ -827,6 +827,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. */
@@ -842,10 +855,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);