diff --git a/src/common/backend/catalog/pg_builtin_proc.cpp b/src/common/backend/catalog/pg_builtin_proc.cpp index 5e30b493b..ff7a9ff1a 100755 --- a/src/common/backend/catalog/pg_builtin_proc.cpp +++ b/src/common/backend/catalog/pg_builtin_proc.cpp @@ -52,6 +52,10 @@ static_assert(sizeof(false) == sizeof(char), "illegal bool size"); static struct HTAB* nameHash = NULL; static struct HTAB* oidHash = NULL; +/* for whale */ +struct HTAB* a_nameHash = NULL; +struct HTAB* a_oidHash = NULL; + /* for dolphin */ struct HTAB* b_nameHash = NULL; struct HTAB* b_oidHash = NULL; @@ -108,6 +112,26 @@ static void InitHashTable(int size) HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT); } +static HTAB* get_name_hash_table_type() +{ + if (a_nameHash != NULL && u_sess->attr.attr_sql.whale) { + return a_nameHash; + } else if (b_nameHash != NULL && u_sess->attr.attr_sql.dolphin) { + return b_nameHash; + } + return nameHash; +} + +static HTAB* get_oid_hash_table_type() +{ + if (a_oidHash != NULL && u_sess->attr.attr_sql.whale) { + return a_oidHash; + } else if (b_oidHash != NULL && u_sess->attr.attr_sql.dolphin) { + return b_oidHash; + } + return oidHash; +} + static const FuncGroup* NameHashTableAccess(HASHACTION action, const char* name, const FuncGroup* group) { char temp_name[MAX_PROC_NAME_LEN] = {0}; @@ -117,12 +141,7 @@ static const FuncGroup* NameHashTableAccess(HASHACTION action, const char* name, bool found = false; Assert(name != NULL); - - if (DB_IS_CMPT(B_FORMAT) && b_nameHash != NULL && u_sess->attr.attr_sql.dolphin) { - result = (HashEntryNameToFuncGroup *)hash_search(b_nameHash, &temp_name, action, &found); - } else { - result = (HashEntryNameToFuncGroup *)hash_search(nameHash, &temp_name, action, &found); - } + result = (HashEntryNameToFuncGroup *)hash_search(get_name_hash_table_type(), &temp_name, action, &found); if (action == HASH_ENTER) { Assert(!found); result->group = group; @@ -143,12 +162,7 @@ static const Builtin_func* OidHashTableAccess(HASHACTION action, Oid oid, const HashEntryOidToBuiltinFunc *result = NULL; bool found = false; Assert(oid > 0); - - if (DB_IS_CMPT(B_FORMAT) && b_oidHash != NULL && u_sess->attr.attr_sql.dolphin) { - result = (HashEntryOidToBuiltinFunc *)hash_search(b_oidHash, &oid, action, &found); - } else { - result = (HashEntryOidToBuiltinFunc *)hash_search(oidHash, &oid, action, &found); - } + result = (HashEntryOidToBuiltinFunc *)hash_search(get_oid_hash_table_type(), &oid, action, &found); if (action == HASH_ENTER) { Assert(!found); result->func = func; diff --git a/src/common/backend/utils/init/postinit.cpp b/src/common/backend/utils/init/postinit.cpp index 32625fee1..14b5fc6ee 100644 --- a/src/common/backend/utils/init/postinit.cpp +++ b/src/common/backend/utils/init/postinit.cpp @@ -2711,9 +2711,13 @@ void PostgresInitializer::InitExtensionVariable() (*init_session_vars)(); } - /* check whether the extension has been created */ + /* check whether the extension has been created + * at most one will be true. + */ + const char* whale = "whale"; const char* dolphin = "dolphin"; u_sess->attr.attr_sql.dolphin = CheckIfExtensionExists(dolphin); + u_sess->attr.attr_sql.whale = CheckIfExtensionExists(whale); } void PostgresInitializer::FinishInit() diff --git a/src/common/pl/plpgsql/src/gram.y b/src/common/pl/plpgsql/src/gram.y index 156573bd6..88088525c 100755 --- a/src/common/pl/plpgsql/src/gram.y +++ b/src/common/pl/plpgsql/src/gram.y @@ -10342,7 +10342,7 @@ check_sql_expr(const char *stmt, int location, int leaderlen) u_sess->plsql_cxt.plpgsql_yylloc = plpgsql_yylloc; RawParserHook parser_hook= raw_parser; #ifndef ENABLE_MULTIPLE_NODES - if (u_sess->attr.attr_sql.dolphin) { + if (u_sess->attr.attr_sql.whale || u_sess->attr.attr_sql.dolphin) { int id = GetCustomParserId(); if (id >= 0 && g_instance.raw_parser_hook[id] != NULL) { parser_hook = (RawParserHook)g_instance.raw_parser_hook[id]; diff --git a/src/gausskernel/optimizer/commands/extension.cpp b/src/gausskernel/optimizer/commands/extension.cpp index 4eff486bb..1f145f79c 100644 --- a/src/gausskernel/optimizer/commands/extension.cpp +++ b/src/gausskernel/optimizer/commands/extension.cpp @@ -1178,6 +1178,9 @@ void CreateExtension(CreateExtensionStmt* stmt) if (pg_strcasecmp(stmt->extname, "dolphin") == 0 && !DB_IS_CMPT(B_FORMAT)) { ereport(ERROR, (errmsg("please create extension \"%s\" with B type DBCOMPATIBILITY", stmt->extname))); + } else if (pg_strcasecmp(stmt->extname, "whale") == 0 && !DB_IS_CMPT(A_FORMAT)) { + ereport(ERROR, + (errmsg("please create extension \"%s\" with A type DBCOMPATIBILITY", stmt->extname))); } /* Check extension name validity before any filesystem access */ check_valid_extension_name(stmt->extname); @@ -1420,6 +1423,8 @@ void CreateExtension(CreateExtensionStmt* stmt) if (pg_strcasecmp(stmt->extname, "dolphin") == 0) { u_sess->attr.attr_sql.dolphin = true; + } else if (pg_strcasecmp(stmt->extname, "whale") == 0) { + u_sess->attr.attr_sql.whale = true; } /* diff --git a/src/gausskernel/process/tcop/postgres.cpp b/src/gausskernel/process/tcop/postgres.cpp index c9e777ce4..a597b291f 100755 --- a/src/gausskernel/process/tcop/postgres.cpp +++ b/src/gausskernel/process/tcop/postgres.cpp @@ -839,7 +839,13 @@ bool IsFileExisted(const char *filename) } #define INIT_PLUGIN_OBJECT "init_plugin_object" +#define WHALE "whale" #define DOLPHIN "dolphin" +void InitASqlPluginHookIfNeeded() +{ + ExecuteFunctionIfExisted(WHALE, INIT_PLUGIN_OBJECT); +} + void InitBSqlPluginHookIfNeeded() { ExecuteFunctionIfExisted(DOLPHIN, INIT_PLUGIN_OBJECT); @@ -881,7 +887,7 @@ List* pg_parse_query(const char* query_string, List** query_string_locationlist) List* (*parser_hook)(const char*, List**) = raw_parser; #ifndef ENABLE_MULTIPLE_NODES - if (u_sess->attr.attr_sql.dolphin) { + if (u_sess->attr.attr_sql.whale || u_sess->attr.attr_sql.dolphin) { int id = GetCustomParserId(); if (id >= 0 && g_instance.raw_parser_hook[id] != NULL) { parser_hook = (List* (*)(const char*, List**))g_instance.raw_parser_hook[id]; @@ -7599,6 +7605,8 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam } else { InitBSqlPluginHookIfNeeded(); } + } else if (u_sess->proc_cxt.MyDatabaseId != InvalidOid && DB_IS_CMPT(A_FORMAT) && u_sess->attr.attr_sql.whale) { + InitASqlPluginHookIfNeeded(); } #endif diff --git a/src/gausskernel/process/threadpool/threadpool_worker.cpp b/src/gausskernel/process/threadpool/threadpool_worker.cpp index 4f2dbd483..b2be2a44c 100644 --- a/src/gausskernel/process/threadpool/threadpool_worker.cpp +++ b/src/gausskernel/process/threadpool/threadpool_worker.cpp @@ -770,6 +770,7 @@ static void init_session_share_memory() } #ifndef ENABLE_MULTIPLE_NODES +extern void InitASqlPluginHookIfNeeded(); extern void InitBSqlPluginHookIfNeeded(); extern void LoadDolphinIfNeeded(); #endif @@ -859,6 +860,8 @@ static bool InitSession(knl_session_context* session) } else { InitBSqlPluginHookIfNeeded(); } + } else if (u_sess->proc_cxt.MyDatabaseId != InvalidOid && DB_IS_CMPT(A_FORMAT) && u_sess->attr.attr_sql.whale) { + InitASqlPluginHookIfNeeded(); } #endif diff --git a/src/include/knl/knl_guc/knl_session_attr_sql.h b/src/include/knl/knl_guc/knl_session_attr_sql.h index 9d252ea0c..8fcb124ff 100644 --- a/src/include/knl/knl_guc/knl_session_attr_sql.h +++ b/src/include/knl/knl_guc/knl_session_attr_sql.h @@ -237,8 +237,9 @@ typedef struct knl_session_attr_sql { int vectorEngineStrategy; #ifndef ENABLE_MULTIPLE_NODES bool enable_custom_parser; -#endif bool dolphin; + bool whale; +#endif } knl_session_attr_sql; #endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SQL */