* Build a new bloom index. */
| 118 | * Build a new bloom index. |
| 119 | */ |
| 120 | IndexBuildResult * |
| 121 | blbuild(Relation heap, Relation index, IndexInfo *indexInfo) |
| 122 | { |
| 123 | IndexBuildResult *result; |
| 124 | double reltuples; |
| 125 | BloomBuildState buildstate; |
| 126 | |
| 127 | if (RelationGetNumberOfBlocks(index) != 0) |
| 128 | elog(ERROR, "index \"%s\" already contains data", |
| 129 | RelationGetRelationName(index)); |
| 130 | |
| 131 | /* Initialize the meta page */ |
| 132 | BloomInitMetapage(index); |
| 133 | |
| 134 | /* Initialize the bloom build state */ |
| 135 | memset(&buildstate, 0, sizeof(buildstate)); |
| 136 | initBloomState(&buildstate.blstate, index); |
| 137 | buildstate.tmpCtx = AllocSetContextCreate(CurrentMemoryContext, |
| 138 | "Bloom build temporary context", |
| 139 | ALLOCSET_DEFAULT_SIZES); |
| 140 | initCachedPage(&buildstate); |
| 141 | |
| 142 | /* Do the heap scan */ |
| 143 | reltuples = table_index_build_scan(heap, index, indexInfo, true, true, |
| 144 | bloomBuildCallback, (void *) &buildstate, |
| 145 | NULL); |
| 146 | |
| 147 | /* Flush last page if needed (it will be, unless heap was empty) */ |
| 148 | if (buildstate.count > 0) |
| 149 | flushCachedPage(index, &buildstate); |
| 150 | |
| 151 | MemoryContextDelete(buildstate.tmpCtx); |
| 152 | |
| 153 | result = (IndexBuildResult *) palloc(sizeof(IndexBuildResult)); |
| 154 | result->heap_tuples = reltuples; |
| 155 | result->index_tuples = buildstate.indtuples; |
| 156 | |
| 157 | return result; |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | * Build an empty bloom index in the initialization fork. |
nothing calls this directly
no test coverage detected