mirror of
https://github.com/postgres/postgres.git
synced 2025-10-21 02:52:47 +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:
@@ -380,6 +380,14 @@ typedef struct GISTBuildBuffers
|
||||
int rootlevel;
|
||||
} GISTBuildBuffers;
|
||||
|
||||
/* GiSTOptions->buffering_mode values */
|
||||
typedef enum GistOptBufferingMode
|
||||
{
|
||||
GIST_OPTION_BUFFERING_AUTO,
|
||||
GIST_OPTION_BUFFERING_ON,
|
||||
GIST_OPTION_BUFFERING_OFF
|
||||
} GistOptBufferingMode;
|
||||
|
||||
/*
|
||||
* Storage type for GiST's reloptions
|
||||
*/
|
||||
@@ -387,7 +395,7 @@ typedef struct GiSTOptions
|
||||
{
|
||||
int32 vl_len_; /* varlena header (do not touch directly!) */
|
||||
int fillfactor; /* page fill factor in percent (0..100) */
|
||||
int bufferingModeOffset; /* use buffering build? */
|
||||
GistOptBufferingMode buffering_mode; /* buffering build mode */
|
||||
} GiSTOptions;
|
||||
|
||||
/* gist.c */
|
||||
|
@@ -31,6 +31,7 @@ typedef enum relopt_type
|
||||
RELOPT_TYPE_BOOL,
|
||||
RELOPT_TYPE_INT,
|
||||
RELOPT_TYPE_REAL,
|
||||
RELOPT_TYPE_ENUM,
|
||||
RELOPT_TYPE_STRING
|
||||
} relopt_type;
|
||||
|
||||
@@ -80,6 +81,7 @@ typedef struct relopt_value
|
||||
bool bool_val;
|
||||
int int_val;
|
||||
double real_val;
|
||||
int enum_val;
|
||||
char *string_val; /* allocated separately */
|
||||
} values;
|
||||
} relopt_value;
|
||||
@@ -107,6 +109,25 @@ typedef struct relopt_real
|
||||
double max;
|
||||
} relopt_real;
|
||||
|
||||
/*
|
||||
* relopt_enum_elt_def -- One member of the array of acceptable values
|
||||
* of an enum reloption.
|
||||
*/
|
||||
typedef struct relopt_enum_elt_def
|
||||
{
|
||||
const char *string_val;
|
||||
int symbol_val;
|
||||
} relopt_enum_elt_def;
|
||||
|
||||
typedef struct relopt_enum
|
||||
{
|
||||
relopt_gen gen;
|
||||
relopt_enum_elt_def *members;
|
||||
int default_val;
|
||||
const char *detailmsg;
|
||||
/* null-terminated array of members */
|
||||
} relopt_enum;
|
||||
|
||||
/* validation routines for strings */
|
||||
typedef void (*validate_string_relopt) (const char *value);
|
||||
|
||||
@@ -254,6 +275,9 @@ extern void add_int_reloption(bits32 kinds, const char *name, const char *desc,
|
||||
extern void add_real_reloption(bits32 kinds, const char *name, const char *desc,
|
||||
double default_val, double min_val, double max_val,
|
||||
LOCKMODE lockmode);
|
||||
extern void add_enum_reloption(bits32 kinds, const char *name, const char *desc,
|
||||
relopt_enum_elt_def *members, int default_val,
|
||||
const char *detailmsg, LOCKMODE lockmode);
|
||||
extern void add_string_reloption(bits32 kinds, const char *name, const char *desc,
|
||||
const char *default_val, validate_string_relopt validator,
|
||||
LOCKMODE lockmode);
|
||||
|
Reference in New Issue
Block a user