1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-22 14:32:25 +03:00

Introduce pg_settings_get_flags() to find flags associated to a GUC

The most meaningful flags are shown, which are the ones useful for the
user and for automating and extending the set of tests supported
currently by check_guc.

This script may actually be removed in the future, but we are not
completely sure yet if and how we want to support the remaining sanity
checks performed there, that are now integrated in the main regression
test suite as of this commit.

Thanks also to Peter Eisentraut and Kyotaro Horiguchi for the
discussion.

Bump catalog version.

Author: Justin Pryzby
Discussion: https://postgr.es/m/20211129030833.GJ17618@telsasoft.com
This commit is contained in:
Michael Paquier
2022-01-31 08:56:41 +09:00
parent 02b8048ba5
commit d10e41d423
6 changed files with 208 additions and 1 deletions

View File

@@ -9634,6 +9634,45 @@ GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
return _ShowOption(record, true);
}
/*
* Return some of the flags associated to the specified GUC in the shape of
* a text array, and NULL if it does not exist. An empty array is returned
* if the GUC exists without any meaningful flags to show.
*/
Datum
pg_settings_get_flags(PG_FUNCTION_ARGS)
{
#define MAX_GUC_FLAGS 5
char *varname = TextDatumGetCString(PG_GETARG_DATUM(0));
struct config_generic *record;
int cnt = 0;
Datum flags[MAX_GUC_FLAGS];
ArrayType *a;
record = find_option(varname, false, true, ERROR);
/* return NULL if no such variable */
if (record == NULL)
PG_RETURN_NULL();
if (record->flags & GUC_EXPLAIN)
flags[cnt++] = CStringGetTextDatum("EXPLAIN");
if (record->flags & GUC_NO_RESET_ALL)
flags[cnt++] = CStringGetTextDatum("NO_RESET_ALL");
if (record->flags & GUC_NO_SHOW_ALL)
flags[cnt++] = CStringGetTextDatum("NO_SHOW_ALL");
if (record->flags & GUC_NOT_IN_SAMPLE)
flags[cnt++] = CStringGetTextDatum("NOT_IN_SAMPLE");
if (record->flags & GUC_RUNTIME_COMPUTED)
flags[cnt++] = CStringGetTextDatum("RUNTIME_COMPUTED");
Assert(cnt <= MAX_GUC_FLAGS);
/* Returns the record as Datum */
a = construct_array(flags, cnt, TEXTOID, -1, false, TYPALIGN_INT);
PG_RETURN_ARRAYTYPE_P(a);
}
/*
* Return GUC variable value by variable number; optionally return canonical
* form of name. Return value is palloc'd.