Skip to content

Commit 45c6d75

Browse files
committed
Clarify handling of special-case values in bootstrap catalog data.
I (tgl) originally coded the special case for pg_proc.pronargs as though it were a kind of default value. It seems better though to treat computable columns as an independent concern: this makes the code clearer, and probably a bit faster too since we needn't do work inside the per-column loop. Improve related comments, as well, in the expectation that there might be more cases like this in future. John Naylor, some additional comment-hacking by me Discussion: https://postgr.es/m/CAJVSVGW-D7OobzU=dybVT2JqZAx-4X1yvBJdavBmqQL05Q6CLw@mail.gmail.com
1 parent f2bb32d commit 45c6d75

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

src/backend/catalog/Catalog.pm

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,21 @@ sub AddDefaultValues
292292
my ($row, $schema, $catname) = @_;
293293
my @missing_fields;
294294

295+
# Compute special-case column values.
296+
# Note: If you add new cases here, you must also teach
297+
# strip_default_values() in include/catalog/reformat_dat_file.pl
298+
# to delete them.
299+
if ($catname eq 'pg_proc')
300+
{
301+
# pg_proc.pronargs can be derived from proargtypes.
302+
if (defined $row->{proargtypes})
303+
{
304+
my @proargtypes = split /\s+/, $row->{proargtypes};
305+
$row->{pronargs} = scalar(@proargtypes);
306+
}
307+
}
308+
309+
# Now fill in defaults, and note any columns that remain undefined.
295310
foreach my $column (@$schema)
296311
{
297312
my $attname = $column->{name};
@@ -305,21 +320,14 @@ sub AddDefaultValues
305320
{
306321
$row->{$attname} = $column->{default};
307322
}
308-
elsif ($catname eq 'pg_proc'
309-
&& $attname eq 'pronargs'
310-
&& defined($row->{proargtypes}))
311-
{
312-
# pg_proc.pronargs can be derived from proargtypes.
313-
my @proargtypes = split /\s+/, $row->{proargtypes};
314-
$row->{$attname} = scalar(@proargtypes);
315-
}
316323
else
317324
{
318325
# Failed to find a value.
319326
push @missing_fields, $attname;
320327
}
321328
}
322329

330+
# Failure to provide all columns is a hard error.
323331
if (@missing_fields)
324332
{
325333
die sprintf "missing values for field(s) %s in %s.dat line %s\n",

src/include/catalog/pg_proc.dat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
# "convert srctypename to desttypename" for cast functions
3131
# "less-equal-greater" for B-tree comparison functions
3232

33+
# Note: pronargs is computed when this file is read, so it does not need
34+
# to be specified in entries here. See AddDefaultValues() in Catalog.pm.
35+
3336
# Once upon a time these entries were ordered by OID. Lately it's often
3437
# been the custom to insert new entries adjacent to related older entries.
3538
# Try to do one or the other though, don't just insert entries at random.

src/include/catalog/reformat_dat_file.pl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,31 +177,31 @@
177177
close $dat;
178178
}
179179

180-
# Leave values out if there is a matching default.
180+
# Remove column values for which there is a matching default,
181+
# or if the value can be computed from other columns.
181182
sub strip_default_values
182183
{
183184
my ($row, $schema, $catname) = @_;
184185

186+
# Delete values that match defaults.
185187
foreach my $column (@$schema)
186188
{
187189
my $attname = $column->{name};
188190
die "strip_default_values: $catname.$attname undefined\n"
189191
if !defined $row->{$attname};
190192

191-
# Delete values that match defaults.
192193
if (defined $column->{default}
193194
and ($row->{$attname} eq $column->{default}))
194195
{
195196
delete $row->{$attname};
196197
}
198+
}
197199

198-
# Also delete pg_proc.pronargs, since that can be recomputed.
199-
if ( $catname eq 'pg_proc'
200-
&& $attname eq 'pronargs'
201-
&& defined($row->{proargtypes}))
202-
{
203-
delete $row->{$attname};
204-
}
200+
# Delete computed values. See AddDefaultValues() in Catalog.pm.
201+
# Note: This must be done after deleting values matching defaults.
202+
if ($catname eq 'pg_proc')
203+
{
204+
delete $row->{pronargs} if defined $row->{proargtypes};
205205
}
206206
}
207207

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy