Make Catalog.pm's representation of toast and index decls more abstract.

Instead of immediately constructing the string we need to emit into the
.BKI file, preserve the items we extracted from the header file in a hash.
This eases using the info for other purposes.

John Naylor (with cosmetic adjustments by me)

Discussion: https://postgr.es/m/37D774E4-FE1F-437E-B3D2-593F314B7505@postgrespro.ru
This commit is contained in:
Tom Lane 2018-04-25 15:19:44 -04:00
parent dc1057fcd8
commit 1eb3a09e93
3 changed files with 23 additions and 22 deletions

View File

@ -86,23 +86,16 @@ sub ParseHeader
# Push the data into the appropriate data structure.
if (/^DECLARE_TOAST\(\s*(\w+),\s*(\d+),\s*(\d+)\)/)
{
my ($toast_name, $toast_oid, $index_oid) = ($1, $2, $3);
push @{ $catalog{toasting} },
"declare toast $toast_oid $index_oid on $toast_name\n";
{ parent_table => $1, toast_oid => $2, toast_index_oid => $3 };
}
elsif (/^DECLARE_(UNIQUE_)?INDEX\(\s*(\w+),\s*(\d+),\s*(.+)\)/)
{
my ($is_unique, $index_name, $index_oid, $using) =
($1, $2, $3, $4);
push @{ $catalog{indexing} },
sprintf(
"declare %sindex %s %s %s\n",
$is_unique ? 'unique ' : '',
$index_name, $index_oid, $using);
}
elsif (/^BUILD_INDICES/)
{
push @{ $catalog{indexing} }, "build indices\n";
{ is_unique => $1 ? 1 : 0,
index_name => $2,
index_oid => $3,
index_decl => $4 };
}
elsif (/^CATALOG\((\w+),(\d+),(\w+)\)/)
{

View File

@ -72,8 +72,7 @@ my $shdescrfile = $output_path . 'postgres.shdescription';
open my $shdescr, '>', $shdescrfile . $tmpext
or die "can't open $shdescrfile$tmpext: $!";
# Read all the files into internal data structures. Not all catalogs
# will have a data file.
# Read all the files into internal data structures.
my @catnames;
my %catalogs;
my %catalog_data;
@ -95,18 +94,28 @@ foreach my $header (@input_files)
$catalogs{$catname} = $catalog;
}
# Not all catalogs have a data file.
if (-e $datfile)
{
$catalog_data{$catname} = Catalog::ParseData($datfile, $schema, 0);
}
foreach my $toast_decl (@{ $catalog->{toasting} })
# If the header file contained toast or index info, build BKI
# commands for those, which we'll output later.
foreach my $toast (@{ $catalog->{toasting} })
{
push @toast_decls, $toast_decl;
push @toast_decls,
sprintf "declare toast %s %s on %s\n",
$toast->{toast_oid}, $toast->{toast_index_oid},
$toast->{parent_table};
}
foreach my $index_decl (@{ $catalog->{indexing} })
foreach my $index (@{ $catalog->{indexing} })
{
push @index_decls, $index_decl;
push @index_decls,
sprintf "declare %sindex %s %s %s\n",
$index->{is_unique} ? 'unique ' : '',
$index->{index_name}, $index->{index_oid},
$index->{index_decl};
}
}
@ -467,6 +476,9 @@ foreach my $declaration (@index_decls)
print $bki $declaration;
}
# last command in the BKI file: build the indexes declared above
print $bki "build indices\n";
# Now generate schemapg.h

View File

@ -47,7 +47,6 @@ extern void CatalogTupleDelete(Relation heapRel, ItemPointer tid);
*/
#define DECLARE_INDEX(name,oid,decl) extern int no_such_variable
#define DECLARE_UNIQUE_INDEX(name,oid,decl) extern int no_such_variable
#define BUILD_INDICES
/*
@ -361,7 +360,4 @@ DECLARE_UNIQUE_INDEX(pg_subscription_subname_index, 6115, on pg_subscription usi
DECLARE_UNIQUE_INDEX(pg_subscription_rel_srrelid_srsubid_index, 6117, on pg_subscription_rel using btree(srrelid oid_ops, srsubid oid_ops));
#define SubscriptionRelSrrelidSrsubidIndexId 6117
/* last step of initialization script: build the indexes declared above */
BUILD_INDICES
#endif /* INDEXING_H */