diff --git a/contrib/security_plugin/gs_policy_plugin.cpp b/contrib/security_plugin/gs_policy_plugin.cpp index fe0f8d141..5f739f5b0 100644 --- a/contrib/security_plugin/gs_policy_plugin.cpp +++ b/contrib/security_plugin/gs_policy_plugin.cpp @@ -97,7 +97,6 @@ PG_MODULE_MAGIC; extern "C" void _PG_init(void); extern "C" void _PG_fini(void); -extern "C" void set_gsaudit_prehook(ProcessUtility_hook_type func); #define POLICY_STR_BUFF_LEN 512 #define POLICY_TMP_BUFF_LEN 256 @@ -1782,7 +1781,7 @@ void install_audit_hook() * preserve the chains. */ next_ExecutorStart_hook = ExecutorStart_hook; - set_gsaudit_prehook(ProcessUtility_hook); + next_ProcessUtility_hook = ProcessUtility_hook; /* * Install audit hooks, the interface for GaussDB kernel user as below @@ -1822,15 +1821,6 @@ void install_label_hook() } } -/* - * This function is used for setting prev_ProcessUtility to rewrite - * standard_ProcessUtility by other extension. - */ -void set_gsaudit_prehook(ProcessUtility_hook_type func) -{ - next_ProcessUtility_hook = func; -} - /* * Define GUC variables and install hooks upon module load. * NOTE: _PG_init will be invoked(installed) many times diff --git a/src/gausskernel/dbmind/kernel/hypopg_index.cpp b/src/gausskernel/dbmind/kernel/hypopg_index.cpp index 62fad5d84..fd6e61971 100644 --- a/src/gausskernel/dbmind/kernel/hypopg_index.cpp +++ b/src/gausskernel/dbmind/kernel/hypopg_index.cpp @@ -104,19 +104,10 @@ void InitHypopg() isExplain = false; } -/* - * This function is used for setting prev_utility_hook to rewrite - * standard_ProcessUtility by extension. - */ -void set_hypopg_prehook(ProcessUtility_hook_type func) -{ - prev_utility_hook = func; -} - void hypopg_register_hook() { // register hooks - set_hypopg_prehook(ProcessUtility_hook); + prev_utility_hook = ProcessUtility_hook; ProcessUtility_hook = hypo_utility_hook; prev_ExecutorEnd_hook = ExecutorEnd_hook; diff --git a/src/gausskernel/process/tcop/auditfuncs.cpp b/src/gausskernel/process/tcop/auditfuncs.cpp index 40f7c47ac..fcba9cdeb 100644 --- a/src/gausskernel/process/tcop/auditfuncs.cpp +++ b/src/gausskernel/process/tcop/auditfuncs.cpp @@ -124,15 +124,6 @@ static const AuditFuncMap g_auditFuncMap[] = { }; static const int g_auditFuncMapNum = sizeof(g_auditFuncMap) / sizeof(AuditFuncMap); -/* - * This function is used for setting prev_ProcessUtility to rewrite - * standard_ProcessUtility by extension. - */ -void set_pgaudit_prehook(ProcessUtility_hook_type func) -{ - prev_ProcessUtility = func; -} - /* * Brief : perfstat_agent_init() * Description : Module load callback. @@ -146,7 +137,7 @@ void pgaudit_agent_init(void) } prev_ExecutorEnd = ExecutorEnd_hook; ExecutorEnd_hook = pgaudit_ExecutorEnd; - set_pgaudit_prehook(ProcessUtility_hook); + prev_ProcessUtility = ProcessUtility_hook; ProcessUtility_hook = (ProcessUtility_hook_type)pgaudit_ProcessUtility; u_sess->exec_cxt.g_pgaudit_agent_attached = true; } diff --git a/src/gausskernel/process/tcop/postgres.cpp b/src/gausskernel/process/tcop/postgres.cpp index 42d832182..80f17493a 100755 --- a/src/gausskernel/process/tcop/postgres.cpp +++ b/src/gausskernel/process/tcop/postgres.cpp @@ -876,11 +876,13 @@ void InitBSqlPluginHookIfNeeded() } #define LOAD_DOLPHIN "create_dolphin_extension" -void LoadDolphinIfNeeded() +bool LoadDolphinIfNeeded() { if (IsFileExisted(DOLPHIN)) { ExecuteFunctionIfExisted(DOLPHIN, LOAD_DOLPHIN); + return true; } + return false; } #endif @@ -7182,6 +7184,8 @@ void RemoveTempNamespace() void LoadSqlPlugin() { if (u_sess->proc_cxt.MyDatabaseId != InvalidOid && DB_IS_CMPT(B_FORMAT)) { + bool loaded = true; + if (!u_sess->attr.attr_sql.dolphin) { /* recheck and load dolphin within lock */ pthread_mutex_lock(&g_instance.loadPluginLock[DB_CMPT_B]); @@ -7191,12 +7195,12 @@ void LoadSqlPlugin() finish_xact_command(); if (!u_sess->attr.attr_sql.dolphin) { - LoadDolphinIfNeeded(); - } else { - InitBSqlPluginHookIfNeeded(); + loaded = LoadDolphinIfNeeded(); } pthread_mutex_unlock(&g_instance.loadPluginLock[DB_CMPT_B]); - } else { + } + + if (loaded) { InitBSqlPluginHookIfNeeded(); } } else if (u_sess->proc_cxt.MyDatabaseId != InvalidOid && DB_IS_CMPT(A_FORMAT) && u_sess->attr.attr_sql.whale) { diff --git a/src/gausskernel/process/tcop/utility.cpp b/src/gausskernel/process/tcop/utility.cpp index 0476aa278..1d2a0be0c 100755 --- a/src/gausskernel/process/tcop/utility.cpp +++ b/src/gausskernel/process/tcop/utility.cpp @@ -2408,6 +2408,12 @@ void standard_ProcessUtility(Node* parse_tree, const char* query_string, ParamLi char* completion_tag, bool isCTAS) { +#if (!defined(ENABLE_MULTIPLE_NODES)) && (!defined(ENABLE_PRIVATEGAUSS)) + if (u_sess->hook_cxt.standardProcessUtilityHook) { + return ((ProcessUtility_hook_type)(u_sess->hook_cxt.standardProcessUtilityHook))(parse_tree, query_string, + params, is_top_level, dest, sent_to_remote, completion_tag, isCTAS); + } +#endif /* This can recurse, so check for excessive recursion */ check_stack_depth(); diff --git a/src/gausskernel/process/threadpool/threadpool_worker.cpp b/src/gausskernel/process/threadpool/threadpool_worker.cpp index 4f68fba0c..51e9824fb 100644 --- a/src/gausskernel/process/threadpool/threadpool_worker.cpp +++ b/src/gausskernel/process/threadpool/threadpool_worker.cpp @@ -793,7 +793,6 @@ static void init_session_share_memory() #ifndef ENABLE_MULTIPLE_NODES extern void InitASqlPluginHookIfNeeded(); extern void InitBSqlPluginHookIfNeeded(); -extern void LoadDolphinIfNeeded(); #endif static bool InitSession(knl_session_context* session) diff --git a/src/include/knl/knl_session.h b/src/include/knl/knl_session.h index 0519ae451..26313b2f8 100644 --- a/src/include/knl/knl_session.h +++ b/src/include/knl/knl_session.h @@ -2650,6 +2650,7 @@ typedef struct knl_u_hook_context { void *execInitExprHook; void *computeHashHook; void *aggSmpHook; + void *standardProcessUtilityHook; } knl_u_hook_context; typedef struct knl_session_context {