diff --git a/src/common/backend/parser/analyze.cpp b/src/common/backend/parser/analyze.cpp index 6f161c1ad..d60ad9c1c 100644 --- a/src/common/backend/parser/analyze.cpp +++ b/src/common/backend/parser/analyze.cpp @@ -356,6 +356,7 @@ Query* transformCreateModelStmt(ParseState* pstate, CreateModelStmt* stmt) Query* transformStmt(ParseState* pstate, Node* parseTree, bool isFirstNode, bool isCreateView) { Query* result = NULL; + AnalyzerRoutine *analyzerRoutineHook = (AnalyzerRoutine*)u_sess->hook_cxt.analyzerRoutineHook; switch (nodeTag(parseTree)) { /* @@ -379,12 +380,17 @@ Query* transformStmt(ParseState* pstate, Node* parseTree, bool isFirstNode, bool case T_SelectStmt: { SelectStmt* n = (SelectStmt*)parseTree; - if (n->valuesLists) + if (n->valuesLists) { result = transformValuesClause(pstate, n); - else if (n->op == SETOP_NONE) - result = transformSelectStmt(pstate, n, isFirstNode, isCreateView); - else + } else if (n->op == SETOP_NONE) { + if (analyzerRoutineHook == NULL || analyzerRoutineHook->transSelect == NULL) { + result = transformSelectStmt(pstate, n, isFirstNode, isCreateView); + } else { + result = analyzerRoutineHook->transSelect(pstate, n, isFirstNode, isCreateView); + } + } else { result = transformSetOperationStmt(pstate, n); + } } break; /* diff --git a/src/common/backend/utils/fmgr/dfmgr.cpp b/src/common/backend/utils/fmgr/dfmgr.cpp index fbdf00197..885bd2146 100644 --- a/src/common/backend/utils/fmgr/dfmgr.cpp +++ b/src/common/backend/utils/fmgr/dfmgr.cpp @@ -319,6 +319,14 @@ void* internal_load_library(const char* libname) (*set_extension_index)(idx); } + /* call init_session_vars after set_extension_index */ + if (IsUnderPostmaster) { + void (*init_session_vars)(void) = (void(*)(void))pg_dlsym(file_scanner->handle, "init_session_vars"); + if (init_session_vars) { + (*init_session_vars)(); + } + } + /* OK to link it into list */ if (file_list == NULL) file_list = file_scanner; diff --git a/src/common/backend/utils/init/globals.cpp b/src/common/backend/utils/init/globals.cpp index 28a6a460f..8e4b01959 100644 --- a/src/common/backend/utils/init/globals.cpp +++ b/src/common/backend/utils/init/globals.cpp @@ -59,7 +59,7 @@ bool open_join_children = true; bool will_shutdown = false; /* hard-wired binary version number */ -const uint32 GRAND_VERSION_NUM = 92305; +const uint32 GRAND_VERSION_NUM = 92306; const uint32 MATVIEW_VERSION_NUM = 92213; const uint32 PARTIALPUSH_VERSION_NUM = 92087; @@ -78,6 +78,7 @@ const uint32 BACKUP_SLOT_VERSION_NUM = 92282; const uint32 ML_OPT_MODEL_VERSION_NUM = 92284; const uint32 FIX_SQL_ADD_RELATION_REF_COUNT = 92291; const uint32 GENERATED_COL_VERSION_NUM = 92303; +const uint32 ANALYZER_HOOK_VERSION_NUM = 92306; /* This variable indicates wheather the instance is in progress of upgrade as a whole */ uint32 volatile WorkingGrandVersionNum = GRAND_VERSION_NUM; diff --git a/src/include/knl/knl_session.h b/src/include/knl/knl_session.h index 7855e2e7f..e730700b5 100644 --- a/src/include/knl/knl_session.h +++ b/src/include/knl/knl_session.h @@ -2281,6 +2281,10 @@ typedef struct sess_orient{ uint32 cn_nodeid; }sess_orient; +typedef struct knl_u_hook_context { + void *analyzerRoutineHook; +} knl_u_hook_context; + typedef struct knl_session_context { volatile knl_session_status status; Dlelem elem; @@ -2380,6 +2384,8 @@ typedef struct knl_session_context { knl_u_streaming_context streaming_cxt; instr_time last_access_time; + + knl_u_hook_context hook_cxt; } knl_session_context; enum stp_xact_err_type { diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h index c42ec48fe..a7576b957 100644 --- a/src/include/miscadmin.h +++ b/src/include/miscadmin.h @@ -54,6 +54,7 @@ extern const uint32 ML_OPT_MODEL_VERSION_NUM; extern const uint32 RANGE_LIST_DISTRIBUTION_VERSION_NUM; extern const uint32 FIX_SQL_ADD_RELATION_REF_COUNT; extern const uint32 GENERATED_COL_VERSION_NUM; +extern const uint32 ANALYZER_HOOK_VERSION_NUM; #define INPLACE_UPGRADE_PRECOMMIT_VERSION 1 diff --git a/src/include/parser/analyze.h b/src/include/parser/analyze.h index 058e1123f..fbe2b69ea 100644 --- a/src/include/parser/analyze.h +++ b/src/include/parser/analyze.h @@ -84,6 +84,12 @@ typedef struct OperatorPlusProcessContext { bool contain_joinExpr; } OperatorPlusProcessContext; +typedef Query* (*transformSelectStmtHook)(ParseState* pstate, SelectStmt* stmt, bool isFirstNode, bool isCreateView); + +typedef struct AnalyzerRoutine { + transformSelectStmtHook transSelect; +} AnalyzerRoutine; + extern void transformOperatorPlus(ParseState* pstate, Node** whereClause); extern bool IsColumnRefPlusOuterJoin(const ColumnRef* cf); extern PlusJoinRTEItem* makePlusJoinRTEItem(RangeTblEntry* rte, bool hasplus);