]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
gen_guc_tables.pl: Improve detection of inconsistent data
authorMichael Paquier <michael@paquier.xyz>
Tue, 17 Mar 2026 08:38:55 +0000 (17:38 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 17 Mar 2026 08:38:55 +0000 (17:38 +0900)
This commit adds two improvements to gen_guc_tables.pl:
1) When finding two entries with the same name, the script complained
about these being not in alphabetical order, which was confusing.
Duplicated entries are now reported as their own error.
2) While the presence of the required fields is checked for all the
parameters, the script did not perform any checks on the non-required
fields.  A check is added to check that any field defined matches with
what can be accepted.  Previously, a typo in the name of a required
field would cause the field to be reported as missing.  Non-mandatory
fields would be silently ignored, which was problematic as we could lose
some information.

Author: Zsolt Parragi <zsolt.parragi@percona.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAN4CZFP=3xUoXb9jpn5OWwicg+rbyrca8-tVmgJsQAa4+OExkw@mail.gmail.com

src/backend/utils/misc/gen_guc_tables.pl

index a285c62f98d3884214824b7ca8b82537239e881f..ac23e93c395e7af2485e3d194c38df0e46c3e397 100644 (file)
@@ -53,6 +53,25 @@ sub validate_guc_entry
                string => [],    # no extra required fields
        );
 
+       # All fields recognized by the generator.  "line_number" is injected
+       # by Catalog::ParseData and is not a user-facing field.
+       my %valid_fields = map { $_ => 1 } (
+               @required_common,
+               qw(long_desc flags ifdef min max options
+                 check_hook assign_hook show_hook
+                 line_number));
+
+       for my $f (sort keys %$entry)
+       {
+               unless ($valid_fields{$f})
+               {
+                       die sprintf(
+                               qq{%s:%d: error: entry "%s" has unrecognized field "%s"\n},
+                               $input_fname, $entry->{line_number},
+                               $entry->{name} // '<unknown>', $f);
+               }
+       }
+
        for my $f (@required_common)
        {
                unless (defined $entry->{$f})
@@ -98,10 +117,16 @@ sub print_table
        {
                validate_guc_entry($entry);
 
-               if (defined($prev_name) && lc($prev_name) ge lc($entry->{name}))
+               if (defined($prev_name) && lc($prev_name) eq lc($entry->{name}))
+               {
+                       die sprintf(qq{%s:%d: error: duplicate entry "%s"\n},
+                               $input_fname, $entry->{line_number}, $entry->{name});
+               }
+               if (defined($prev_name) && lc($prev_name) gt lc($entry->{name}))
                {
                        die sprintf(
-                               "entries are not in alphabetical order: \"%s\", \"%s\"\n",
+                               qq{%s:%d: error: entries are not in alphabetical order: "%s", "%s"\n},
+                               $input_fname, $entry->{line_number},
                                $prev_name, $entry->{name});
                }