Fix builtin func bug in plugin.

This commit is contained in:
totaj
2023-12-05 11:34:17 +08:00
parent 5fbb0ca3a6
commit 440afce160
3 changed files with 49 additions and 19 deletions

View File

@ -38,10 +38,6 @@
static_assert(sizeof(true) == sizeof(char), "illegal bool size");
static_assert(sizeof(false) == sizeof(char), "illegal bool size");
#define CUR_THR_IS_WORKER() (t_thrd.role == WORKER || t_thrd.role == THREADPOOL_WORKER ||\
t_thrd.role == STREAM_WORKER || t_thrd.role == THREADPOOL_STREAM || t_thrd.role == WAL_DB_SENDER||\
t_thrd.role == PARALLEL_DECODE || t_thrd.role == JOB_WORKER)
#ifdef ENABLE_MULTIPLE_NODES
FuncGroup g_func_groups[] = {
#include "builtin_funcs.ini"

View File

@ -48,6 +48,14 @@ THR_LOCAL PGDLLIMPORT needs_fmgr_hook_type needs_fmgr_hook = NULL;
THR_LOCAL PGDLLIMPORT fmgr_hook_type fmgr_hook = NULL;
extern void InitFuncCallUDFInfo(FunctionCallInfoData* fcinfo, int argN, bool setFuncPtr);
#if (!defined(ENABLE_MULTIPLE_NODES)) && (!defined(ENABLE_PRIVATEGAUSS))
/* for dolphin and whale plugin */
int a_fmgr_nbuiltins = -1;
int b_fmgr_nbuiltins = -1;
FmgrBuiltin *a_fmgr_builtins = NULL;
FmgrBuiltin *b_fmgr_builtins = NULL;
#endif
/*
* Declaration for old-style function pointer type. This is now used only
* in fmgr_oldstyle() and is no longer exported.
@ -157,12 +165,12 @@ static RegExternFunc plpgsql_function_table[] = {
*/
RegExternFunc b_plpgsql_function_table[3];
/*
* Now for whale to rewrite plpgsql_call_handler, plpgsql_inline_handler
* and plpgsql_validator.
*/
RegExternFunc a_plpgsql_function_table[3];
/*
* Now for whale to rewrite plpgsql_call_handler, plpgsql_inline_handler
* and plpgsql_validator.
*/
RegExternFunc a_plpgsql_function_table[3];
static HTAB* CFuncHash = NULL;
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo* finfo, MemoryContext mcxt, bool ignore_security);
@ -197,14 +205,27 @@ const FmgrBuiltin* fmgr_isbuiltin(Oid id)
*/
static const FmgrBuiltin* fmgr_lookupByName(const char* name)
{
int nbuiltins = fmgr_nbuiltins;
const FmgrBuiltin *builtinfunc = fmgr_builtins;
#if (!defined(ENABLE_MULTIPLE_NODES)) && (!defined(ENABLE_PRIVATEGAUSS))
if (CUR_THR_IS_WORKER() && IsNormalProcessingMode()) {
if (a_fmgr_nbuiltins > 0 && DB_IS_CMPT(A_FORMAT)) {
nbuiltins = a_fmgr_nbuiltins;
builtinfunc = a_fmgr_builtins;
} else if (b_fmgr_nbuiltins > 0 && DB_IS_CMPT(B_FORMAT)) {
nbuiltins = b_fmgr_nbuiltins;
builtinfunc = b_fmgr_builtins;
}
}
#endif
int low = 0;
int high = fmgr_nbuiltins - 1;
int high = nbuiltins - 1;
int ret;
while (low <= high) {
int i = (high + low) / 2;
ret = strcmp(name, fmgr_builtins[i].funcName);
ret = strcmp(name, builtinfunc[i].funcName);
if (ret == 0) {
return fmgr_builtins + i;
return builtinfunc + i;
} else if (ret > 0) {
low = i + 1;
} else {
@ -409,12 +430,12 @@ static PGFunction load_plpgsql_function(char* funcname)
sizeof(b_plpgsql_function_table) / sizeof(b_plpgsql_function_table[0]),
sizeof(RegExternFunc),
ExternFuncComp);
} else if (u_sess->attr.attr_sql.whale) {
search_result = (RegExternFunc*)bsearch(&tmp_key,
a_plpgsql_function_table,
sizeof(a_plpgsql_function_table) / sizeof(a_plpgsql_function_table[0]),
sizeof(RegExternFunc),
ExternFuncComp);
} else if (u_sess->attr.attr_sql.whale) {
search_result = (RegExternFunc*)bsearch(&tmp_key,
a_plpgsql_function_table,
sizeof(a_plpgsql_function_table) / sizeof(a_plpgsql_function_table[0]),
sizeof(RegExternFunc),
ExternFuncComp);
}
if (search_result == NULL) {
search_result = (RegExternFunc*)bsearch(&tmp_key,

View File

@ -210,7 +210,20 @@ static_assert(sizeof(NULL) == sizeof(void*), "NULL must be a 8 byte-length point
} \
}
#define CUR_THR_IS_WORKER() (t_thrd.role == WORKER || t_thrd.role == THREADPOOL_WORKER ||\
t_thrd.role == STREAM_WORKER || t_thrd.role == THREADPOOL_STREAM || t_thrd.role == WAL_DB_SENDER||\
t_thrd.role == PARALLEL_DECODE || t_thrd.role == JOB_WORKER)
#if (!defined(ENABLE_MULTIPLE_NODES)) && (!defined(ENABLE_PRIVATEGAUSS))
/* for dolphin and whale plugin */
extern int a_fmgr_nbuiltins;
extern int b_fmgr_nbuiltins;
extern FmgrBuiltin *a_fmgr_builtins;
extern FmgrBuiltin *b_fmgr_builtins;
#endif
extern const FmgrBuiltin fmgr_builtins[];
extern const FmgrBuiltin* fmgr_isbuiltin(Oid id);
extern const int fmgr_nbuiltins; /* number of entries in table */