Re: Reorganize GUC structs
Peter Eisentraut <peter@eisentraut.org>
From: Peter Eisentraut <peter@eisentraut.org>
To: Chao Li <li.evan.chao@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-10-15T14:05:29Z
Lists: pgsql-hackers
Attachments
- v2-0001-Use-designated-initializers-for-guc_tables.patch (text/plain) patch v2-0001
- v2-0002-Change-config_generic.vartype-to-be-initialized-a.patch (text/plain) patch v2-0002
- v2-0003-Reorganize-GUC-structs.patch (text/plain) patch v2-0003
- v2-0004-Sort-guc_parameters.dat-alphabetically-by-name.patch (text/plain) patch v2-0004
- v2-0005-Enforce-alphabetical-order-in-guc_parameters.dat.patch (text/plain) patch v2-0005
On 09.10.25 09:15, Chao Li wrote:
> 0001 - looks good to me. Basically it only moves for loop’s loop
> variable type definition into for(), it isn’t tied to rest commits, I
> guess it can be pushed independently.
>
> 0002 - also looks good. It just add “const” where possible. I think it
> can be pushed together with 0001.
>
> 0003 - also looks good. It moves “reset_extra” from individual typed
> config structure to “config_generic”, which dramatically eliminates
> unnecessary switch-cases.
I have committed these first three. Attached is the rest of the patch
series rebased.
It looks like we have consensus in principle on the remaining changes,
but I'll leave them out here a while longer in case there are any
further thoughts.
Regarding ...
> Just a small comment:
>
> ```
> @@ -6244,29 +6217,11 @@ RestoreGUCState(void *gucstate)
> switch (gconf->vartype)
> {
> case PGC_BOOL:
> -{
> -struct config_bool *conf = (struct config_bool *) gconf;
> -
> -if (conf->reset_extra && conf->reset_extra != gconf->extra)
> -guc_free(conf->reset_extra);
> -break;
> -}
> case PGC_INT:
> -{
> -struct config_int *conf = (struct config_int *) gconf;
> -
> -if (conf->reset_extra && conf->reset_extra != gconf->extra)
> -guc_free(conf->reset_extra);
> -break;
> -}
> case PGC_REAL:
> -{
> -struct config_real *conf = (struct config_real *) gconf;
> -
> -if (conf->reset_extra && conf->reset_extra != gconf->extra)
> -guc_free(conf->reset_extra);
> -break;
> -}
> +case PGC_ENUM:
> +/* no need to do anything */
> +break;
> case PGC_STRING:
> {
> struct config_string *conf = (struct config_string *) gconf;
> @@ -6274,19 +6229,11 @@ RestoreGUCState(void *gucstate)
> guc_free(*conf->variable);
> if (conf->reset_val && conf->reset_val != *conf->variable)
> guc_free(conf->reset_val);
> -if (conf->reset_extra && conf->reset_extra != gconf->extra)
> -guc_free(conf->reset_extra);
> -break;
> -}
> -case PGC_ENUM:
> -{
> -struct config_enum *conf = (struct config_enum *) gconf;
> -
> -if (conf->reset_extra && conf->reset_extra != gconf->extra)
> -guc_free(conf->reset_extra);
> break;
> }
> }
> ```
>
> Do we still need this switch-case? As only PGC_STRING needs to do
> something, why not just do:
>
> ```
> If (gconf-vartype == PGC_STRING)
> {
> …
> }
> if (gconf->reset_extra && gconf->reset_extra != gconf->extra)
> guc_free(gconf->reset_extra);
> ```
I initially had it like that, but there are a couple of other places in
the existing code that have a switch with only actual code for
PGC_STRING, so I ended up following that pattern.
Commits
-
Remove extraneous newlines from guc_parameters.dat
- a7f59b252a8e 19 (unreleased) landed
-
Fix NLS for incorrect GUC enum value hint message
- 0fc33b00536c 19 (unreleased) landed
-
Clean up qsort comparison function for GUC entries
- d2f24df19b7a 19 (unreleased) landed
-
Sort guc_parameters.dat alphabetically by name
- fce7c73fba4e 19 (unreleased) landed
-
Reorganize GUC structs
- a13833c35f9e 19 (unreleased) landed
-
Change config_generic.vartype to be initialized at compile time
- e1a912c86d52 19 (unreleased) landed
-
Use designated initializers for guc_tables
- 0a7bde461016 19 (unreleased) landed
-
Change reset_extra into a config_generic common field
- 5f4c3b33a976 19 (unreleased) landed
-
Add some const qualifiers
- 29dc7a668753 19 (unreleased) landed
-
Modernize some for loops
- 1a795188889c 19 (unreleased) landed