Skip to content

Commit 9b1a6f5

Browse files
committed
Generate syscache info from catalog files
Add a new genbki macros MAKE_SYSCACHE that specifies the syscache ID macro, the underlying index, and the number of buckets. From that, we can generate the existing tables in syscache.h and syscache.c via genbki.pl. Reviewed-by: John Naylor <johncnaylorls@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/75ae5875-3abc-dafc-8aec-73247ed41cde@eisentraut.org
1 parent 46d8587 commit 9b1a6f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+267
-717
lines changed

src/backend/catalog/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/postgres.bki
22
/schemapg.h
3+
/syscache_ids.h
4+
/syscache_info.h
35
/system_fk_info.h
46
/system_constraints.sql
57
/pg_*_d.h

src/backend/catalog/Catalog.pm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ sub ParseHeader
129129
%+,
130130
};
131131
}
132+
elsif (
133+
/^MAKE_SYSCACHE\(\s*
134+
(?<syscache_name>\w+),\s*
135+
(?<index_name>\w+),\s*
136+
(?<syscache_nbuckets>\w+)\s*
137+
\)/x
138+
)
139+
{
140+
push @{ $catalog{syscaches} }, {%+};
141+
}
132142
elsif (
133143
/^DECLARE_OID_DEFINING_MACRO\(\s*
134144
(?<other_name>\w+),\s*

src/backend/catalog/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ CATALOG_HEADERS := \
120120
pg_subscription.h \
121121
pg_subscription_rel.h
122122

123-
GENERATED_HEADERS := $(CATALOG_HEADERS:%.h=%_d.h) schemapg.h system_fk_info.h
123+
GENERATED_HEADERS := $(CATALOG_HEADERS:%.h=%_d.h) schemapg.h syscache_ids.h syscache_info.h system_fk_info.h
124124

125125
POSTGRES_BKI_SRCS := $(addprefix $(top_srcdir)/src/include/catalog/, $(CATALOG_HEADERS))
126126

src/backend/catalog/genbki.pl

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
my %catalog_data;
5757
my @toast_decls;
5858
my @index_decls;
59+
my %syscaches;
60+
my %syscache_catalogs;
5961
my %oidcounts;
6062
my @system_constraints;
6163

@@ -121,6 +123,9 @@
121123
}
122124
}
123125

126+
# Lookup table to get index info by index name
127+
my %indexes;
128+
124129
# If the header file contained toast or index info, build BKI
125130
# commands for those, which we'll output later.
126131
foreach my $toast (@{ $catalog->{toasting} })
@@ -134,6 +139,8 @@
134139
}
135140
foreach my $index (@{ $catalog->{indexing} })
136141
{
142+
$indexes{ $index->{index_name} } = $index;
143+
137144
push @index_decls,
138145
sprintf "declare %sindex %s %s on %s using %s\n",
139146
$index->{is_unique} ? 'unique ' : '',
@@ -151,6 +158,26 @@
151158
$index->{index_name};
152159
}
153160
}
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+
}
154181
}
155182

156183
# Complain and exit if we found any duplicate OIDs.
@@ -419,6 +446,12 @@
419446
my $constraints_file = $output_path . 'system_constraints.sql';
420447
open my $constraints, '>', $constraints_file . $tmpext
421448
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: $!";
422455
423456
# Generate postgres.bki and pg_*_d.h headers.
424457
@@ -753,17 +786,59 @@
753786
# Closing boilerplate for system_fk_info.h
754787
print $fk_info "};\n\n#endif\t\t\t\t\t\t\t/* SYSTEM_FK_INFO_H */\n";
755788

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+
756827
# We're done emitting data
757828
close $bki;
758829
close $schemapg;
759830
close $fk_info;
760831
close $constraints;
832+
close $syscache_ids_fh;
833+
close $syscache_info_fh;
761834

762835
# Finally, rename the completed files into place.
763836
Catalog::RenameTempFile($bkifile, $tmpext);
764837
Catalog::RenameTempFile($schemafile, $tmpext);
765838
Catalog::RenameTempFile($fk_info_file, $tmpext);
766839
Catalog::RenameTempFile($constraints_file, $tmpext);
840+
Catalog::RenameTempFile($syscache_ids_file, $tmpext);
841+
Catalog::RenameTempFile($syscache_info_file, $tmpext);
767842

768843
exit($num_errors != 0 ? 1 : 0);
769844

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy