diff --git a/src/common/backend/catalog/pg_aggregate.cpp b/src/common/backend/catalog/pg_aggregate.cpp index 5c5e3f6a6..0e88f6ba5 100644 --- a/src/common/backend/catalog/pg_aggregate.cpp +++ b/src/common/backend/catalog/pg_aggregate.cpp @@ -38,6 +38,8 @@ 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 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, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), errmsg("unsafe use of pseudo-type \"internal\""), diff --git a/src/common/backend/utils/fmgr/fmgr.cpp b/src/common/backend/utils/fmgr/fmgr.cpp index 173c0f532..fc4e28270 100755 --- a/src/common/backend/utils/fmgr/fmgr.cpp +++ b/src/common/backend/utils/fmgr/fmgr.cpp @@ -151,6 +151,12 @@ static RegExternFunc plpgsql_function_table[] = { {"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 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; tmp_key.func_name = funcname; - search_result = (RegExternFunc*)bsearch(&tmp_key, - plpgsql_function_table, - sizeof(plpgsql_function_table) / sizeof(plpgsql_function_table[0]), + if (u_sess->attr.attr_sql.dolphin) { + search_result = (RegExternFunc*)bsearch(&tmp_key, + b_plpgsql_function_table, + sizeof(b_plpgsql_function_table) / sizeof(b_plpgsql_function_table[0]), sizeof(RegExternFunc), 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) { retval = search_result->func_addr; } else if (!strcmp(funcname, "dist_fdw_validator")) { diff --git a/src/common/pl/plpgsql/src/pl_comp.cpp b/src/common/pl/plpgsql/src/pl_comp.cpp index 1bb5ce7eb..23c69f27f 100644 --- a/src/common/pl/plpgsql/src/pl_comp.cpp +++ b/src/common/pl/plpgsql/src/pl_comp.cpp @@ -102,21 +102,6 @@ extern bool is_func_need_cache(Oid funcid, const char* func_name); extern bool plpgsql_check_insert_colocate( 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. * @@ -1172,7 +1157,7 @@ static PLpgSQL_function* do_compile(FunctionCallInfo fcinfo, HeapTuple proc_tup, */ bool saved_flag = u_sess->plsql_cxt.have_error; u_sess->plsql_cxt.have_error = false; - parse_rc = (*PlsqlParser())(); + parse_rc = plpgsql_yyparse(); #ifndef ENABLE_MULTIPLE_NODES if (u_sess->plsql_cxt.have_error && u_sess->attr.attr_common.plsql_show_all_error) { 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 */ - parse_rc = (*PlsqlParser())(); + parse_rc = plpgsql_yyparse(); if (parse_rc != 0) { ereport(ERROR, (errmodule(MOD_PLSQL), errcode(ERRCODE_UNRECOGNIZED_NODE_TYPE), errmsg("Syntax parsing error, plpgsql parser returned %d", parse_rc))); diff --git a/src/include/knl/knl_session.h b/src/include/knl/knl_session.h index a408a64a6..3ae141385 100644 --- a/src/include/knl/knl_session.h +++ b/src/include/knl/knl_session.h @@ -2691,6 +2691,7 @@ typedef struct knl_u_hook_context { void *computeHashHook; void *aggSmpHook; void *standardProcessUtilityHook; + void *aggIsSupportedHook; } knl_u_hook_context; /* PBE message flag */ typedef enum {