add plpgsql hook and aggIsSupportedHook

This commit is contained in:
chenxiaobin19
2022-11-11 15:03:05 +08:00
parent ebef1ed4cd
commit 138d45bdd2
4 changed files with 28 additions and 20 deletions

View File

@ -38,6 +38,8 @@
static Oid lookup_agg_function(List* fnName, int nargs, Oid* input_types, Oid* rettype); static Oid lookup_agg_function(List* fnName, int nargs, Oid* input_types, Oid* rettype);
typedef bool (*aggIsSupportedFunc)(const char* aggName);
static void InternalAggIsSupported(const char *aggName) static void InternalAggIsSupported(const char *aggName)
{ {
static const char *supportList[] = { static const char *supportList[] = {
@ -59,6 +61,11 @@ static void InternalAggIsSupported(const char *aggName)
} }
} }
if (u_sess->hook_cxt.aggIsSupportedHook != NULL &&
((aggIsSupportedFunc)(u_sess->hook_cxt.aggIsSupportedHook))(aggName)) {
return;
}
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("unsafe use of pseudo-type \"internal\""), errmsg("unsafe use of pseudo-type \"internal\""),

View File

@ -151,6 +151,12 @@ static RegExternFunc plpgsql_function_table[] = {
{"report_application_error", report_application_error}, {"report_application_error", report_application_error},
}; };
/*
* Now for dolphin to rewrite plpgsql_call_handler, plpgsql_inline_handler
* and plpgsql_validator.
*/
RegExternFunc b_plpgsql_function_table[3];
static HTAB* CFuncHash = NULL; static HTAB* CFuncHash = NULL;
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo* finfo, MemoryContext mcxt, bool ignore_security); static void fmgr_info_cxt_security(Oid functionId, FmgrInfo* finfo, MemoryContext mcxt, bool ignore_security);
@ -391,11 +397,20 @@ static PGFunction load_plpgsql_function(char* funcname)
RegExternFunc* search_result = NULL; RegExternFunc* search_result = NULL;
tmp_key.func_name = funcname; tmp_key.func_name = funcname;
search_result = (RegExternFunc*)bsearch(&tmp_key, if (u_sess->attr.attr_sql.dolphin) {
plpgsql_function_table, search_result = (RegExternFunc*)bsearch(&tmp_key,
sizeof(plpgsql_function_table) / sizeof(plpgsql_function_table[0]), b_plpgsql_function_table,
sizeof(b_plpgsql_function_table) / sizeof(b_plpgsql_function_table[0]),
sizeof(RegExternFunc), sizeof(RegExternFunc),
ExternFuncComp); ExternFuncComp);
}
if (search_result == NULL) {
search_result = (RegExternFunc*)bsearch(&tmp_key,
plpgsql_function_table,
sizeof(plpgsql_function_table) / sizeof(plpgsql_function_table[0]),
sizeof(RegExternFunc),
ExternFuncComp);
}
if (search_result != NULL) { if (search_result != NULL) {
retval = search_result->func_addr; retval = search_result->func_addr;
} else if (!strcmp(funcname, "dist_fdw_validator")) { } else if (!strcmp(funcname, "dist_fdw_validator")) {

View File

@ -102,21 +102,6 @@ extern bool is_func_need_cache(Oid funcid, const char* func_name);
extern bool plpgsql_check_insert_colocate( extern bool plpgsql_check_insert_colocate(
Query* query, List* qry_part_attr_num, List* trig_part_attr_num, PLpgSQL_function* func); Query* query, List* qry_part_attr_num, List* trig_part_attr_num, PLpgSQL_function* func);
typedef int (*plsql_parser)(void);
static inline plsql_parser PlsqlParser()
{
int (*plsql_parser_hook)(void) = plpgsql_yyparse;
#ifndef ENABLE_MULTIPLE_NODES
if (u_sess->attr.attr_sql.enable_custom_parser) {
int id = GetCustomParserId();
if (id >= 0 && g_instance.plsql_parser_hook[id] != NULL) {
plsql_parser_hook = (int(*)(void))g_instance.plsql_parser_hook[id];
}
}
#endif
return plsql_parser_hook;
}
/* ---------- /* ----------
* plpgsql_compile Make an execution tree for a PL/pgSQL function. * plpgsql_compile Make an execution tree for a PL/pgSQL function.
* *
@ -1172,7 +1157,7 @@ static PLpgSQL_function* do_compile(FunctionCallInfo fcinfo, HeapTuple proc_tup,
*/ */
bool saved_flag = u_sess->plsql_cxt.have_error; bool saved_flag = u_sess->plsql_cxt.have_error;
u_sess->plsql_cxt.have_error = false; u_sess->plsql_cxt.have_error = false;
parse_rc = (*PlsqlParser())(); parse_rc = plpgsql_yyparse();
#ifndef ENABLE_MULTIPLE_NODES #ifndef ENABLE_MULTIPLE_NODES
if (u_sess->plsql_cxt.have_error && u_sess->attr.attr_common.plsql_show_all_error) { if (u_sess->plsql_cxt.have_error && u_sess->attr.attr_common.plsql_show_all_error) {
u_sess->plsql_cxt.have_error = false; u_sess->plsql_cxt.have_error = false;
@ -1475,7 +1460,7 @@ PLpgSQL_function* plpgsql_compile_inline(char* proc_source)
/* /*
* Now parse the function's text * Now parse the function's text
*/ */
parse_rc = (*PlsqlParser())(); parse_rc = plpgsql_yyparse();
if (parse_rc != 0) { if (parse_rc != 0) {
ereport(ERROR, (errmodule(MOD_PLSQL), errcode(ERRCODE_UNRECOGNIZED_NODE_TYPE), ereport(ERROR, (errmodule(MOD_PLSQL), errcode(ERRCODE_UNRECOGNIZED_NODE_TYPE),
errmsg("Syntax parsing error, plpgsql parser returned %d", parse_rc))); errmsg("Syntax parsing error, plpgsql parser returned %d", parse_rc)));

View File

@ -2691,6 +2691,7 @@ typedef struct knl_u_hook_context {
void *computeHashHook; void *computeHashHook;
void *aggSmpHook; void *aggSmpHook;
void *standardProcessUtilityHook; void *standardProcessUtilityHook;
void *aggIsSupportedHook;
} knl_u_hook_context; } knl_u_hook_context;
/* PBE message flag */ /* PBE message flag */
typedef enum { typedef enum {