!1778 添加whale插件

Merge pull request !1778 from 仲夏十三/dolphin
This commit is contained in:
opengauss-bot
2022-06-01 07:51:55 +00:00
committed by Gitee
7 changed files with 51 additions and 16 deletions

View File

@ -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;

View File

@ -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()

View File

@ -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];

View File

@ -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;
}
/*

View File

@ -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

View File

@ -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

View File

@ -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 */