aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-04-25 15:19:44 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-04-25 16:01:58 -0400
commit1eb3a09e93d28765fcf42c703c4c7322ad2686d7 (patch)
tree988578c206e65fc83ce720969f3818cf4d6fa722 /src/backend
parentdc1057fcd878d5c062c5c4c2b548af2be513b6ab (diff)
downloadpostgresql-1eb3a09e93d28765fcf42c703c4c7322ad2686d7.tar.gz
postgresql-1eb3a09e93d28765fcf42c703c4c7322ad2686d7.zip
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
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/catalog/Catalog.pm17
-rw-r--r--src/backend/catalog/genbki.pl24
2 files changed, 23 insertions, 18 deletions
diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm
index ce425562f51..823e09aa56a 100644
--- a/src/backend/catalog/Catalog.pm
+++ b/src/backend/catalog/Catalog.pm
@@ -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+)\)/)
{
diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl
index 5d4fa5c1544..83b6158a60e 100644
--- a/src/backend/catalog/genbki.pl
+++ b/src/backend/catalog/genbki.pl
@@ -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