Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit db35bf5

Browse files
committed
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
1 parent df90401 commit db35bf5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/backend/access/spgist/spginsert.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
typedef struct
3232
{
3333
SpGistState spgstate; /* SPGiST's working state */
34+
int64 indtuples; /* total number of tuples indexed */
3435
MemoryContext tmpCtx; /* per-tuple temporary context */
3536
} SpGistBuildState;
3637

@@ -58,6 +59,9 @@ spgistBuildCallback(Relation index, HeapTuple htup, Datum *values,
5859
MemoryContextReset(buildstate->tmpCtx);
5960
}
6061

62+
/* Update total tuple count */
63+
buildstate->indtuples += 1;
64+
6165
MemoryContextSwitchTo(oldCtx);
6266
MemoryContextReset(buildstate->tmpCtx);
6367
}
@@ -131,6 +135,7 @@ spgbuild(Relation heap, Relation index, IndexInfo *indexInfo)
131135
*/
132136
initSpGistState(&buildstate.spgstate, index);
133137
buildstate.spgstate.isBuild = true;
138+
buildstate.indtuples = 0;
134139

135140
buildstate.tmpCtx = AllocSetContextCreate(CurrentMemoryContext,
136141
"SP-GiST build temporary context",
@@ -144,7 +149,8 @@ spgbuild(Relation heap, Relation index, IndexInfo *indexInfo)
144149
SpGistUpdateMetaPage(index);
145150

146151
result = (IndexBuildResult *) palloc0(sizeof(IndexBuildResult));
147-
result->heap_tuples = result->index_tuples = reltuples;
152+
result->heap_tuples = reltuples;
153+
result->index_tuples = buildstate.indtuples;
148154

149155
return result;
150156
}

0 commit comments

Comments
 (0)