Commit 1eb3a09e authored by Tom Lane's avatar Tom Lane

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
parent dc1057fc
...@@ -86,23 +86,16 @@ sub ParseHeader ...@@ -86,23 +86,16 @@ sub ParseHeader
# Push the data into the appropriate data structure. # Push the data into the appropriate data structure.
if (/^DECLARE_TOAST\(\s*(\w+),\s*(\d+),\s*(\d+)\)/) if (/^DECLARE_TOAST\(\s*(\w+),\s*(\d+),\s*(\d+)\)/)
{ {
my ($toast_name, $toast_oid, $index_oid) = ($1, $2, $3);
push @{ $catalog{toasting} }, 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*(.+)\)/) elsif (/^DECLARE_(UNIQUE_)?INDEX\(\s*(\w+),\s*(\d+),\s*(.+)\)/)
{ {
my ($is_unique, $index_name, $index_oid, $using) =
($1, $2, $3, $4);
push @{ $catalog{indexing} }, push @{ $catalog{indexing} },
sprintf( { is_unique => $1 ? 1 : 0,
"declare %sindex %s %s %s\n", index_name => $2,
$is_unique ? 'unique ' : '', index_oid => $3,
$index_name, $index_oid, $using); index_decl => $4 };
}
elsif (/^BUILD_INDICES/)
{
push @{ $catalog{indexing} }, "build indices\n";
} }
elsif (/^CATALOG\((\w+),(\d+),(\w+)\)/) elsif (/^CATALOG\((\w+),(\d+),(\w+)\)/)
{ {
......
...@@ -72,8 +72,7 @@ my $shdescrfile = $output_path . 'postgres.shdescription'; ...@@ -72,8 +72,7 @@ my $shdescrfile = $output_path . 'postgres.shdescription';
open my $shdescr, '>', $shdescrfile . $tmpext open my $shdescr, '>', $shdescrfile . $tmpext
or die "can't open $shdescrfile$tmpext: $!"; or die "can't open $shdescrfile$tmpext: $!";
# Read all the files into internal data structures. Not all catalogs # Read all the files into internal data structures.
# will have a data file.
my @catnames; my @catnames;
my %catalogs; my %catalogs;
my %catalog_data; my %catalog_data;
...@@ -95,18 +94,28 @@ foreach my $header (@input_files) ...@@ -95,18 +94,28 @@ foreach my $header (@input_files)
$catalogs{$catname} = $catalog; $catalogs{$catname} = $catalog;
} }
# Not all catalogs have a data file.
if (-e $datfile) if (-e $datfile)
{ {
$catalog_data{$catname} = Catalog::ParseData($datfile, $schema, 0); $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) ...@@ -467,6 +476,9 @@ foreach my $declaration (@index_decls)
print $bki $declaration; print $bki $declaration;
} }
# last command in the BKI file: build the indexes declared above
print $bki "build indices\n";
# Now generate schemapg.h # Now generate schemapg.h
......
...@@ -47,7 +47,6 @@ extern void CatalogTupleDelete(Relation heapRel, ItemPointer tid); ...@@ -47,7 +47,6 @@ extern void CatalogTupleDelete(Relation heapRel, ItemPointer tid);
*/ */
#define DECLARE_INDEX(name,oid,decl) extern int no_such_variable #define DECLARE_INDEX(name,oid,decl) extern int no_such_variable
#define DECLARE_UNIQUE_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 ...@@ -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)); 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 #define SubscriptionRelSrrelidSrsubidIndexId 6117
/* last step of initialization script: build the indexes declared above */
BUILD_INDICES
#endif /* INDEXING_H */ #endif /* INDEXING_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment