Datum bloptions(PG_FUNCTION_ARGS) { Datum reloptions = PG_GETARG_DATUM(0); bool validate = PG_GETARG_BOOL(1); relopt_value *options; int numoptions; BloomOptions *rdopts; relopt_parse_elt tab[INDEX_MAX_KEYS+1]; int i; char buf[16]; tab[0].optname = "length"; tab[0].opttype = RELOPT_TYPE_INT; tab[0].offset = offsetof(BloomOptions, bloomLength); for(i=0;i<INDEX_MAX_KEYS;i++) { snprintf(buf, sizeof(buf), "col%d", i+1); tab[i+1].optname = pstrdup(buf); tab[i+1].opttype = RELOPT_TYPE_INT; tab[i+1].offset = offsetof(BloomOptions, bitSize[i]); } options = parseRelOptions(reloptions, validate, bloom_kind, &numoptions); rdopts = allocateReloptStruct(sizeof(BloomOptions), options, numoptions); fillRelOptions((void *) rdopts, sizeof(BloomOptions), options, numoptions, validate, tab, INDEX_MAX_KEYS+1); rdopts = makeDefaultBloomOptions(rdopts); PG_RETURN_BYTEA_P(rdopts); }
/* * Fill in metapage for bloom index. */ void BloomFillMetapage(Relation index, Page metaPage) { BloomOptions *opts; BloomMetaPageData *metadata; /* * Choose the index's options. If reloptions have been assigned, use * those, otherwise create default options. */ opts = (BloomOptions *) index->rd_options; if (!opts) opts = makeDefaultBloomOptions(); /* * Initialize contents of meta page, including a copy of the options, * which are now frozen for the life of the index. */ BloomInitPage(metaPage, BLOOM_META); metadata = BloomPageGetMeta(metaPage); memset(metadata, 0, sizeof(BloomMetaPageData)); metadata->magickNumber = BLOOM_MAGICK_NUMBER; metadata->opts = *opts; ((PageHeader) metaPage)->pd_lower += sizeof(BloomMetaPageData); /* If this fails, probably FreeBlockNumberArray size calc is wrong: */ Assert(((PageHeader) metaPage)->pd_lower <= ((PageHeader) metaPage)->pd_upper); }
void BloomInitMetabuffer(Buffer b, Relation index) { BloomMetaPageData *metadata; Page page = BufferGetPage(b); BloomInitPage(page, BLOOM_META, BufferGetPageSize(b)); metadata = BloomPageGetMeta(page); memset(metadata, 0, sizeof(BloomMetaPageData)); metadata->magickNumber = BLOOM_MAGICK_NUMBER; metadata->opts = *makeDefaultBloomOptions((BloomOptions*)index->rd_options); }