summaryrefslogtreecommitdiff
path: root/src/backend/access/spgist/spginsert.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-03-22 13:23:48 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-03-22 13:23:48 -0400
commit7f6f8ccd976da21c0117bddfee8bd86226bd2559 (patch)
tree43a357c09d9e220f4dc07dbf75fea6b6538a2713 /src/backend/access/spgist/spginsert.c
parent67e02cde7373b09a8f6897b7fea3800ceb91ad9e (diff)
Fix tuple counting in SP-GiST index build.
Count the number of tuples in the index honestly, instead of assuming that it's the same as the number of tuples in the heap. (It might be different if the index is partial.) Back-patch to all supported versions. Tomas Vondra Discussion: https://postgr.es/m/3b3d8eac-c709-0d25-088e-b98339a1b28a@2ndquadrant.com
Diffstat (limited to 'src/backend/access/spgist/spginsert.c')
-rw-r--r--src/backend/access/spgist/spginsert.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/backend/access/spgist/spginsert.c b/src/backend/access/spgist/spginsert.c
index cf3d11c34cb..edb41c1fc05 100644
--- a/src/backend/access/spgist/spginsert.c
+++ b/src/backend/access/spgist/spginsert.c
@@ -30,6 +30,7 @@
typedef struct
{
SpGistState spgstate; /* SPGiST's working state */
+ int64 indtuples; /* total number of tuples indexed */
MemoryContext tmpCtx; /* per-tuple temporary context */
} SpGistBuildState;
@@ -57,6 +58,9 @@ spgistBuildCallback(Relation index, HeapTuple htup, Datum *values,
MemoryContextReset(buildstate->tmpCtx);
}
+ /* Update total tuple count */
+ buildstate->indtuples += 1;
+
MemoryContextSwitchTo(oldCtx);
MemoryContextReset(buildstate->tmpCtx);
}
@@ -130,6 +134,7 @@ spgbuild(PG_FUNCTION_ARGS)
*/
initSpGistState(&buildstate.spgstate, index);
buildstate.spgstate.isBuild = true;
+ buildstate.indtuples = 0;
buildstate.tmpCtx = AllocSetContextCreate(CurrentMemoryContext,
"SP-GiST build temporary context",
@@ -145,7 +150,8 @@ spgbuild(PG_FUNCTION_ARGS)
SpGistUpdateMetaPage(index);
result = (IndexBuildResult *) palloc0(sizeof(IndexBuildResult));
- result->heap_tuples = result->index_tuples = reltuples;
+ result->heap_tuples = reltuples;
+ result->index_tuples = buildstate.indtuples;
PG_RETURN_POINTER(result);
}