mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
Minor cleanup in genbki.pl.
Separate out the pg_attribute logic of genbki.pl into its own function. Drop unnecessary "defined $catalog->{data}" check. This both narrows and shortens the data writing loop of the script. There is no functional change (the emitted files are the same as before). John Naylor Discussion: https://postgr.es/m/CAJVSVGXnLH=BSo0x-aA818f=MyQqGS5nM-GDCWAMdnvQJTRC1A@mail.gmail.com
This commit is contained in:
@ -156,8 +156,13 @@ foreach my $catname (@{ $catalogs->{names} })
|
|||||||
print $bki "open $catname\n";
|
print $bki "open $catname\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined $catalog->{data})
|
# For pg_attribute.h, we generate data entries ourselves.
|
||||||
|
# NB: pg_type.h must come before pg_attribute.h in the input list
|
||||||
|
# of catalog names, since we use info from pg_type.h here.
|
||||||
|
if ($catname eq 'pg_attribute')
|
||||||
{
|
{
|
||||||
|
gen_pg_attribute($schema, @attnames);
|
||||||
|
}
|
||||||
|
|
||||||
# Ordinary catalog with DATA line(s)
|
# Ordinary catalog with DATA line(s)
|
||||||
foreach my $row (@{ $catalog->{data} })
|
foreach my $row (@{ $catalog->{data} })
|
||||||
@ -230,79 +235,6 @@ foreach my $catname (@{ $catalogs->{names} })
|
|||||||
$row->{oid}, $catname, $row->{shdescr};
|
$row->{oid}, $catname, $row->{shdescr};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if ($catname eq 'pg_attribute')
|
|
||||||
{
|
|
||||||
|
|
||||||
# For pg_attribute.h, we generate DATA entries ourselves.
|
|
||||||
# NB: pg_type.h must come before pg_attribute.h in the input list
|
|
||||||
# of catalog names, since we use info from pg_type.h here.
|
|
||||||
foreach my $table_name (@{ $catalogs->{names} })
|
|
||||||
{
|
|
||||||
my $table = $catalogs->{$table_name};
|
|
||||||
|
|
||||||
# Currently, all bootstrapped relations also need schemapg.h
|
|
||||||
# entries, so skip if the relation isn't to be in schemapg.h.
|
|
||||||
next if !$table->{schema_macro};
|
|
||||||
|
|
||||||
$schemapg_entries{$table_name} = [];
|
|
||||||
push @tables_needing_macros, $table_name;
|
|
||||||
|
|
||||||
# Generate entries for user attributes.
|
|
||||||
my $attnum = 0;
|
|
||||||
my $priornotnull = 1;
|
|
||||||
foreach my $attr (@{ $table->{columns} })
|
|
||||||
{
|
|
||||||
$attnum++;
|
|
||||||
my %row;
|
|
||||||
$row{attnum} = $attnum;
|
|
||||||
$row{attrelid} = $table->{relation_oid};
|
|
||||||
|
|
||||||
morph_row_for_pgattr(\%row, $schema, $attr, $priornotnull);
|
|
||||||
$priornotnull &= ($row{attnotnull} eq 't');
|
|
||||||
|
|
||||||
# If it's bootstrapped, put an entry in postgres.bki.
|
|
||||||
print_bki_insert(\%row, @attnames) if $table->{bootstrap};
|
|
||||||
|
|
||||||
# Store schemapg entries for later.
|
|
||||||
morph_row_for_schemapg(\%row, $schema);
|
|
||||||
push @{ $schemapg_entries{$table_name} },
|
|
||||||
sprintf "{ %s }",
|
|
||||||
join(', ', grep { defined $_ } @row{@attnames});
|
|
||||||
}
|
|
||||||
|
|
||||||
# Generate entries for system attributes.
|
|
||||||
# We only need postgres.bki entries, not schemapg.h entries.
|
|
||||||
if ($table->{bootstrap})
|
|
||||||
{
|
|
||||||
$attnum = 0;
|
|
||||||
my @SYS_ATTRS = (
|
|
||||||
{ name => 'ctid', type => 'tid' },
|
|
||||||
{ name => 'oid', type => 'oid' },
|
|
||||||
{ name => 'xmin', type => 'xid' },
|
|
||||||
{ name => 'cmin', type => 'cid' },
|
|
||||||
{ name => 'xmax', type => 'xid' },
|
|
||||||
{ name => 'cmax', type => 'cid' },
|
|
||||||
{ name => 'tableoid', type => 'oid' });
|
|
||||||
foreach my $attr (@SYS_ATTRS)
|
|
||||||
{
|
|
||||||
$attnum--;
|
|
||||||
my %row;
|
|
||||||
$row{attnum} = $attnum;
|
|
||||||
$row{attrelid} = $table->{relation_oid};
|
|
||||||
$row{attstattarget} = '0';
|
|
||||||
|
|
||||||
# Omit the oid column if the catalog doesn't have them
|
|
||||||
next
|
|
||||||
if $table->{without_oids}
|
|
||||||
&& $attr->{name} eq 'oid';
|
|
||||||
|
|
||||||
morph_row_for_pgattr(\%row, $schema, $attr, 1);
|
|
||||||
print_bki_insert(\%row, @attnames);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
print $bki "close $catname\n";
|
print $bki "close $catname\n";
|
||||||
}
|
}
|
||||||
@ -375,6 +307,82 @@ exit 0;
|
|||||||
#################### Subroutines ########################
|
#################### Subroutines ########################
|
||||||
|
|
||||||
|
|
||||||
|
# For each catalog marked as needing a schema macro, generate the
|
||||||
|
# per-user-attribute data to be incorporated into schemapg.h. Also, for
|
||||||
|
# bootstrap catalogs, emit pg_attribute entries into the .bki file
|
||||||
|
# for both user and system attributes.
|
||||||
|
sub gen_pg_attribute
|
||||||
|
{
|
||||||
|
my $schema = shift;
|
||||||
|
my @attnames = @_;
|
||||||
|
|
||||||
|
foreach my $table_name (@{ $catalogs->{names} })
|
||||||
|
{
|
||||||
|
my $table = $catalogs->{$table_name};
|
||||||
|
|
||||||
|
# Currently, all bootstrapped relations also need schemapg.h
|
||||||
|
# entries, so skip if the relation isn't to be in schemapg.h.
|
||||||
|
next if !$table->{schema_macro};
|
||||||
|
|
||||||
|
$schemapg_entries{$table_name} = [];
|
||||||
|
push @tables_needing_macros, $table_name;
|
||||||
|
|
||||||
|
# Generate entries for user attributes.
|
||||||
|
my $attnum = 0;
|
||||||
|
my $priornotnull = 1;
|
||||||
|
foreach my $attr (@{ $table->{columns} })
|
||||||
|
{
|
||||||
|
$attnum++;
|
||||||
|
my %row;
|
||||||
|
$row{attnum} = $attnum;
|
||||||
|
$row{attrelid} = $table->{relation_oid};
|
||||||
|
|
||||||
|
morph_row_for_pgattr(\%row, $schema, $attr, $priornotnull);
|
||||||
|
$priornotnull &= ($row{attnotnull} eq 't');
|
||||||
|
|
||||||
|
# If it's bootstrapped, put an entry in postgres.bki.
|
||||||
|
print_bki_insert(\%row, @attnames) if $table->{bootstrap};
|
||||||
|
|
||||||
|
# Store schemapg entries for later.
|
||||||
|
morph_row_for_schemapg(\%row, $schema);
|
||||||
|
push @{ $schemapg_entries{$table_name} },
|
||||||
|
sprintf "{ %s }",
|
||||||
|
join(', ', grep { defined $_ } @row{@attnames});
|
||||||
|
}
|
||||||
|
|
||||||
|
# Generate entries for system attributes.
|
||||||
|
# We only need postgres.bki entries, not schemapg.h entries.
|
||||||
|
if ($table->{bootstrap})
|
||||||
|
{
|
||||||
|
$attnum = 0;
|
||||||
|
my @SYS_ATTRS = (
|
||||||
|
{ name => 'ctid', type => 'tid' },
|
||||||
|
{ name => 'oid', type => 'oid' },
|
||||||
|
{ name => 'xmin', type => 'xid' },
|
||||||
|
{ name => 'cmin', type => 'cid' },
|
||||||
|
{ name => 'xmax', type => 'xid' },
|
||||||
|
{ name => 'cmax', type => 'cid' },
|
||||||
|
{ name => 'tableoid', type => 'oid' });
|
||||||
|
foreach my $attr (@SYS_ATTRS)
|
||||||
|
{
|
||||||
|
$attnum--;
|
||||||
|
my %row;
|
||||||
|
$row{attnum} = $attnum;
|
||||||
|
$row{attrelid} = $table->{relation_oid};
|
||||||
|
$row{attstattarget} = '0';
|
||||||
|
|
||||||
|
# Omit the oid column if the catalog doesn't have them
|
||||||
|
next
|
||||||
|
if $table->{without_oids}
|
||||||
|
&& $attr->{name} eq 'oid';
|
||||||
|
|
||||||
|
morph_row_for_pgattr(\%row, $schema, $attr, 1);
|
||||||
|
print_bki_insert(\%row, @attnames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Given $pgattr_schema (the pg_attribute schema for a catalog sufficient for
|
# Given $pgattr_schema (the pg_attribute schema for a catalog sufficient for
|
||||||
# AddDefaultValues), $attr (the description of a catalog row), and
|
# AddDefaultValues), $attr (the description of a catalog row), and
|
||||||
# $priornotnull (whether all prior attributes in this catalog are not null),
|
# $priornotnull (whether all prior attributes in this catalog are not null),
|
||||||
|
Reference in New Issue
Block a user