Content-Length: 306655 | pFad | http://github.com/postgrespro/postgres_cluster/commit/649f1792508fb040a9b70c68dfedd6b93897e087

00 Fix tuple counting in SP-GiST index build. · postgrespro/postgres_cluster@649f179 · GitHub
Skip to content

Commit 649f179

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 7de4a1b commit 649f179

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
@@ -32,6 +32,7 @@
3232
typedef struct
3333
{
3434
SpGistState spgstate; /* SPGiST's working state */
35+
int64 indtuples; /* total number of tuples indexed */
3536
MemoryContext tmpCtx; /* per-tuple temporary context */
3637
} SpGistBuildState;
3738

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

63+
/* Update total tuple count */
64+
buildstate->indtuples += 1;
65+
6266
MemoryContextSwitchTo(oldCtx);
6367
MemoryContextReset(buildstate->tmpCtx);
6468
}
@@ -132,6 +136,7 @@ spgbuild(Relation heap, Relation index, IndexInfo *indexInfo)
132136
*/
133137
initSpGistState(&buildstate.spgstate, index);
134138
buildstate.spgstate.isBuild = true;
139+
buildstate.indtuples = 0;
135140

136141
buildstate.tmpCtx = AllocSetContextCreate(CurrentMemoryContext,
137142
"SP-GiST build temporary context",
@@ -146,7 +151,8 @@ spgbuild(Relation heap, Relation index, IndexInfo *indexInfo)
146151
SpGistUpdateMetaPage(index);
147152

148153
result = (IndexBuildResult *) palloc0(sizeof(IndexBuildResult));
149-
result->heap_tuples = result->index_tuples = reltuples;
154+
result->heap_tuples = reltuples;
155+
result->index_tuples = buildstate.indtuples;
150156

151157
return result;
152158
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres_cluster/commit/649f1792508fb040a9b70c68dfedd6b93897e087

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy