Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1eb3a09

Browse files
committed
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
1 parent dc1057f commit 1eb3a09

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

src/backend/catalog/Catalog.pm

+5-12
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,16 @@ sub ParseHeader
8686
# Push the data into the appropriate data structure.
8787
if (/^DECLARE_TOAST\(\s*(\w+),\s*(\d+),\s*(\d+)\)/)
8888
{
89-
my ($toast_name, $toast_oid, $index_oid) = ($1, $2, $3);
9089
push @{ $catalog{toasting} },
91-
"declare toast $toast_oid $index_oid on $toast_name\n";
90+
{ parent_table => $1, toast_oid => $2, toast_index_oid => $3 };
9291
}
9392
elsif (/^DECLARE_(UNIQUE_)?INDEX\(\s*(\w+),\s*(\d+),\s*(.+)\)/)
9493
{
95-
my ($is_unique, $index_name, $index_oid, $using) =
96-
($1, $2, $3, $4);
9794
push @{ $catalog{indexing} },
98-
sprintf(
99-
"declare %sindex %s %s %s\n",
100-
$is_unique ? 'unique ' : '',
101-
$index_name, $index_oid, $using);
102-
}
103-
elsif (/^BUILD_INDICES/)
104-
{
105-
push @{ $catalog{indexing} }, "build indices\n";
95+
{ is_unique => $1 ? 1 : 0,
96+
index_name => $2,
97+
index_oid => $3,
98+
index_decl => $4 };
10699
}
107100
elsif (/^CATALOG\((\w+),(\d+),(\w+)\)/)
108101
{

src/backend/catalog/genbki.pl

+18-6
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@
7272
open my $shdescr, '>', $shdescrfile . $tmpext
7373
or die "can't open $shdescrfile$tmpext: $!";
7474

75-
# Read all the files into internal data structures. Not all catalogs
76-
# will have a data file.
75+
# Read all the files into internal data structures.
7776
my @catnames;
7877
my %catalogs;
7978
my %catalog_data;
@@ -95,18 +94,28 @@
9594
$catalogs{$catname} = $catalog;
9695
}
9796

97+
# Not all catalogs have a data file.
9898
if (-e $datfile)
9999
{
100100
$catalog_data{$catname} = Catalog::ParseData($datfile, $schema, 0);
101101
}
102102

103-
foreach my $toast_decl (@{ $catalog->{toasting} })
103+
# If the header file contained toast or index info, build BKI
104+
# commands for those, which we'll output later.
105+
foreach my $toast (@{ $catalog->{toasting} })
104106
{
105-
push @toast_decls, $toast_decl;
107+
push @toast_decls,
108+
sprintf "declare toast %s %s on %s\n",
109+
$toast->{toast_oid}, $toast->{toast_index_oid},
110+
$toast->{parent_table};
106111
}
107-
foreach my $index_decl (@{ $catalog->{indexing} })
112+
foreach my $index (@{ $catalog->{indexing} })
108113
{
109-
push @index_decls, $index_decl;
114+
push @index_decls,
115+
sprintf "declare %sindex %s %s %s\n",
116+
$index->{is_unique} ? 'unique ' : '',
117+
$index->{index_name}, $index->{index_oid},
118+
$index->{index_decl};
110119
}
111120
}
112121

@@ -467,6 +476,9 @@
467476
print $bki $declaration;
468477
}
469478

479+
# last command in the BKI file: build the indexes declared above
480+
print $bki "build indices\n";
481+
470482

471483
# Now generate schemapg.h
472484

src/include/catalog/indexing.h

-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ extern void CatalogTupleDelete(Relation heapRel, ItemPointer tid);
4747
*/
4848
#define DECLARE_INDEX(name,oid,decl) extern int no_such_variable
4949
#define DECLARE_UNIQUE_INDEX(name,oid,decl) extern int no_such_variable
50-
#define BUILD_INDICES
5150

5251

5352
/*
@@ -361,7 +360,4 @@ DECLARE_UNIQUE_INDEX(pg_subscription_subname_index, 6115, on pg_subscription usi
361360
DECLARE_UNIQUE_INDEX(pg_subscription_rel_srrelid_srsubid_index, 6117, on pg_subscription_rel using btree(srrelid oid_ops, srsubid oid_ops));
362361
#define SubscriptionRelSrrelidSrsubidIndexId 6117
363362

364-
/* last step of initialization script: build the indexes declared above */
365-
BUILD_INDICES
366-
367363
#endif /* INDEXING_H */

0 commit comments

Comments
 (0)