Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8ff5f82

Browse files
committed
Reduce the size of the fmgr_builtin_oid_index[] array.
This index array was originally defined to have 10000 entries (rangingup to FirstGenbkiObjectId), but we really only need entries up to thelast existing builtin function OID, currently 6121. That saves closeto 8K of never-accessed space in the server executable, at the smallprice of one more fetch in fmgr_isbuiltin().We could reduce the array size still further by renumbering a few ofthe highest-numbered builtin functions; but there's a small risk ofbreaking 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 longas there's still lots of space below that.)Discussion:https://postgr.es/m/12359.1547063064@sss.pgh.pa.us
1 parent59029b6 commit8ff5f82

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

‎src/backend/utils/Gen_fmgrtab.pl

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@
8080
$catalog_data{$catname} = Catalog::ParseData($datfile,$schema, 0);
8181
}
8282

83-
# Fetch some values for later.
84-
my$FirstGenbkiObjectId =
85-
Catalog::FindDefinedSymbol('access/transam.h',$include_path,
86-
'FirstGenbkiObjectId');
87-
8883
# Collect certain fields from pg_proc.dat.
8984
my@fmgr = ();
9085

@@ -225,13 +220,15 @@
225220
$bmap{'t'} ='true';
226221
$bmap{'f'} ='false';
227222
my@fmgr_builtin_oid_index;
223+
my$last_builtin_oid = 0;
228224
my$fmgr_count = 0;
229225
foreachmy$s (sort {$a->{oid}<=>$b->{oid} }@fmgr)
230226
{
231227
print$tfh
232228
" {$s->{oid},$s->{nargs},$bmap{$s->{strict}},$bmap{$s->{retset}},\"$s->{prosrc}\",$s->{prosrc} }";
233229

234230
$fmgr_builtin_oid_index[$s->{oid} ] =$fmgr_count++;
231+
$last_builtin_oid =$s->{oid};
235232

236233
if ($fmgr_count <=$#fmgr)
237234
{
@@ -244,31 +241,30 @@
244241
}
245242
print$tfh"};\n";
246243

247-
print$tfhqq|
244+
printf$tfhqq|
248245
const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin));
249-
|;
246+
247+
const Oid fmgr_last_builtin_oid =%u;
248+
|,$last_builtin_oid;
250249

251250

252251
# Create fmgr_builtins_oid_index table.
253-
#
254-
# Note that the array has to be filled up to FirstGenbkiObjectId,
255-
# as we can't rely on zero initialization as 0 is a valid mapping.
256-
print$tfhqq|
257-
const uint16 fmgr_builtin_oid_index[FirstGenbkiObjectId] = {
258-
|;
252+
printf$tfhqq|
253+
const uint16 fmgr_builtin_oid_index[%u] = {
254+
|,$last_builtin_oid + 1;
259255

260-
for (my$i = 0;$i <$FirstGenbkiObjectId;$i++)
256+
for (my$i = 0;$i <=$last_builtin_oid;$i++)
261257
{
262258
my$oid =$fmgr_builtin_oid_index[$i];
263259

264-
# fmgr_builtin_oid_index is sparse, mapnonexistant functions to
260+
# fmgr_builtin_oid_index is sparse, mapnonexistent functions to
265261
# InvalidOidBuiltinMapping
266262
if (notdefined$oid)
267263
{
268264
$oid ='InvalidOidBuiltinMapping';
269265
}
270266

271-
if ($i+ 1==$FirstGenbkiObjectId)
267+
if ($i ==$last_builtin_oid)
272268
{
273269
print$tfh"$oid\n";
274270
}

‎src/backend/utils/fmgr/fmgr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ fmgr_isbuiltin(Oid id)
7575
uint16index;
7676

7777
/* fast lookup only possible if original oid still assigned */
78-
if (id >=FirstGenbkiObjectId)
78+
if (id>fmgr_last_builtin_oid)
7979
returnNULL;
8080

8181
/*
8282
* Lookup function data. If there's a miss in that range it's likely a
83-
*nonexistant function, returning NULL here will trigger an ERROR later.
83+
*nonexistent function, returning NULL here will trigger an ERROR later.
8484
*/
8585
index=fmgr_builtin_oid_index[id];
8686
if (index==InvalidOidBuiltinMapping)

‎src/include/utils/fmgrtab.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ extern const FmgrBuiltin fmgr_builtins[];
3636

3737
externconstintfmgr_nbuiltins;/* number of entries in table */
3838

39+
externconstOidfmgr_last_builtin_oid;/* highest function OID in table */
40+
3941
/*
40-
* Mapping from a builtin function'soid tothe index in the fmgr_builtins
41-
* array.
42+
* Mapping from a builtin function'sOID toits index in the fmgr_builtins
43+
* array. This is indexed from 0 through fmgr_last_builtin_oid.
4244
*/
4345
#defineInvalidOidBuiltinMapping PG_UINT16_MAX
44-
externconstuint16fmgr_builtin_oid_index[FirstGenbkiObjectId];
46+
externconstuint16fmgr_builtin_oid_index[];
4547

4648
#endif/* FMGRTAB_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp