Skip to content

Commit 995e0fb

Browse files
committed
Un-break genbki.pl's error reporting capabilities.
This essentially reverts commit 69eb643, which added a fast path in Catalog::ParseData, but neglected to preserve the behavior of adding a line_number field in each hash. That makes it impossible for genbki.pl to provide any localization of error reports, which is bad enough; but actually the affected error reports failed entirely, producing useless bleats like "use of undefined value in sprintf". 69eb643 claimed to get a 15% speedup, but I'm not sure I believe that: the time to rebuild the bki files changes by less than 1% for me. In any case, making debugging of mistakes in .dat files more difficult would not be justified by even an order of magnitude speedup here; it's just not that big a chunk of the total build time. Per report from David Wheeler. Although it's also broken in v16, I don't think this is worth a back-patch, since we're very unlikely to touch the v16 catalog data again. Discussion: https://postgr.es/m/19238.1710953049@sss.pgh.pa.us
1 parent 1218ca9 commit 995e0fb

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

src/backend/catalog/Catalog.pm

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -300,21 +300,21 @@ sub ParseHeader
300300

301301
# Parses a file containing Perl data structure literals, returning live data.
302302
#
303-
# The parameter $preserve_formatting needs to be set for callers that want
303+
# The parameter $preserve_comments needs to be set for callers that want
304304
# to work with non-data lines in the data files, such as comments and blank
305305
# lines. If a caller just wants to consume the data, leave it unset.
306+
# (When requested, non-data lines will be returned as array entries that
307+
# are strings not hashes, so extra code is needed to deal with that.)
306308
sub ParseData
307309
{
308-
my ($input_file, $schema, $preserve_formatting) = @_;
310+
my ($input_file, $schema, $preserve_comments) = @_;
309311

310312
open(my $ifd, '<', $input_file) || die "$input_file: $!";
311313
$input_file =~ /(\w+)\.dat$/
312314
or die "Input file $input_file needs to be a .dat file.\n";
313315
my $catname = $1;
314316
my $data = [];
315317

316-
if ($preserve_formatting)
317-
{
318318
# Scan the input file.
319319
while (<$ifd>)
320320
{
@@ -369,31 +369,17 @@ sub ParseData
369369
# with --full-tuples to print autogenerated entries, which seems like
370370
# useful behavior for debugging.)
371371
#
372-
# Otherwise, we have a non-data string, which we need to keep in
373-
# order to preserve formatting.
372+
# Otherwise, we have a non-data string, which we keep only if
373+
# the caller requested it.
374374
if (defined $hash_ref)
375375
{
376376
push @$data, $hash_ref if !$hash_ref->{autogenerated};
377377
}
378378
else
379379
{
380-
push @$data, $_;
380+
push @$data, $_ if $preserve_comments;
381381
}
382382
}
383-
}
384-
else
385-
{
386-
# When we only care about the contents, it's faster to read and eval
387-
# the whole file at once.
388-
local $/;
389-
my $full_file = <$ifd>;
390-
eval "\$data = $full_file" ## no critic (ProhibitStringyEval)
391-
or die "error parsing $input_file\n";
392-
foreach my $hash_ref (@{$data})
393-
{
394-
AddDefaultValues($hash_ref, $schema, $catname);
395-
}
396-
}
397383

398384
close $ifd;
399385

0 commit comments

Comments
 (0)