|
56 | 56 | my %catalog_data;
|
57 | 57 | my @toast_decls;
|
58 | 58 | my @index_decls;
|
| 59 | +my %syscaches; |
| 60 | +my %syscache_catalogs; |
59 | 61 | my %oidcounts;
|
60 | 62 | my @system_constraints;
|
61 | 63 |
|
|
121 | 123 | }
|
122 | 124 | }
|
123 | 125 |
|
| 126 | + # Lookup table to get index info by index name |
| 127 | + my %indexes; |
| 128 | + |
124 | 129 | # If the header file contained toast or index info, build BKI
|
125 | 130 | # commands for those, which we'll output later.
|
126 | 131 | foreach my $toast (@{ $catalog->{toasting} })
|
|
134 | 139 | }
|
135 | 140 | foreach my $index (@{ $catalog->{indexing} })
|
136 | 141 | {
|
| 142 | + $indexes{ $index->{index_name} } = $index; |
| 143 | + |
137 | 144 | push @index_decls,
|
138 | 145 | sprintf "declare %sindex %s %s on %s using %s\n",
|
139 | 146 | $index->{is_unique} ? 'unique ' : '',
|
|
151 | 158 | $index->{index_name};
|
152 | 159 | }
|
153 | 160 | }
|
| 161 | + |
| 162 | + # Analyze syscache info |
| 163 | + foreach my $syscache (@{ $catalog->{syscaches} }) |
| 164 | + { |
| 165 | + my $index = $indexes{ $syscache->{index_name} }; |
| 166 | + my $tblname = $index->{table_name}; |
| 167 | + my $key = $index->{index_decl}; |
| 168 | + $key =~ s/^\w+\(//; |
| 169 | + $key =~ s/\)$//; |
| 170 | + $key =~ s/(\w+)\s+\w+/Anum_${tblname}_$1/g; |
| 171 | + |
| 172 | + $syscaches{ $syscache->{syscache_name} } = { |
| 173 | + table_oid_macro => $catalogs{$tblname}->{relation_oid_macro}, |
| 174 | + index_oid_macro => $index->{index_oid_macro}, |
| 175 | + key => $key, |
| 176 | + nbuckets => $syscache->{syscache_nbuckets}, |
| 177 | + }; |
| 178 | + |
| 179 | + $syscache_catalogs{$catname} = 1; |
| 180 | + } |
154 | 181 | }
|
155 | 182 |
|
156 | 183 | # Complain and exit if we found any duplicate OIDs.
|
|
419 | 446 | my $constraints_file = $output_path . 'system_constraints.sql';
|
420 | 447 | open my $constraints, '>', $constraints_file . $tmpext
|
421 | 448 | or die "can't open $constraints_file$tmpext: $!";
|
| 449 | +my $syscache_ids_file = $output_path . 'syscache_ids.h'; |
| 450 | +open my $syscache_ids_fh, '>', $syscache_ids_file . $tmpext |
| 451 | + or die "can't open $syscache_ids_file$tmpext: $!"; |
| 452 | +my $syscache_info_file = $output_path . 'syscache_info.h'; |
| 453 | +open my $syscache_info_fh, '>', $syscache_info_file . $tmpext |
| 454 | + or die "can't open $syscache_info_file$tmpext: $!"; |
422 | 455 |
|
423 | 456 | # Generate postgres.bki and pg_*_d.h headers.
|
424 | 457 |
|
|
753 | 786 | # Closing boilerplate for system_fk_info.h
|
754 | 787 | print $fk_info "};\n\n#endif\t\t\t\t\t\t\t/* SYSTEM_FK_INFO_H */\n";
|
755 | 788 |
|
| 789 | +# Now generate syscache info |
| 790 | + |
| 791 | +print_boilerplate($syscache_ids_fh, "syscache_ids.h", "SysCache identifiers"); |
| 792 | +print $syscache_ids_fh "enum SysCacheIdentifier |
| 793 | +{ |
| 794 | +"; |
| 795 | + |
| 796 | +print_boilerplate($syscache_info_fh, "syscache_info.h", |
| 797 | + "SysCache definitions"); |
| 798 | +print $syscache_info_fh "\n"; |
| 799 | +foreach my $catname (sort keys %syscache_catalogs) |
| 800 | +{ |
| 801 | + print $syscache_info_fh qq{#include "catalog/${catname}_d.h"\n}; |
| 802 | +} |
| 803 | +print $syscache_info_fh "\n"; |
| 804 | +print $syscache_info_fh "static const struct cachedesc cacheinfo[] = {\n"; |
| 805 | + |
| 806 | +my $last_syscache; |
| 807 | +foreach my $syscache (sort keys %syscaches) |
| 808 | +{ |
| 809 | + print $syscache_ids_fh "\t$syscache,\n"; |
| 810 | + $last_syscache = $syscache; |
| 811 | + |
| 812 | + print $syscache_info_fh "\t[$syscache] = {\n"; |
| 813 | + print $syscache_info_fh "\t\t", $syscaches{$syscache}{table_oid_macro}, |
| 814 | + ",\n"; |
| 815 | + print $syscache_info_fh "\t\t", $syscaches{$syscache}{index_oid_macro}, |
| 816 | + ",\n"; |
| 817 | + print $syscache_info_fh "\t\tKEY(", $syscaches{$syscache}{key}, "),\n"; |
| 818 | + print $syscache_info_fh "\t\t", $syscaches{$syscache}{nbuckets}, "\n"; |
| 819 | + print $syscache_info_fh "\t},\n"; |
| 820 | +} |
| 821 | + |
| 822 | +print $syscache_ids_fh "};\n"; |
| 823 | +print $syscache_ids_fh "#define SysCacheSize ($last_syscache + 1)\n"; |
| 824 | + |
| 825 | +print $syscache_info_fh "};\n"; |
| 826 | + |
756 | 827 | # We're done emitting data
|
757 | 828 | close $bki;
|
758 | 829 | close $schemapg;
|
759 | 830 | close $fk_info;
|
760 | 831 | close $constraints;
|
| 832 | +close $syscache_ids_fh; |
| 833 | +close $syscache_info_fh; |
761 | 834 |
|
762 | 835 | # Finally, rename the completed files into place.
|
763 | 836 | Catalog::RenameTempFile($bkifile, $tmpext);
|
764 | 837 | Catalog::RenameTempFile($schemafile, $tmpext);
|
765 | 838 | Catalog::RenameTempFile($fk_info_file, $tmpext);
|
766 | 839 | Catalog::RenameTempFile($constraints_file, $tmpext);
|
| 840 | +Catalog::RenameTempFile($syscache_ids_file, $tmpext); |
| 841 | +Catalog::RenameTempFile($syscache_info_file, $tmpext); |
767 | 842 |
|
768 | 843 | exit($num_errors != 0 ? 1 : 0);
|
769 | 844 |
|
|
0 commit comments