* bmbuild() -- Build a new bitmap index. */
| 117 | * bmbuild() -- Build a new bitmap index. |
| 118 | */ |
| 119 | IndexBuildResult * |
| 120 | bmbuild(Relation heap, Relation index, IndexInfo *indexInfo) |
| 121 | { |
| 122 | double reltuples; |
| 123 | BMBuildState bmstate; |
| 124 | IndexBuildResult *result; |
| 125 | TupleDesc tupDesc; |
| 126 | |
| 127 | if (indexInfo->ii_Concurrent) |
| 128 | ereport(ERROR, |
| 129 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 130 | errmsg("CONCURRENTLY is not supported when creating bitmap indexes"))); |
| 131 | |
| 132 | /* We expect this to be called exactly once. */ |
| 133 | if (RelationGetNumberOfBlocks(index) != 0) |
| 134 | ereport (ERROR, |
| 135 | (errcode(ERRCODE_INDEX_CORRUPTED), |
| 136 | errmsg("index \"%s\" already contains data", |
| 137 | RelationGetRelationName(index)))); |
| 138 | |
| 139 | tupDesc = RelationGetDescr(index); |
| 140 | |
| 141 | /* initialize the bitmap index for MAIN_FORKNUM. */ |
| 142 | _bitmap_init(index, RelationNeedsWAL(index), false); |
| 143 | |
| 144 | /* initialize the build state. */ |
| 145 | _bitmap_init_buildstate(index, &bmstate); |
| 146 | |
| 147 | /* do the heap scan */ |
| 148 | reltuples = table_index_build_scan(heap, index, indexInfo, false, true, |
| 149 | bmbuildCallback, (void *) &bmstate, |
| 150 | NULL); |
| 151 | /* clean up the build state */ |
| 152 | _bitmap_cleanup_buildstate(index, &bmstate); |
| 153 | |
| 154 | /* return statistics */ |
| 155 | result = (IndexBuildResult *) palloc0(sizeof(IndexBuildResult)); |
| 156 | |
| 157 | result->heap_tuples = reltuples; |
| 158 | result->index_tuples = bmstate.ituples; |
| 159 | |
| 160 | return result; |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | * bmbuildempty() -- build an empty bitmap index in the initialization fork |
nothing calls this directly
no test coverage detected