Reorganize GUC structs

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Reorganize GUC structs
Date: 2025-10-03 06:55:10
Message-ID: 8fdfb91e-60fb-44fa-8df6-f5dea47353c9@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

This patch series does some reorganizing of the GUC table structs
(config_generic, config_bool, etc.) to modernize and simplify things. I
suspect that some changes like these would have been desirable as the
GUC code has evolved over time, but were avoided because of the burden
of having to adjust all the static GUC tables at the same time. Since
these are now generated, this is no longer a problem.

The main change is that instead of having five separate structs, one for
each type, with the generic part contained in each of them, flip it
around and have one common struct, with the type-specific part has a
subfield.

The very original GUC design had type-specific structs and
type-specific lists, and the membership in one of the lists defined
the type. But now the structs themselves know the type (from the
.vartype field), and they are all loaded into a common hash table at
run time, this original separation no longer makes sense. It creates
a bunch of inconsistencies in the code about whether the type-specific
or the generic struct is the primary struct, and a lot of casting in
between, which makes certain assumptions about the struct layouts.

After the change, all these casts are gone and all the data is
accessed via normal field references. Also, various code is
simplified because only one kind of struct needs to be processed.

Additionally, I have sorted guc_parameters.dat alphabetically by name,
and have added code to enforce the sort order going forward. (Note: The
order is actually checked after lower-casing, to handle the likes of
"DateStyle".)

The order in these lists was previously pretty random and had grown
organically over time. This made it unnecessarily cumbersome to
maintain these lists, as there was no clear guidelines about where to
put new entries. Also, after the merger of the type-specific GUC
structs, the list still reflected the previous type-specific
super-order.

By enforcing alphabetical order, the place for new entries becomes
clear, and often related entries will be listed close together.

The patches in the series are arranged so that they can be considered
and applied incrementally.

Attachment Content-Type Size
v1-0001-Modernize-some-for-loops.patch text/plain 18.9 KB
v1-0002-Add-some-const-qualifiers.patch text/plain 14.6 KB
v1-0003-Change-reset_extra-into-a-config_generic-common-f.patch text/plain 12.9 KB
v1-0004-Use-designated-initializers-for-guc_tables.patch text/plain 3.2 KB
v1-0005-Change-config_generic.vartype-to-be-initialized-a.patch text/plain 3.6 KB
v1-0006-Reorganize-GUC-structs.patch text/plain 89.3 KB
v1-0007-Sort-guc_parameters.dat-alphabetically-by-name.patch text/plain 270.9 KB
v1-0008-Enforce-alphabetical-order-in-guc_parameters.dat.patch text/plain 2.4 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2025-10-03 07:01:26 Re: anonymous unions (C11)
Previous Message Ashutosh Bapat 2025-10-03 06:52:05 Re: Report bytes and transactions actually sent downtream