mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Support reloptions of enum type
All our current in core relation options of type string (not many, admittedly) behave in reality like enums. But after seeing an implementation for enum reloptions, it's clear that strings are messier, so introduce the new reloption type. Switch all string options to be enums instead. Fortunately we have a recently introduced test module for reloptions, so we don't lose coverage of string reloptions, which may still be used by third-party modules. Authors: Nikolay Shaplov, Álvaro Herrera Reviewed-by: Nikita Glukhov, Aleksandr Parfenov Discussion: https://postgr.es/m/43332102.S2V5pIjXRx@x200m
This commit is contained in:
@ -125,15 +125,15 @@ gistbuild(Relation heap, Relation index, IndexInfo *indexInfo)
|
||||
|
||||
buildstate.indexrel = index;
|
||||
buildstate.heaprel = heap;
|
||||
|
||||
if (index->rd_options)
|
||||
{
|
||||
/* Get buffering mode from the options string */
|
||||
GiSTOptions *options = (GiSTOptions *) index->rd_options;
|
||||
char *bufferingMode = (char *) options + options->bufferingModeOffset;
|
||||
|
||||
if (strcmp(bufferingMode, "on") == 0)
|
||||
if (options->buffering_mode == GIST_OPTION_BUFFERING_ON)
|
||||
buildstate.bufferingMode = GIST_BUFFERING_STATS;
|
||||
else if (strcmp(bufferingMode, "off") == 0)
|
||||
else if (options->buffering_mode == GIST_OPTION_BUFFERING_OFF)
|
||||
buildstate.bufferingMode = GIST_BUFFERING_DISABLED;
|
||||
else
|
||||
buildstate.bufferingMode = GIST_BUFFERING_AUTO;
|
||||
@ -236,25 +236,6 @@ gistbuild(Relation heap, Relation index, IndexInfo *indexInfo)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Validator for "buffering" reloption on GiST indexes. Allows "on", "off"
|
||||
* and "auto" values.
|
||||
*/
|
||||
void
|
||||
gistValidateBufferingOption(const char *value)
|
||||
{
|
||||
if (value == NULL ||
|
||||
(strcmp(value, "on") != 0 &&
|
||||
strcmp(value, "off") != 0 &&
|
||||
strcmp(value, "auto") != 0))
|
||||
{
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("invalid value for \"buffering\" option"),
|
||||
errdetail("Valid values are \"on\", \"off\", and \"auto\".")));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Attempt to switch to buffering mode.
|
||||
*
|
||||
|
@ -913,7 +913,7 @@ gistoptions(Datum reloptions, bool validate)
|
||||
int numoptions;
|
||||
static const relopt_parse_elt tab[] = {
|
||||
{"fillfactor", RELOPT_TYPE_INT, offsetof(GiSTOptions, fillfactor)},
|
||||
{"buffering", RELOPT_TYPE_STRING, offsetof(GiSTOptions, bufferingModeOffset)}
|
||||
{"buffering", RELOPT_TYPE_ENUM, offsetof(GiSTOptions, buffering_mode)}
|
||||
};
|
||||
|
||||
options = parseRelOptions(reloptions, validate, RELOPT_KIND_GIST,
|
||||
|
Reference in New Issue
Block a user