I wrote: > I'll submit a > preliminary patch soon to get some of those items out of the way.
I've attached a patch that takes care of these cleanups so they don't clutter the patch set. -John Naylor
From d97a8b2e5fa4977e656d1aca7ee7bf1289ecbd40 Mon Sep 17 00:00:00 2001 From: John Naylor <jcnay...@gmail.com> Date: Sat, 3 Mar 2018 16:56:10 +0700 Subject: [PATCH] Some non-functional cleanups in preparation for the upcoming bootstrap data conversion: Arrange pg_tablespace.h OID symbols so they are immediately after the relevant DATA() line. Separate out the pg_attribute logic of genbki.pl into its own function and skip checking if the data is defined. This both narrows and shortens the data writing loop of the script. Correct spelling of some macros. --- src/backend/catalog/aclchk.c | 6 +- src/backend/catalog/genbki.pl | 272 ++++++++++++++++++---------------- src/include/catalog/pg_init_privs.h | 2 +- src/include/catalog/pg_tablespace.h | 3 +- src/interfaces/ecpg/ecpglib/execute.c | 2 +- src/interfaces/ecpg/ecpglib/pg_type.h | 2 +- 6 files changed, 149 insertions(+), 138 deletions(-) diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c index 3f2c629..0648539 100644 --- a/src/backend/catalog/aclchk.c +++ b/src/backend/catalog/aclchk.c @@ -5969,8 +5969,8 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a MemSet(nulls, false, sizeof(nulls)); MemSet(replace, false, sizeof(replace)); - values[Anum_pg_init_privs_privs - 1] = PointerGetDatum(new_acl); - replace[Anum_pg_init_privs_privs - 1] = true; + values[Anum_pg_init_privs_initprivs - 1] = PointerGetDatum(new_acl); + replace[Anum_pg_init_privs_initprivs - 1] = true; oldtuple = heap_modify_tuple(oldtuple, RelationGetDescr(relation), values, nulls, replace); @@ -6007,7 +6007,7 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a values[Anum_pg_init_privs_privtype - 1] = CharGetDatum(INITPRIVS_EXTENSION); - values[Anum_pg_init_privs_privs - 1] = PointerGetDatum(new_acl); + values[Anum_pg_init_privs_initprivs - 1] = PointerGetDatum(new_acl); tuple = heap_form_tuple(RelationGetDescr(relation), values, nulls); diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl index ed90a02..8d740c3 100644 --- a/src/backend/catalog/genbki.pl +++ b/src/backend/catalog/genbki.pl @@ -156,154 +156,85 @@ foreach my $catname (@{ $catalogs->{names} }) 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); + } - # Ordinary catalog with DATA line(s) - foreach my $row (@{ $catalog->{data} }) - { - - # Split line into tokens without interpreting their meaning. - my %bki_values; - @bki_values{@attnames} = - Catalog::SplitDataLine($row->{bki_values}); - - # Perform required substitutions on fields - foreach my $column (@$schema) - { - my $attname = $column->{name}; - my $atttype = $column->{type}; - - # Substitute constant values we acquired above. - # (It's intentional that this can apply to parts of a field). - $bki_values{$attname} =~ s/\bPGUID\b/$BOOTSTRAP_SUPERUSERID/g; - $bki_values{$attname} =~ s/\bPGNSP\b/$PG_CATALOG_NAMESPACE/g; - - # Replace regproc columns' values with OIDs. - # If we don't have a unique value to substitute, - # just do nothing (regprocin will complain). - if ($atttype eq 'regproc') - { - my $procoid = $regprocoids{ $bki_values{$attname} }; - $bki_values{$attname} = $procoid - if defined($procoid) && $procoid ne 'MULTIPLE'; - } - } + # Ordinary catalog with DATA line(s) + foreach my $row (@{ $catalog->{data} }) + { - # Save pg_proc oids for use in later regproc substitutions. - # This relies on the order we process the files in! - if ($catname eq 'pg_proc') - { - if (defined($regprocoids{ $bki_values{proname} })) - { - $regprocoids{ $bki_values{proname} } = 'MULTIPLE'; - } - else - { - $regprocoids{ $bki_values{proname} } = $row->{oid}; - } - } + # Split line into tokens without interpreting their meaning. + my %bki_values; + @bki_values{@attnames} = + Catalog::SplitDataLine($row->{bki_values}); - # Save pg_type info for pg_attribute processing below - if ($catname eq 'pg_type') + # Perform required substitutions on fields + foreach my $column (@$schema) + { + my $attname = $column->{name}; + my $atttype = $column->{type}; + + # Substitute constant values we acquired above. + # (It's intentional that this can apply to parts of a field). + $bki_values{$attname} =~ s/\bPGUID\b/$BOOTSTRAP_SUPERUSERID/g; + $bki_values{$attname} =~ s/\bPGNSP\b/$PG_CATALOG_NAMESPACE/g; + + # Replace regproc columns' values with OIDs. + # If we don't have a unique value to substitute, + # just do nothing (regprocin will complain). + if ($atttype eq 'regproc') { - my %type = %bki_values; - $type{oid} = $row->{oid}; - $types{ $type{typname} } = \%type; + my $procoid = $regprocoids{ $bki_values{$attname} }; + $bki_values{$attname} = $procoid + if defined($procoid) && $procoid ne 'MULTIPLE'; } + } - # Write to postgres.bki - my $oid = $row->{oid} ? "OID = $row->{oid} " : ''; - printf $bki "insert %s( %s )\n", $oid, - join(' ', @bki_values{@attnames}); - - # Write comments to postgres.description and - # postgres.shdescription - if (defined $row->{descr}) + # Save pg_proc oids for use in later regproc substitutions. + # This relies on the order we process the files in! + if ($catname eq 'pg_proc') + { + if (defined($regprocoids{ $bki_values{proname} })) { - printf $descr "%s\t%s\t0\t%s\n", - $row->{oid}, $catname, $row->{descr}; + $regprocoids{ $bki_values{proname} } = 'MULTIPLE'; } - if (defined $row->{shdescr}) + else { - printf $shdescr "%s\t%s\t%s\n", - $row->{oid}, $catname, $row->{shdescr}; + $regprocoids{ $bki_values{proname} } = $row->{oid}; } } - } - 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} }) + # Save pg_type info for pg_attribute processing below + if ($catname eq 'pg_type') { - 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'); + my %type = %bki_values; + $type{oid} = $row->{oid}; + $types{ $type{typname} } = \%type; + } - # If it's bootstrapped, put an entry in postgres.bki. - print_bki_insert(\%row, @attnames) if $table->{bootstrap}; + # Write to postgres.bki + my $oid = $row->{oid} ? "OID = $row->{oid} " : ''; + printf $bki "insert %s( %s )\n", $oid, + join(' ', @bki_values{@attnames}); - # 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); - } - } + # Write comments to postgres.description and + # postgres.shdescription + if (defined $row->{descr}) + { + printf $descr "%s\t%s\t0\t%s\n", + $row->{oid}, $catname, $row->{descr}; + } + if (defined $row->{shdescr}) + { + printf $shdescr "%s\t%s\t%s\n", + $row->{oid}, $catname, $row->{shdescr}; } } - print $bki "close $catname\n"; } @@ -375,6 +306,87 @@ exit 0; #################### Subroutines ######################## +# Iterate over all the catalogs. Where specified in the given header, build +# a hard-coded tuple descriptor for utils/relcache.c. Some of these are +# also bootstrap tables, which require pg_attribute entries in .bki for +# both user and system attributes. +sub gen_pg_attribute +{ + my $schema = shift; + + my @attnames; + foreach my $column (@$schema) + { + push @attnames, $column->{name}; + } + + 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 # AddDefaultValues), $attr (the description of a catalog row), and # $priornotnull (whether all prior attributes in this catalog are not null), diff --git a/src/include/catalog/pg_init_privs.h b/src/include/catalog/pg_init_privs.h index 6ea005f..65f02c2 100644 --- a/src/include/catalog/pg_init_privs.h +++ b/src/include/catalog/pg_init_privs.h @@ -69,7 +69,7 @@ typedef FormData_pg_init_privs * Form_pg_init_privs; #define Anum_pg_init_privs_classoid 2 #define Anum_pg_init_privs_objsubid 3 #define Anum_pg_init_privs_privtype 4 -#define Anum_pg_init_privs_privs 5 +#define Anum_pg_init_privs_initprivs 5 /* * It is important to know if the initial privileges are from initdb or from an diff --git a/src/include/catalog/pg_tablespace.h b/src/include/catalog/pg_tablespace.h index 3967056..360fc4c 100644 --- a/src/include/catalog/pg_tablespace.h +++ b/src/include/catalog/pg_tablespace.h @@ -58,9 +58,8 @@ typedef FormData_pg_tablespace *Form_pg_tablespace; #define Anum_pg_tablespace_spcoptions 4 DATA(insert OID = 1663 ( pg_default PGUID _null_ _null_ )); -DATA(insert OID = 1664 ( pg_global PGUID _null_ _null_ )); - #define DEFAULTTABLESPACE_OID 1663 +DATA(insert OID = 1664 ( pg_global PGUID _null_ _null_ )); #define GLOBALTABLESPACE_OID 1664 #endif /* PG_TABLESPACE_H */ diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 7d6d7d0..0404385 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -255,7 +255,7 @@ ecpg_is_type_an_array(int type, const struct statement *stmt, const struct varia return ECPG_ARRAY_ERROR; if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TIMETZOID, ECPG_ARRAY_NONE, stmt->lineno)) return ECPG_ARRAY_ERROR; - if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), ZPBITOID, ECPG_ARRAY_NONE, stmt->lineno)) + if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), BITOID, ECPG_ARRAY_NONE, stmt->lineno)) return ECPG_ARRAY_ERROR; if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), VARBITOID, ECPG_ARRAY_NONE, stmt->lineno)) return ECPG_ARRAY_ERROR; diff --git a/src/interfaces/ecpg/ecpglib/pg_type.h b/src/interfaces/ecpg/ecpglib/pg_type.h index 5d9eeca..f75c887 100644 --- a/src/interfaces/ecpg/ecpglib/pg_type.h +++ b/src/interfaces/ecpg/ecpglib/pg_type.h @@ -54,7 +54,7 @@ #define TIMESTAMPTZOID 1184 #define INTERVALOID 1186 #define TIMETZOID 1266 -#define ZPBITOID 1560 +#define BITOID 1560 #define VARBITOID 1562 #define NUMERICOID 1700 #define REFCURSOROID 1790 -- 2.7.4