From 0bec30078080730a8f1adf0e54060d60d6fc3015 Mon Sep 17 00:00:00 2001 From: John Naylor Date: Sat, 28 Apr 2018 15:54:14 +0700 Subject: [PATCH 1/1] Clarify special-case bootstrap values. Take special-case computation of out of the loop over all columns. This makes the code a bit more clear. It doesn't make much of a difference now, but if many columns are computed, it becomes difficult to read. Also add more comments. --- src/backend/catalog/Catalog.pm | 22 ++++++++++++++-------- src/include/catalog/pg_proc.dat | 3 +++ src/include/catalog/reformat_dat_file.pl | 13 ++++++------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm index 67d1719..a6f555c 100644 --- a/src/backend/catalog/Catalog.pm +++ b/src/backend/catalog/Catalog.pm @@ -292,6 +292,20 @@ sub AddDefaultValues my ($row, $schema, $catname) = @_; my @missing_fields; + # Compute special-case field values. + # Note: If you add new cases here, you must also teach + # strip_default_values() in include/catalog/reformat_dat_file.pl + # to delete them. + if ($catname eq 'pg_proc') + { + # pg_proc.pronargs can be derived from proargtypes. + if (defined $row->{proargtypes}) + { + my @proargtypes = split /\s+/, $row->{proargtypes}; + $row->{pronargs} = scalar(@proargtypes); + } + } + foreach my $column (@$schema) { my $attname = $column->{name}; @@ -305,14 +319,6 @@ sub AddDefaultValues { $row->{$attname} = $column->{default}; } - elsif ($catname eq 'pg_proc' - && $attname eq 'pronargs' - && defined($row->{proargtypes})) - { - # pg_proc.pronargs can be derived from proargtypes. - my @proargtypes = split /\s+/, $row->{proargtypes}; - $row->{$attname} = scalar(@proargtypes); - } else { # Failed to find a value. diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index f643f56..be37fb0 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -19,6 +19,9 @@ # duplicate the operator's comment.) initdb will supply suitable default # comments for functions referenced by pg_operator. +# Note: pronargs is computed when this file is read, so does not need to be +# specified here. See AddDefaultValues() in Catalog.pm. + # Try to follow the style of existing functions' comments. # Some recommended conventions: diff --git a/src/include/catalog/reformat_dat_file.pl b/src/include/catalog/reformat_dat_file.pl index 8ebbec6..c807d3a 100644 --- a/src/include/catalog/reformat_dat_file.pl +++ b/src/include/catalog/reformat_dat_file.pl @@ -194,14 +194,13 @@ sub strip_default_values { delete $row->{$attname}; } + } - # Also delete pg_proc.pronargs, since that can be recomputed. - if ( $catname eq 'pg_proc' - && $attname eq 'pronargs' - && defined($row->{proargtypes})) - { - delete $row->{$attname}; - } + # Delete computed values. See AddDefaultValues() in Catalog.pm. + # Note: This must be done after deleting values matching defaults. + if ($catname eq 'pg_proc') + { + delete $row->{pronargs} if defined $row->{proargtypes}; } } -- 2.7.4