Commit 8ff5f824 authored by Tom Lane's avatar Tom Lane

Reduce the size of the fmgr_builtin_oid_index[] array.

This index array was originally defined to have 10000 entries (ranging
up to FirstGenbkiObjectId), but we really only need entries up to the
last existing builtin function OID, currently 6121.  That saves close
to 8K of never-accessed space in the server executable, at the small
price of one more fetch in fmgr_isbuiltin().

We could reduce the array size still further by renumbering a few of
the highest-numbered builtin functions; but there's a small risk of
breaking clients that have chosen to hardwire those function OIDs,
so it's not clear if it'd be worth the trouble.  (We should, however,
discourage future patches from choosing function OIDs above 6K as long
as there's still lots of space below that.)

Discussion: https://postgr.es/m/12359.1547063064@sss.pgh.pa.us
parent 59029b6f
...@@ -80,11 +80,6 @@ foreach my $datfile (@input_files) ...@@ -80,11 +80,6 @@ foreach my $datfile (@input_files)
$catalog_data{$catname} = Catalog::ParseData($datfile, $schema, 0); $catalog_data{$catname} = Catalog::ParseData($datfile, $schema, 0);
} }
# Fetch some values for later.
my $FirstGenbkiObjectId =
Catalog::FindDefinedSymbol('access/transam.h', $include_path,
'FirstGenbkiObjectId');
# Collect certain fields from pg_proc.dat. # Collect certain fields from pg_proc.dat.
my @fmgr = (); my @fmgr = ();
...@@ -225,6 +220,7 @@ my %bmap; ...@@ -225,6 +220,7 @@ my %bmap;
$bmap{'t'} = 'true'; $bmap{'t'} = 'true';
$bmap{'f'} = 'false'; $bmap{'f'} = 'false';
my @fmgr_builtin_oid_index; my @fmgr_builtin_oid_index;
my $last_builtin_oid = 0;
my $fmgr_count = 0; my $fmgr_count = 0;
foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr) foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
{ {
...@@ -232,6 +228,7 @@ foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr) ...@@ -232,6 +228,7 @@ foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
" { $s->{oid}, $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, \"$s->{prosrc}\", $s->{prosrc} }"; " { $s->{oid}, $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, \"$s->{prosrc}\", $s->{prosrc} }";
$fmgr_builtin_oid_index[ $s->{oid} ] = $fmgr_count++; $fmgr_builtin_oid_index[ $s->{oid} ] = $fmgr_count++;
$last_builtin_oid = $s->{oid};
if ($fmgr_count <= $#fmgr) if ($fmgr_count <= $#fmgr)
{ {
...@@ -244,31 +241,30 @@ foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr) ...@@ -244,31 +241,30 @@ foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
} }
print $tfh "};\n"; print $tfh "};\n";
print $tfh qq| printf $tfh qq|
const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)); const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin));
|;
const Oid fmgr_last_builtin_oid = %u;
|, $last_builtin_oid;
# Create fmgr_builtins_oid_index table. # Create fmgr_builtins_oid_index table.
# printf $tfh qq|
# Note that the array has to be filled up to FirstGenbkiObjectId, const uint16 fmgr_builtin_oid_index[%u] = {
# as we can't rely on zero initialization as 0 is a valid mapping. |, $last_builtin_oid + 1;
print $tfh qq|
const uint16 fmgr_builtin_oid_index[FirstGenbkiObjectId] = {
|;
for (my $i = 0; $i < $FirstGenbkiObjectId; $i++) for (my $i = 0; $i <= $last_builtin_oid; $i++)
{ {
my $oid = $fmgr_builtin_oid_index[$i]; my $oid = $fmgr_builtin_oid_index[$i];
# fmgr_builtin_oid_index is sparse, map nonexistant functions to # fmgr_builtin_oid_index is sparse, map nonexistent functions to
# InvalidOidBuiltinMapping # InvalidOidBuiltinMapping
if (not defined $oid) if (not defined $oid)
{ {
$oid = 'InvalidOidBuiltinMapping'; $oid = 'InvalidOidBuiltinMapping';
} }
if ($i + 1 == $FirstGenbkiObjectId) if ($i == $last_builtin_oid)
{ {
print $tfh " $oid\n"; print $tfh " $oid\n";
} }
......
...@@ -75,12 +75,12 @@ fmgr_isbuiltin(Oid id) ...@@ -75,12 +75,12 @@ fmgr_isbuiltin(Oid id)
uint16 index; uint16 index;
/* fast lookup only possible if original oid still assigned */ /* fast lookup only possible if original oid still assigned */
if (id >= FirstGenbkiObjectId) if (id > fmgr_last_builtin_oid)
return NULL; return NULL;
/* /*
* Lookup function data. If there's a miss in that range it's likely a * Lookup function data. If there's a miss in that range it's likely a
* nonexistant function, returning NULL here will trigger an ERROR later. * nonexistent function, returning NULL here will trigger an ERROR later.
*/ */
index = fmgr_builtin_oid_index[id]; index = fmgr_builtin_oid_index[id];
if (index == InvalidOidBuiltinMapping) if (index == InvalidOidBuiltinMapping)
......
...@@ -36,11 +36,13 @@ extern const FmgrBuiltin fmgr_builtins[]; ...@@ -36,11 +36,13 @@ extern const FmgrBuiltin fmgr_builtins[];
extern const int fmgr_nbuiltins; /* number of entries in table */ extern const int fmgr_nbuiltins; /* number of entries in table */
extern const Oid fmgr_last_builtin_oid; /* highest function OID in table */
/* /*
* Mapping from a builtin function's oid to the index in the fmgr_builtins * Mapping from a builtin function's OID to its index in the fmgr_builtins
* array. * array. This is indexed from 0 through fmgr_last_builtin_oid.
*/ */
#define InvalidOidBuiltinMapping PG_UINT16_MAX #define InvalidOidBuiltinMapping PG_UINT16_MAX
extern const uint16 fmgr_builtin_oid_index[FirstGenbkiObjectId]; extern const uint16 fmgr_builtin_oid_index[];
#endif /* FMGRTAB_H */ #endif /* FMGRTAB_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment