Skip to content

Commit c23f0a5

Browse files
nataraj-hates-MS-for-stealing-githubCommitfest Bot
authored andcommitted
Add alias to be used as "unset" state.
Add `unset_alias` string parameter to ternary reloption definition. This will allow user explicitly switch ternary option to "unset" state. Use this feature to implement `vacuum_index_cleanup` and gist's `buffering` reloptions as ternary reloptions
1 parent 907c510 commit c23f0a5

File tree

7 files changed

+54
-82
lines changed

7 files changed

+54
-82
lines changed

src/backend/access/common/reloptions.c

Lines changed: 39 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@ static relopt_ternary ternaryRelOpts[] =
170170
RELOPT_KIND_HEAP | RELOPT_KIND_TOAST,
171171
ShareUpdateExclusiveLock
172172
},
173+
NULL,
174+
TERNARY_UNSET
175+
},
176+
{
177+
{
178+
"vacuum_index_cleanup",
179+
"Controls index vacuuming and index cleanup",
180+
RELOPT_KIND_HEAP | RELOPT_KIND_TOAST,
181+
ShareUpdateExclusiveLock
182+
},
183+
"auto",
184+
TERNARY_UNSET
185+
},
186+
{
187+
{
188+
"buffering",
189+
"Enables buffering build for this GiST index",
190+
RELOPT_KIND_GIST,
191+
AccessExclusiveLock
192+
},
193+
"auto",
173194
TERNARY_UNSET
174195
},
175196
/* list terminator */
@@ -498,30 +519,6 @@ static relopt_real realRelOpts[] =
498519
{{NULL}}
499520
};
500521

