summaryrefslogtreecommitdiff
path: root/src/test/modules
diff options
context:
space:
mode:
authorAlvaro Herrera2019-09-25 18:56:52 +0000
committerAlvaro Herrera2019-09-25 18:56:52 +0000
commit773df883e8f7543958d0d719c025b5f47c5a67f0 (patch)
tree1d27ebb1f3a767e20ebd9c4ccf1a8f2b16baf9bb /src/test/modules
parentcaba97a9d9f4d4fa2531985fd12d3cd823da06f3 (diff)
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
Diffstat (limited to 'src/test/modules')
-rw-r--r--src/test/modules/dummy_index_am/dummy_index_am.c37
-rw-r--r--src/test/modules/dummy_index_am/sql/reloptions.sql10
2 files changed, 40 insertions, 7 deletions
diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c
index 59a918bd613..bc68767f3a0 100644
--- a/src/test/modules/dummy_index_am/dummy_index_am.c
+++ b/src/test/modules/dummy_index_am/dummy_index_am.c
@@ -25,11 +25,16 @@ PG_MODULE_MAGIC;
void _PG_init(void);
/* parse table for fillRelOptions */
-relopt_parse_elt di_relopt_tab[5];
+relopt_parse_elt di_relopt_tab[6];
/* Kind of relation options for dummy index */
relopt_kind di_relopt_kind;
+typedef enum DummyAmEnum {
+ DUMMY_AM_ENUM_ONE,
+ DUMMY_AM_ENUM_TWO
+} DummyAmEnum;
+
/* Dummy index options */
typedef struct DummyIndexOptions
{
@@ -37,10 +42,18 @@ typedef struct DummyIndexOptions
int option_int;
double option_real;
bool option_bool;
+ DummyAmEnum option_enum;
int option_string_val_offset;
int option_string_null_offset;
} DummyIndexOptions;
+relopt_enum_elt_def dummyAmEnumValues[] =
+{
+ {"one", DUMMY_AM_ENUM_ONE},
+ {"two", DUMMY_AM_ENUM_TWO},
+ {(const char *)NULL} /* list terminator */
+};
+
/* Handler for index AM */
PG_FUNCTION_INFO_V1(dihandler);
@@ -85,13 +98,23 @@ create_reloptions_table(void)
di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL;
di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool);
+ add_enum_reloption(di_relopt_kind, "option_enum",
+ "Enum option for dummy_index_am",
+ dummyAmEnumValues,
+ DUMMY_AM_ENUM_ONE,
+ "Valid values are \"one\" and \"two\".",
+ AccessExclusiveLock);
+ di_relopt_tab[3].optname = "option_enum";
+ di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM;
+ di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum);
+
add_string_reloption(di_relopt_kind, "option_string_val",
"String option for dummy_index_am with non-NULL default",
"DefaultValue", &validate_string_option,
AccessExclusiveLock);
- di_relopt_tab[3].optname = "option_string_val";
- di_relopt_tab[3].opttype = RELOPT_TYPE_STRING;
- di_relopt_tab[3].offset = offsetof(DummyIndexOptions,
+ di_relopt_tab[4].optname = "option_string_val";
+ di_relopt_tab[4].opttype = RELOPT_TYPE_STRING;
+ di_relopt_tab[4].offset = offsetof(DummyIndexOptions,
option_string_val_offset);
/*
@@ -102,9 +125,9 @@ create_reloptions_table(void)
NULL, /* description */
NULL, &validate_string_option,
AccessExclusiveLock);
- di_relopt_tab[4].optname = "option_string_null";
- di_relopt_tab[4].opttype = RELOPT_TYPE_STRING;
- di_relopt_tab[4].offset = offsetof(DummyIndexOptions,
+ di_relopt_tab[5].optname = "option_string_null";
+ di_relopt_tab[5].opttype = RELOPT_TYPE_STRING;
+ di_relopt_tab[5].offset = offsetof(DummyIndexOptions,
option_string_null_offset);
}
diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql
index be3457562f1..0172cf094e6 100644
--- a/src/test/modules/dummy_index_am/sql/reloptions.sql
+++ b/src/test/modules/dummy_index_am/sql/reloptions.sql
@@ -32,12 +32,15 @@ ALTER INDEX dummy_test_idx SET (option_bool = true);
ALTER INDEX dummy_test_idx SET (option_real = 3.2);
ALTER INDEX dummy_test_idx SET (option_string_val = 'val2');
ALTER INDEX dummy_test_idx SET (option_string_null = NULL);
+ALTER INDEX dummy_test_idx SET (option_enum = 'one');
+ALTER INDEX dummy_test_idx SET (option_enum = 'three');
SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx';
-- ALTER INDEX .. RESET
ALTER INDEX dummy_test_idx RESET (option_int);
ALTER INDEX dummy_test_idx RESET (option_bool);
ALTER INDEX dummy_test_idx RESET (option_real);
+ALTER INDEX dummy_test_idx RESET (option_enum);
ALTER INDEX dummy_test_idx RESET (option_string_val);
ALTER INDEX dummy_test_idx RESET (option_string_null);
SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx';
@@ -62,6 +65,13 @@ ALTER INDEX dummy_test_idx SET (option_real = true); -- error
ALTER INDEX dummy_test_idx SET (option_real = 'val5'); -- error
SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx';
ALTER INDEX dummy_test_idx RESET (option_real);
+-- Enum
+ALTER INDEX dummy_test_idx SET (option_enum = 'one'); -- ok
+ALTER INDEX dummy_test_idx SET (option_enum = 0); -- error
+ALTER INDEX dummy_test_idx SET (option_enum = true); -- error
+ALTER INDEX dummy_test_idx SET (option_enum = 'three'); -- error
+SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx';
+ALTER INDEX dummy_test_idx RESET (option_enum);
-- String
ALTER INDEX dummy_test_idx SET (option_string_val = 4); -- ok
ALTER INDEX dummy_test_idx SET (option_string_val = 3.5); -- ok