Add analyzer hook.

This commit is contained in:
TotaJ
2021-08-27 10:24:41 +08:00
parent 079e63b7f6
commit 820483885a
6 changed files with 33 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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