!2555 优化内置函数(Internal Language实现)的查找方式

Merge pull request !2555 from april01xxx/dev_005_fmgr_lookup
This commit is contained in:
opengauss-bot 2023-02-13 02:02:57 +00:00 committed by Gitee
commit 2262a009cf
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 74 additions and 19 deletions

View File

@ -7605,7 +7605,7 @@
),
AddFuncGroup(
"pg_cancel_session", 1,
AddBuiltinFunc(_0(3991), _1("pg_cancel_session"), _2(2), _3(true), _4(false), _5(pg_cancel_session), _6(16), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(0), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('v'), _19(0), _20(2, 20, 20), _21(NULL), _22(NULL), _23(NULL), _24(NULL), _25("pg_cancel_session"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL))
AddBuiltinFunc(_0(3991), _1("pg_cancel_session"), _2(2), _3(true), _4(false), _5(pg_cancel_session), _6(16), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(0), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('v'), _19(0), _20(2, 20, 20), _21(NULL), _22(NULL), _23(NULL), _24(NULL), _25("pg_cancel_session"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0))
),
AddFuncGroup(
"pg_cbm_force_track", 1,

View File

@ -86,7 +86,7 @@ my $prorettype; #[6]
foreach my $row (@{ $catalog{builtindata} })
{
if ($row =~ /_0\(([0-9A-Z]+)\),\s+_1\(\"(\S+)\"\),\s+_2\((\d+)\),\s+_3\((\w+)\),\s+_4\((\w+)\),\s+.+?_6\((\d+)\),.+?_25\(\"(\w+)\"\),/)
if ($row =~ /_0\(([0-9A-Z_]+)\),\s+_1\(\"(\S+)\"\),\s+_2\((\d+)\),\s+_3\((\w+)\),\s+_4\((\w+)\),\s+.+?_6\((\w+)\),.+?_9\(INTERNALlanguageId\),.+?_25\(\"(.+?)\"\),/)
{
$foid = $1;
$funcName = $2;
@ -218,12 +218,58 @@ foreach my $s (sort { $a->{proname} cmp $b->{proname} } @fmgr)
# Create the fmgr_builtins table
print T "\nconst FmgrBuiltin fmgr_builtins[] = {\n";
my @fmgr_builtin_oid_index;
my $last_builtin_oid = 0;
foreach my $s (sort { $a->{prosrc} cmp $b->{prosrc} } @fmgr)
{
print T
" { $s->{oid}, \"$s->{prosrc}\", $s->{nargs}, $s->{strict}, $s->{retset}, $s->{prosrc}, $s->{prorettype} },\n";
$nfmgrfuncs = $nfmgrfuncs + 1;
" { $s->{oid}, \"$s->{prosrc}\", $s->{nargs}, $s->{strict}, $s->{retset}, $s->{prosrc}, $s->{prorettype} }";
$fmgr_builtin_oid_index[$s->{oid}] = $nfmgrfuncs++;
if ($nfmgrfuncs <= $#fmgr)
{
print T ",\n";
}
else
{
print T "\n";
}
$last_builtin_oid = $s->{oid};
}
print T "};\n";
printf T qq|
const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin));
const Oid fmgr_last_builtin_oid = %u;
|, $last_builtin_oid;
# Create fmgr_builtin_oid_index table.
printf T qq|
const uint16 fmgr_builtin_oid_index[%u] = {
|, $last_builtin_oid + 1;
for (my $i = 0; $i <= $last_builtin_oid; $i++)
{
my $oid = $fmgr_builtin_oid_index[$i];
# fmgr_builtin_oid_index is sparse, map nonexistent functions to
# InvalidOidBuiltinMapping
if (not defined $oid)
{
$oid = 'InvalidOidBuiltinMapping';
}
if ($i == $last_builtin_oid)
{
print T " $oid\n";
}
else
{
print T " $oid,\n";
}
}
print T "};\n";
print H "\n#define nBuiltinFuncs $nfuncs\n";
print H "\n#define NFMGRFUNCS $nfmgrfuncs\n";
@ -232,17 +278,6 @@ print H "\n#define NFMGRFUNCS $nfmgrfuncs\n";
# And add the file footers.
print H "\n#endif /* FMGROIDS_H */\n";
print T
qq| /* dummy entry is easier than getting rid of comma after last real one */
/* (not that there has ever been anything wrong with *having* a
comma after the last field in an array initializer) */
{ 0, NULL, 0, false, false, NULL, InvalidOid}
};
/* Note fmgr_nbuiltins excludes the dummy entry */
const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
|;
close(H);
close(T);
close(B);

View File

@ -171,11 +171,21 @@ extern char* get_language_name(Oid languageOid);
const FmgrBuiltin* fmgr_isbuiltin(Oid id)
{
const Builtin_func* func = SearchBuiltinFuncByOid(id);
if (func == NULL)
uint16 index;
/* fast lookup only possible if original oid still assigned */
if (id > fmgr_last_builtin_oid)
return NULL;
else
return (func->prolang != INTERNALlanguageId) ? NULL : (const FmgrBuiltin*)func;
/*
* Lookup function data. If there's a miss in that range it's likely a
* nonexistent function, returning NULL here will trigger an ERROR later.
*/
index = fmgr_builtin_oid_index[id];
if (index == InvalidOidBuiltinMapping)
return NULL;
return &fmgr_builtins[index];
}
/*

View File

@ -226,8 +226,18 @@ extern FuncGroup g_func_groups[];
extern const int g_nfuncgroups; /* number of function groups */
extern const Oid fmgr_last_builtin_oid; /* highest function OID in table */
void initBuiltinFuncs();
const FuncGroup* SearchBuiltinFuncByName(const char* funcname);
const Builtin_func* SearchBuiltinFuncByOid(Oid id);
/*
* Mapping from a builtin function's oid to the index in the fmgr_builtins
* array.
*/
#define InvalidOidBuiltinMapping UINT16_MAX
extern const uint16 fmgr_builtin_oid_index[];
#endif /* FMGRTAB_H */