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

Commit 76e2b5a

Browse files
committed
Fix errors in contrib/bloom 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.) Fix counting of tuples in current index page, too. This error would have led to failing to write out the final page of the index if it contained exactly one tuple, so that the last tuple of the relation would not get indexed. Back-patch to 9.6 where contrib/bloom was added. Tomas Vondra and Tom Lane Discussion: https://postgr.es/m/3b3d8eac-c709-0d25-088e-b98339a1b28a@2ndquadrant.com
1 parent 66e9287 commit 76e2b5a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

contrib/bloom/blinsert.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ PG_MODULE_MAGIC;
3333
typedef struct
3434
{
3535
BloomState blstate; /* bloom index state */
36+
int64 indtuples; /* total number of tuples indexed */
3637
MemoryContext tmpCtx; /* temporary memory context reset after each
3738
* tuple */
3839
char data[BLCKSZ]; /* cached page */
39-
int64 count; /* number of tuples in cached page */
40+
int count; /* number of tuples in cached page */
4041
} BloomBuildState;
4142

4243
/*
@@ -102,8 +103,14 @@ bloomBuildCallback(Relation index, HeapTuple htup, Datum *values,
102103
/* We shouldn't be here since we're inserting to the empty page */
103104
elog(ERROR, "could not add new bloom tuple to empty page");
104105
}
106+
107+
/* Next item was added successfully */
108+
buildstate->count++;
105109
}
106110

111+
/* Update total tuple count */
112+
buildstate->indtuples += 1;
113+
107114
MemoryContextSwitchTo(oldCtx);
108115
MemoryContextReset(buildstate->tmpCtx);
109116
}
@@ -137,17 +144,15 @@ blbuild(Relation heap, Relation index, IndexInfo *indexInfo)
137144
reltuples = IndexBuildHeapScan(heap, index, indexInfo, true,
138145
bloomBuildCallback, (void *) &buildstate);
139146

140-
/*
141-
* There are could be some items in cached page. Flush this page if
142-
* needed.
143-
*/
147+
/* Flush last page if needed (it will be, unless heap was empty) */
144148
if (buildstate.count > 0)
145149
flushCachedPage(index, &buildstate);
146150

147151
MemoryContextDelete(buildstate.tmpCtx);
148152

149153
result = (IndexBuildResult *) palloc(sizeof(IndexBuildResult));
150-
result->heap_tuples = result->index_tuples = reltuples;
154+
result->heap_tuples = reltuples;
155+
result->index_tuples = buildstate.indtuples;
151156

152157
return result;
153158
}

0 commit comments

Comments
 (0)