mirror of
https://github.com/postgres/postgres.git
synced 2025-04-29 13:56:47 +03:00
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
This commit is contained in:
parent
a35d729231
commit
eee190da7e
@ -31,6 +31,7 @@
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
SpGistState spgstate; /* SPGiST's working state */
|
SpGistState spgstate; /* SPGiST's working state */
|
||||||
|
int64 indtuples; /* total number of tuples indexed */
|
||||||
MemoryContext tmpCtx; /* per-tuple temporary context */
|
MemoryContext tmpCtx; /* per-tuple temporary context */
|
||||||
} SpGistBuildState;
|
} SpGistBuildState;
|
||||||
|
|
||||||
@ -58,6 +59,9 @@ spgistBuildCallback(Relation index, HeapTuple htup, Datum *values,
|
|||||||
MemoryContextReset(buildstate->tmpCtx);
|
MemoryContextReset(buildstate->tmpCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Update total tuple count */
|
||||||
|
buildstate->indtuples += 1;
|
||||||
|
|
||||||
MemoryContextSwitchTo(oldCtx);
|
MemoryContextSwitchTo(oldCtx);
|
||||||
MemoryContextReset(buildstate->tmpCtx);
|
MemoryContextReset(buildstate->tmpCtx);
|
||||||
}
|
}
|
||||||
@ -134,6 +138,7 @@ spgbuild(PG_FUNCTION_ARGS)
|
|||||||
*/
|
*/
|
||||||
initSpGistState(&buildstate.spgstate, index);
|
initSpGistState(&buildstate.spgstate, index);
|
||||||
buildstate.spgstate.isBuild = true;
|
buildstate.spgstate.isBuild = true;
|
||||||
|
buildstate.indtuples = 0;
|
||||||
|
|
||||||
buildstate.tmpCtx = AllocSetContextCreate(CurrentMemoryContext,
|
buildstate.tmpCtx = AllocSetContextCreate(CurrentMemoryContext,
|
||||||
"SP-GiST build temporary context",
|
"SP-GiST build temporary context",
|
||||||
@ -149,7 +154,8 @@ spgbuild(PG_FUNCTION_ARGS)
|
|||||||
SpGistUpdateMetaPage(index);
|
SpGistUpdateMetaPage(index);
|
||||||
|
|
||||||
result = (IndexBuildResult *) palloc0(sizeof(IndexBuildResult));
|
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);
|
PG_RETURN_POINTER(result);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user