summaryrefslogtreecommitdiff
path: root/src/include/access/reloptions.h
diff options
context:
space:
mode:
authorAlexander Korotkov2020-03-30 16:17:11 +0000
committerAlexander Korotkov2020-03-30 16:17:23 +0000
commit911e70207703799605f5a0e8aad9f06cff067c63 (patch)
tree5cdbffea1945c2c0b766db195a55bcb372d60537 /src/include/access/reloptions.h
parent1d53432ff940b789c2431ba476a2a6e2db3edf84 (diff)
Implement operator class parameters
PostgreSQL provides set of template index access methods, where opclasses have much freedom in the semantics of indexing. These index AMs are GiST, GIN, SP-GiST and BRIN. There opclasses define representation of keys, operations on them and supported search strategies. So, it's natural that opclasses may be faced some tradeoffs, which require user-side decision. This commit implements opclass parameters allowing users to set some values, which tell opclass how to index the particular dataset. This commit doesn't introduce new storage in system catalog. Instead it uses pg_attribute.attoptions, which is used for table column storage options but unused for index attributes. In order to evade changing signature of each opclass support function, we implement unified way to pass options to opclass support functions. Options are set to fn_expr as the constant bytea expression. It's possible due to the fact that opclass support functions are executed outside of expressions, so fn_expr is unused for them. This commit comes with some examples of opclass options usage. We parametrize signature length in GiST. That applies to multiple opclasses: tsvector_ops, gist__intbig_ops, gist_ltree_ops, gist__ltree_ops, gist_trgm_ops and gist_hstore_ops. Also we parametrize maximum number of integer ranges for gist__int_ops. However, the main future usage of this feature is expected to be json, where users would be able to specify which way to index particular json parts. Catversion is bumped. Discussion: https://postgr.es/m/d22c3a18-31c7-1879-fc11-4c1ce2f5e5af%40postgrespro.ru Author: Nikita Glukhov, revised by me Reviwed-by: Nikolay Shaplov, Robert Haas, Tom Lane, Tomas Vondra, Alvaro Herrera
Diffstat (limited to 'src/include/access/reloptions.h')
-rw-r--r--src/include/access/reloptions.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/include/access/reloptions.h b/src/include/access/reloptions.h
index 36e6472768f..5964438cb0c 100644
--- a/src/include/access/reloptions.h
+++ b/src/include/access/reloptions.h
@@ -38,6 +38,7 @@ typedef enum relopt_type
/* kinds supported by reloptions */
typedef enum relopt_kind
{
+ RELOPT_KIND_LOCAL = 0,
RELOPT_KIND_HEAP = (1 << 0),
RELOPT_KIND_TOAST = (1 << 1),
RELOPT_KIND_BTREE = (1 << 2),
@@ -130,6 +131,10 @@ typedef struct relopt_enum
/* validation routines for strings */
typedef void (*validate_string_relopt) (const char *value);
+typedef Size (*fill_string_relopt) (const char *value, void *ptr);
+
+/* validation routine for the whole option set */
+typedef void (*relopts_validator) (void *parsed_options, relopt_value *vals, int nvals);
typedef struct relopt_string
{
@@ -137,6 +142,7 @@ typedef struct relopt_string
int default_len;
bool default_isnull;
validate_string_relopt validate_cb;
+ fill_string_relopt fill_cb;
char *default_val;
} relopt_string;
@@ -148,6 +154,21 @@ typedef struct
int offset; /* offset of field in result struct */
} relopt_parse_elt;
+/* Local reloption definition */
+typedef struct local_relopt
+{
+ relopt_gen *option; /* option definition */
+ int offset; /* offset of parsed value in bytea structure */
+} local_relopt;
+
+/* Structure to hold local reloption data for build_local_reloptions() */
+typedef struct local_relopts
+{
+ List *options; /* list of local_relopt definitions */
+ List *validators; /* list of relopts_validator callbacks */
+ Size relopt_struct_size; /* size of parsed bytea structure */
+} local_relopts;
+
/*
* Utility macro to get a value for a string reloption once the options
* are parsed. This gets a pointer to the string value itself. "optstruct"
@@ -174,6 +195,30 @@ extern void add_string_reloption(bits32 kinds, const char *name, const char *des
const char *default_val, validate_string_relopt validator,
LOCKMODE lockmode);
+extern void init_local_reloptions(local_relopts *opts, Size relopt_struct_size);
+extern void register_reloptions_validator(local_relopts *opts,
+ relopts_validator validator);
+extern void add_local_bool_reloption(local_relopts *opts, const char *name,
+ const char *desc, bool default_val,
+ int offset);
+extern void add_local_int_reloption(local_relopts *opts, const char *name,
+ const char *desc, int default_val,
+ int min_val, int max_val, int offset);
+extern void add_local_real_reloption(local_relopts *opts, const char *name,
+ const char *desc, double default_val,
+ double min_val, double max_val,
+ int offset);
+extern void add_local_enum_reloption(local_relopts *relopts,
+ const char *name, const char *desc,
+ relopt_enum_elt_def *members,
+ int default_val, const char *detailmsg,
+ int offset);
+extern void add_local_string_reloption(local_relopts *opts, const char *name,
+ const char *desc,
+ const char *default_val,
+ validate_string_relopt validator,
+ fill_string_relopt filler, int offset);
+
extern Datum transformRelOptions(Datum oldOptions, List *defList,
const char *namspace, char *validnsps[],
bool acceptOidsOff, bool isReset);
@@ -185,6 +230,8 @@ extern void *build_reloptions(Datum reloptions, bool validate,
Size relopt_struct_size,
const relopt_parse_elt *relopt_elems,
int num_relopt_elems);
+extern void *build_local_reloptions(local_relopts *relopts, Datum options,
+ bool validate);
extern bytea *default_reloptions(Datum reloptions, bool validate,
relopt_kind kind);