v2-0005-Enforce-alphabetical-order-in-guc_parameters.dat.patch

text/plain

Filename: v2-0005-Enforce-alphabetical-order-in-guc_parameters.dat.patch
Type: text/plain
Part: 4
Message: Re: Reorganize GUC structs

Patch

Format: format-patch
Series: patch v2-0005
Subject: Enforce alphabetical order in guc_parameters.dat
File+
src/backend/utils/misc/gen_guc_tables.pl 10 0
src/backend/utils/misc/guc_parameters.dat 1 1
From a8138309c2d643de4d4c637583e04aba9cee34af Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Fri, 3 Oct 2025 08:27:18 +0200
Subject: [PATCH v2 5/5] Enforce alphabetical order in guc_parameters.dat

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.

Note: The order is actually checked after lower-casing, to handle the
likes of "DateStyle".

Discussion: https://www.postgresql.org/message-id/flat/8fdfb91e-60fb-44fa-8df6-f5dea47353c9@eisentraut.org
---
 src/backend/utils/misc/gen_guc_tables.pl  | 10 ++++++++++
 src/backend/utils/misc/guc_parameters.dat |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/backend/utils/misc/gen_guc_tables.pl b/src/backend/utils/misc/gen_guc_tables.pl
index 3efde02bab8..601c34ec30b 100644
--- a/src/backend/utils/misc/gen_guc_tables.pl
+++ b/src/backend/utils/misc/gen_guc_tables.pl
@@ -42,6 +42,7 @@ sub dquote
 sub print_table
 {
 	my ($ofh) = @_;
+	my $prev_name = undef;
 
 	print $ofh "\n\n";
 	print $ofh "struct config_generic ConfigureNames[] =\n";
@@ -49,6 +50,13 @@ sub print_table
 
 	foreach my $entry (@{$parse})
 	{
+		if (defined($prev_name) && lc($prev_name) ge lc($entry->{name}))
+		{
+			die sprintf(
+				"entries are not in alphabetical order: \"%s\", \"%s\"\n",
+				$prev_name, $entry->{name});
+		}
+
 		print $ofh "#ifdef $entry->{ifdef}\n" if $entry->{ifdef};
 		print $ofh "\t{\n";
 		printf $ofh "\t\t.name = %s,\n", dquote($entry->{name});
@@ -80,6 +88,8 @@ sub print_table
 		print $ofh "\t},\n";
 		print $ofh "#endif\n" if $entry->{ifdef};
 		print $ofh "\n";
+
+		$prev_name = $entry->{name};
 	}
 
 	print $ofh "\t/* End-of-list marker */\n";
diff --git a/src/backend/utils/misc/guc_parameters.dat b/src/backend/utils/misc/guc_parameters.dat
index f7be908b4ed..25da769eb35 100644
--- a/src/backend/utils/misc/guc_parameters.dat
+++ b/src/backend/utils/misc/guc_parameters.dat
@@ -23,7 +23,7 @@
 # 3. Decide on a name, a default value, upper and lower bounds (if
 #    applicable), etc.
 #
-# 4. Add a record below.
+# 4. Add a record below (in alphabetical order).
 #
 # 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
 #    appropriate.
-- 
2.51.0