Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Make Catalog.pm's representation of toast and index decls more abstract.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 25 Apr 2018 19:19:44 +0000 (15:19 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 25 Apr 2018 20:01:58 +0000 (16:01 -0400)
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

src/backend/catalog/Catalog.pm
src/backend/catalog/genbki.pl
src/include/catalog/indexing.h

index ce425562f51557b190a4d76f300bd0295bde7503..823e09aa56a3a8a0e9f7bf111a6661b5f41f1813 100644 (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+)\)/)
        {
index 5d4fa5c154420d7616678cd69d7b3b0ebaae5284..83b6158a60eb8dbdb448782341ee8b659ae04719 100644 (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
 
index 42499e235f2d1bd1edc30e930eef51ffa25f7ebe..24915824caac4e9060003b0a9610ed8228320e25 100644 (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 */