diff --git a/src/common/backend/utils/init/miscinit.cpp b/src/common/backend/utils/init/miscinit.cpp index 490d34c6f..c1c09411b 100644 --- a/src/common/backend/utils/init/miscinit.cpp +++ b/src/common/backend/utils/init/miscinit.cpp @@ -451,6 +451,33 @@ const char* show_nodegroup_mode(void) return "unknown"; } } + +#endif + +#ifndef ENABLE_MULTIPLE_NODES +const int GetCustomParserId() +{ + int id = 0; + switch (u_sess->attr.attr_sql.sql_compatibility) { + case A_FORMAT: + id = DB_CMPT_A; + break; + case B_FORMAT: + id = DB_CMPT_B; + break; + case C_FORMAT: + id = DB_CMPT_C; + break; + case PG_FORMAT: + id = DB_CMPT_PG; + break; + default: + ereport(WARNING, (errmsg("Unknown sql compatibility: %d", u_sess->attr.attr_sql.sql_compatibility))); + return -1; + } + Assert(id >= 0 && id < DB_CMPT_MAX); + return id; +} #endif /* diff --git a/src/common/backend/utils/misc/guc/guc_sql.cpp b/src/common/backend/utils/misc/guc/guc_sql.cpp index e4936d7e7..fca448ca5 100755 --- a/src/common/backend/utils/misc/guc/guc_sql.cpp +++ b/src/common/backend/utils/misc/guc/guc_sql.cpp @@ -1307,6 +1307,17 @@ static void InitSqlConfigureNamesBool() NULL, NULL, NULL}, + {{"enable_custom_parser", + PGC_USERSET, + NODE_SINGLENODE, + UNGROUPED, + gettext_noop("Enables custom parser"), + NULL}, + &u_sess->attr.attr_sql.enable_custom_parser, + false, + NULL, + NULL, + NULL}, #endif {{"enable_partition_opfusion", diff --git a/src/common/pl/plpgsql/src/pl_comp.cpp b/src/common/pl/plpgsql/src/pl_comp.cpp index 1611b428c..614d0154a 100644 --- a/src/common/pl/plpgsql/src/pl_comp.cpp +++ b/src/common/pl/plpgsql/src/pl_comp.cpp @@ -102,6 +102,20 @@ 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. * @@ -1098,7 +1112,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 = plpgsql_yyparse(); + parse_rc = (*PlsqlParser())(); #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; @@ -1368,7 +1382,7 @@ PLpgSQL_function* plpgsql_compile_inline(char* proc_source) /* * Now parse the function's text */ - parse_rc = plpgsql_yyparse(); + parse_rc = (*PlsqlParser())(); 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/gausskernel/process/tcop/postgres.cpp b/src/gausskernel/process/tcop/postgres.cpp index 8e26201f2..12f8b1493 100755 --- a/src/gausskernel/process/tcop/postgres.cpp +++ b/src/gausskernel/process/tcop/postgres.cpp @@ -816,6 +816,7 @@ void client_read_ended(void) } } + /* * Do raw parsing (only). * @@ -841,7 +842,16 @@ List* pg_parse_query(const char* query_string, List** query_string_locationlist) PGSTAT_START_TIME_RECORD(); - raw_parsetree_list = raw_parser(query_string, query_string_locationlist); + List* (*parser_hook)(const char*, List**) = raw_parser; +#ifndef ENABLE_MULTIPLE_NODES + if (u_sess->attr.attr_sql.enable_custom_parser) { + 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]; + } + } +#endif + raw_parsetree_list = parser_hook(query_string, query_string_locationlist); PGSTAT_END_TIME_RECORD(PARSE_TIME); 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 78722fce6..1b9892e2a 100644 --- a/src/include/knl/knl_guc/knl_session_attr_sql.h +++ b/src/include/knl/knl_guc/knl_session_attr_sql.h @@ -232,6 +232,9 @@ typedef struct knl_session_attr_sql { int pldebugger_timeout; bool for_print_tuple; bool numeric_out_for_format; +#ifndef ENABLE_MULTIPLE_NODES + bool enable_custom_parser; +#endif } knl_session_attr_sql; #endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SQL */ diff --git a/src/include/knl/knl_instance.h b/src/include/knl/knl_instance.h index adbe1af91..fabfaab66 100755 --- a/src/include/knl/knl_instance.h +++ b/src/include/knl/knl_instance.h @@ -74,6 +74,9 @@ const int NUM_PERCENTILE_COUNT = 2; const int INIT_NUMA_ALLOC_COUNT = 32; const int HOTKEY_ABANDON_LENGTH = 100; const int MAX_GLOBAL_CACHEMEM_NUM = 128; +#ifndef ENABLE_MULTIPLE_NODES +const int DB_CMPT_MAX = 4; +#endif enum knl_virtual_role { VUNKNOWN = 0, @@ -1030,6 +1033,11 @@ typedef struct knl_instance_context { knl_g_streaming_dr_context streaming_dr_cxt; struct PLGlobalPackageRuntimeCache* global_session_pkg; pg_atomic_uint32 extensionNum; + +#ifndef ENABLE_MULTIPLE_NODES + void *raw_parser_hook[DB_CMPT_MAX]; + void *plsql_parser_hook[DB_CMPT_MAX]; +#endif } knl_instance_context; extern long random(); diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h index fe78e2fdf..5a4a769e9 100644 --- a/src/include/miscadmin.h +++ b/src/include/miscadmin.h @@ -332,6 +332,10 @@ extern bool exist_logic_cluster(); #ifdef ENABLE_MULTIPLE_NODES extern const char* show_nodegroup_mode(void); #endif + +#ifndef ENABLE_MULTIPLE_NODES +extern const int GetCustomParserId(); +#endif extern const char* show_lcgroup_name(); extern Oid get_pgxc_logic_groupoid(Oid roleid); extern Oid get_pgxc_logic_groupoid(const char* groupname);