501-
/* values from StdRdOptIndexCleanup */
502-
static relopt_enum_elt_def StdRdOptIndexCleanupValues[] =
503-
{
504-
{"auto", STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO},
505-
{"on", STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON},
506-
{"off", STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF},
507-
{"true", STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON},
508-
{"false", STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF},
509-
{"yes", STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON},
510-
{"no", STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF},
511-
{"1", STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON},
512-
{"0", STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF},
513-
{(const char *) NULL} /* list terminator */
514-
};
515-
516-
/* values from GistOptBufferingMode */
517-
static relopt_enum_elt_def gistBufferingOptValues[] =
518-
{
519-
{"auto", GIST_OPTION_BUFFERING_AUTO},
520-
{"on", GIST_OPTION_BUFFERING_ON},
521-
{"off", GIST_OPTION_BUFFERING_OFF},
522-
{(const char *) NULL} /* list terminator */
523-
};
524-
525522
/* values from ViewOptCheckOption */
526523
static relopt_enum_elt_def viewCheckOptValues[] =
527524
{
@@ -533,28 +530,6 @@ static relopt_enum_elt_def viewCheckOptValues[] =
533530

534531
static relopt_enum enumRelOpts[] =
535532
{
536-
{
537-
{
538-
"vacuum_index_cleanup",
539-
"Controls index vacuuming and index cleanup",
540-
RELOPT_KIND_HEAP | RELOPT_KIND_TOAST,
541-
ShareUpdateExclusiveLock
542-
},
543-
StdRdOptIndexCleanupValues,
544-
STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO,
545-
gettext_noop("Valid values are \"on\", \"off\", and \"auto\".")
546-
},
547-
{
548-
{
549-
"buffering",
550-
"Enables buffering build for this GiST index",
551-
RELOPT_KIND_GIST,
552-
AccessExclusiveLock
553-
},
554-
gistBufferingOptValues,
555-
GIST_OPTION_BUFFERING_AUTO,
556-
gettext_noop("Valid values are \"on\", \"off\", and \"auto\".")
557-
},
558533
{
559534
{
560535
"check_option",
@@ -922,13 +897,14 @@ add_local_bool_reloption(local_relopts *relopts, const char *name,
922897
*/
923898
static relopt_ternary *
924899
init_ternary_reloption(bits32 kinds, const char *name, const char *desc,
925-
ternary default_val, LOCKMODE lockmode)
900+
ternary default_val, const char* unset_alias, LOCKMODE lockmode)
926901
{
927902
relopt_ternary *newoption;
928903

929904
newoption = (relopt_ternary *) allocate_reloption(kinds,
930905
RELOPT_TYPE_TERNARY, name, desc, lockmode);
931906
newoption->default_val = default_val;
907+
newoption->unset_alias = unset_alias;
932908

933909
return newoption;
934910
}
@@ -939,10 +915,10 @@ init_ternary_reloption(bits32 kinds, const char *name, const char *desc,
939915
*/
940916
void
941917
add_ternary_reloption(bits32 kinds, const char *name, const char *desc,
942-
ternary default_val, LOCKMODE lockmode)
918+
ternary default_val, const char* unset_alias, LOCKMODE lockmode)
943919
{
944920
relopt_ternary *newoption = init_ternary_reloption(kinds, name, desc,
945-
default_val, lockmode);
921+
default_val, unset_alias, lockmode);
946922

947923
add_reloption((relopt_gen *) newoption);
948924
}
@@ -956,11 +932,11 @@ add_ternary_reloption(bits32 kinds, const char *name, const char *desc,
956932
void
957933
add_local_ternary_reloption(local_relopts *relopts, const char *name,
958934
const char *desc, ternary default_val,
959-
int offset)
935+
const char* unset_alias, int offset)
960936
{
961937
relopt_ternary *newoption = init_ternary_reloption(RELOPT_KIND_LOCAL,
962938
name, desc,
963-
default_val, 0);
939+
default_val, unset_alias, 0);
964940

965941
add_local_reloption(relopts, (relopt_gen *) newoption, offset);
966942
}
@@ -1701,8 +1677,19 @@ parse_one_reloption(relopt_value *option, char *text_str, int text_len,
17011677
case RELOPT_TYPE_TERNARY:
17021678
{
17031679
bool b;
1680+
relopt_ternary *opt = (relopt_ternary *) option->gen;
1681+
17041682
parsed = parse_bool(value, &b);
17051683
option->values.ternary_val = b ? TERNARY_TRUE : TERNARY_FALSE;
1684+
1685+
if (!parsed && opt->unset_alias)
1686+
{
1687+
if (pg_strcasecmp(value, opt->unset_alias) == 0)
1688+
{
1689+
option->values.ternary_val = TERNARY_UNSET;
1690+
parsed = true;
1691+
}
1692+
}
17061693
if (validate && !parsed)
17071694
ereport(ERROR,
17081695
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -1999,7 +1986,7 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
19991986
offsetof(StdRdOptions, user_catalog_table)},
20001987
{"parallel_workers", RELOPT_TYPE_INT,
20011988
offsetof(StdRdOptions, parallel_workers)},
2002-
{"vacuum_index_cleanup", RELOPT_TYPE_ENUM,
1989+
{"vacuum_index_cleanup", RELOPT_TYPE_TERNARY,
20031990
offsetof(StdRdOptions, vacuum_index_cleanup)},
20041991
{"vacuum_truncate", RELOPT_TYPE_TERNARY,
20051992
offsetof(StdRdOptions, vacuum_truncate)},

src/backend/access/gist/gistbuild.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ gistbuild(Relation heap, Relation index, IndexInfo *indexInfo)
213213
*/
214214
if (options)
215215
{
216-
if (options->buffering_mode == GIST_OPTION_BUFFERING_ON)
216+
if (options->buffering_mode == TERNARY_TRUE)
217217
buildstate.buildMode = GIST_BUFFERING_STATS;
218-
else if (options->buffering_mode == GIST_OPTION_BUFFERING_OFF)
218+
else if (options->buffering_mode == TERNARY_FALSE)
219219
buildstate.buildMode = GIST_BUFFERING_DISABLED;
220220
else /* must be "auto" */
221221
buildstate.buildMode = GIST_BUFFERING_AUTO;

src/backend/commands/vacuum.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,22 +2169,21 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams params,
21692169
*/
21702170
if (params.index_cleanup == VACOPTVALUE_UNSPECIFIED)
21712171
{
2172-
StdRdOptIndexCleanup vacuum_index_cleanup;
2172+
ternary vacuum_index_cleanup;
21732173

21742174
if (rel->rd_options == NULL)
2175-
vacuum_index_cleanup = STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO;
2175+
vacuum_index_cleanup = TERNARY_UNSET;
21762176
else
21772177
vacuum_index_cleanup =
21782178
((StdRdOptions *) rel->rd_options)->vacuum_index_cleanup;
21792179

2180-
if (vacuum_index_cleanup == STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO)
2180+
if (vacuum_index_cleanup == TERNARY_UNSET)
21812181
params.index_cleanup = VACOPTVALUE_AUTO;
2182-
else if (vacuum_index_cleanup == STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON)
2182+
else if (vacuum_index_cleanup == TERNARY_TRUE)
21832183
params.index_cleanup = VACOPTVALUE_ENABLED;
21842184
else
21852185
{
2186-
Assert(vacuum_index_cleanup ==
2187-
STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF);
2186+
Assert(vacuum_index_cleanup == TERNARY_FALSE);
21882187
params.index_cleanup = VACOPTVALUE_DISABLED;
21892188
}
21902189
}

src/include/access/gist_private.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -380,22 +380,14 @@ typedef struct GISTBuildBuffers
380380
int rootlevel;
381381
} GISTBuildBuffers;
382382

383-
/* GiSTOptions->buffering_mode values */
384-
typedef enum GistOptBufferingMode
385-
{
386-
GIST_OPTION_BUFFERING_AUTO,
387-
GIST_OPTION_BUFFERING_ON,
388-
GIST_OPTION_BUFFERING_OFF,
389-
} GistOptBufferingMode;
390-
391383
/*
392384
* Storage type for GiST's reloptions
393385
*/
394386
typedef struct GiSTOptions
395387
{
396388
int32 vl_len_; /* varlena header (do not touch directly!) */
397389
int fillfactor; /* page fill factor in percent (0..100) */
398-
GistOptBufferingMode buffering_mode; /* buffering build mode */
390+
ternary buffering_mode; /* buffering build mode */
399391
} GiSTOptions;
400392

401393
/* gist.c */

src/include/access/reloptions.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ typedef struct relopt_bool
9999
typedef struct relopt_rernary
100100
{
101101
relopt_gen gen;
102+
const char *unset_alias; /* word that will be treated as unset value */
102103
int default_val;
103104
} relopt_ternary;
104105

@@ -191,7 +192,8 @@ extern relopt_kind add_reloption_kind(void);
191192
extern void add_bool_reloption(bits32 kinds, const char *name, const char *desc,
192193
bool default_val, LOCKMODE lockmode);
193194
extern void add_ternary_reloption(bits32 kinds, const char *name,
194-
const char *desc, int default_val, LOCKMODE lockmode);
195+
const char *desc, ternary default_val,
196+
const char* unset_alias, LOCKMODE lockmode);
195197
extern void add_int_reloption(bits32 kinds, const char *name, const char *desc,
196198
int default_val, int min_val, int max_val,
197199
LOCKMODE lockmode);
@@ -213,7 +215,8 @@ extern void add_local_bool_reloption(local_relopts *relopts, const char *name,
213215
int offset);
214216
extern void add_local_ternary_reloption(local_relopts *relopts,
215217
const char *name, const char *desc,
216-
ternary default_val, int offset);
218+
ternary default_val, const char* unset_alias,
219+
int offset);
217220
extern void add_local_int_reloption(local_relopts *relopts, const char *name,
218221
const char *desc, int default_val,
219222
int min_val, int max_val, int offset);

src/include/utils/rel.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,6 @@ typedef struct AutoVacOpts
330330
float8 analyze_scale_factor;
331331
} AutoVacOpts;
332332

333-
/* StdRdOptions->vacuum_index_cleanup values */
334-
typedef enum StdRdOptIndexCleanup
335-
{
336-
STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO = 0,
337-
STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF,
338-
STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON,
339-
} StdRdOptIndexCleanup;
340-
341333
typedef struct StdRdOptions
342334
{
343335
int32 vl_len_; /* varlena header (do not touch directly!) */
@@ -346,7 +338,7 @@ typedef struct StdRdOptions
346338
AutoVacOpts autovacuum; /* autovacuum-related options */
347339
bool user_catalog_table; /* use as an additional catalog relation */
348340
int parallel_workers; /* max number of parallel workers */
349-
StdRdOptIndexCleanup vacuum_index_cleanup; /* controls index vacuuming */
341+
ternary vacuum_index_cleanup; /* controls index vacuuming */
350342
ternary vacuum_truncate; /* enables vacuum to truncate a relation */
351343

352344
/*

src/test/regress/expected/gist.out

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ create index gist_pointidx4 on gist_point_tbl using gist(p) with (buffering = au
1212
drop index gist_pointidx2, gist_pointidx3, gist_pointidx4;
1313
-- Make sure bad values are refused
1414
create index gist_pointidx5 on gist_point_tbl using gist(p) with (buffering = invalid_value);
15-
ERROR: invalid value for enum option "buffering": invalid_value
16-
DETAIL: Valid values are "on", "off", and "auto".
15+
ERROR: invalid value for ternary option "buffering": invalid_value
1716
create index gist_pointidx5 on gist_point_tbl using gist(p) with (fillfactor=9);
1817
ERROR: value 9 out of bounds for option "fillfactor"
1918
DETAIL: Valid values are between "10" and "100".

0 commit comments

Comments
 (0)