!2520 MOT new features

Merge pull request !2520 from Vinoth Veeraraghavan/master
This commit is contained in:
opengauss-bot
2022-12-07 12:15:54 +00:00
committed by Gitee
429 changed files with 64994 additions and 27182 deletions

View File

@ -54,7 +54,9 @@ typedef enum {
XACT_EVENT_PREPARE,
XACT_EVENT_COMMIT_PREPARED,
XACT_EVENT_ROLLBACK_PREPARED,
XACT_EVENT_PREROLLBACK_CLEANUP // For MOT, to cleanup some internal resources.
XACT_EVENT_PREROLLBACK_CLEANUP, // For MOT, to cleanup some internal resources.
XACT_EVENT_POST_COMMIT_CLEANUP, // For MOT, to cleanup some dropped function JIT sources.
XACT_EVENT_STMT_FINISH // For MOT, to notify end of statement.
} XactEvent;
typedef void (*XactCallback)(XactEvent event, void* arg);

View File

@ -69,4 +69,8 @@ extern void PlanTreeWalker(
Plan* plan, void (*walker)(Plan*, void*, const char*), void* context, const char* queryString);
extern DatanodeStatement* light_set_datanode_queries(const char* stmt_name);
#ifdef ENABLE_MOT
extern void TryMotJitCodegenQuery(const char* queryString, CachedPlanSource* psrc, Query* query);
#endif
#endif /* PREPARE_H */

View File

@ -22,7 +22,7 @@
// forward declaration
namespace JitExec
{
struct JitContext;
struct MotJitContext;
}
#endif
@ -58,7 +58,7 @@ typedef struct QueryDesc {
struct Instrumentation* totaltime; /* total time spent in ExecutorRun */
bool executed; /* if the query already executed */
#ifdef ENABLE_MOT
JitExec::JitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */
JitExec::MotJitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */
#endif
} QueryDesc;
@ -66,7 +66,7 @@ typedef struct QueryDesc {
#ifdef ENABLE_MOT
extern QueryDesc* CreateQueryDesc(PlannedStmt* plannedstmt, const char* sourceText, Snapshot snapshot,
Snapshot crosscheck_snapshot, DestReceiver* dest, ParamListInfo params, int instrument_options,
JitExec::JitContext* mot_jit_context = nullptr);
JitExec::MotJitContext* motJitContext = nullptr);
#else
extern QueryDesc* CreateQueryDesc(PlannedStmt* plannedstmt, const char* sourceText, Snapshot snapshot,
Snapshot crosscheck_snapshot, DestReceiver* dest, ParamListInfo params, int instrument_options);

View File

@ -1024,7 +1024,7 @@ typedef struct knl_g_archive_context {
#ifdef ENABLE_MOT
typedef struct knl_g_mot_context {
JitExec::JitExecMode jitExecMode;
struct VariableCacheData* shmemVariableCache;
} knl_g_mot_context;
#endif

View File

@ -2568,20 +2568,18 @@ namespace MOT {
}
namespace JitExec {
struct JitContext;
struct MotJitContext;
struct JitContextPool;
}
namespace tvm {
class JitIf;
class JitWhile;
class JitDoWhile;
}
namespace llvm {
namespace llvm_util {
class JitIf;
class JitLoop;
class JitWhile;
class JitDoWhile;
class JitFor;
class JitSwitchCase;
class JitTryCatch;
}
typedef struct knl_u_mot_context {
@ -2596,14 +2594,23 @@ typedef struct knl_u_mot_context {
// JIT
JitExec::JitContextPool* jit_session_context_pool;
uint32_t jit_context_count;
llvm::JitIf* jit_llvm_if_stack;
llvm::JitWhile* jit_llvm_while_stack;
llvm::JitDoWhile* jit_llvm_do_while_stack;
tvm::JitIf* jit_tvm_if_stack;
tvm::JitWhile* jit_tvm_while_stack;
tvm::JitDoWhile* jit_tvm_do_while_stack;
JitExec::JitContext* jit_context;
llvm_util::JitIf* jit_llvm_if_stack;
llvm_util::JitLoop* jit_llvm_loop_stack;
llvm_util::JitWhile* jit_llvm_while_stack;
llvm_util::JitDoWhile* jit_llvm_do_while_stack;
llvm_util::JitFor* jit_llvm_for_stack;
llvm_util::JitSwitchCase* jit_llvm_switch_case_stack;
llvm_util::JitTryCatch* jit_llvm_try_catch_stack;
JitExec::MotJitContext* jit_context;
MOT::TxnManager* jit_txn;
int jit_compile_depth;
int jit_parse_error;
void* jit_pg_query;
void* jit_ns_stack;
void* jit_session_source_map;
bool jit_xact_callback_registered;
int jit_codegen_error;
} knl_u_mot_context;
#endif
@ -2878,6 +2885,10 @@ extern bool enable_out_param_override();
extern THR_LOCAL knl_session_context* u_sess;
#ifdef ENABLE_MOT
extern void knl_u_mot_init(knl_u_mot_context* mot_cxt);
#endif
inline bool stp_disable_xact_and_set_err_msg(bool *save_commit_rollback_state, stp_xact_err_type type)
{
*save_commit_rollback_state = u_sess->SPI_cxt.is_allow_commit_rollback;

View File

@ -36,7 +36,7 @@
// forward declaration for MOT JitContext
namespace JitExec
{
struct JitContext;
struct MotJitContext;
}
#endif
@ -653,7 +653,7 @@ typedef struct EState {
bool isRowTriggerShippable; /* true if all row triggers are shippable. */
#ifdef ENABLE_MOT
JitExec::JitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */
JitExec::MotJitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */
#endif
PruningResult* pruningResult;

View File

@ -397,6 +397,10 @@ typedef enum NodeTag {
T_SelectIntoVarList,
T_AlterTableStmt,
T_AlterTableCmd,
#ifdef ENABLE_MOT
T_AlterForeingTableCmd,
T_RenameForeingTableCmd,
#endif
T_AlterDomainStmt,
T_SetOperationStmt,
T_GrantStmt,

View File

@ -963,6 +963,26 @@ typedef struct CreateForeignTableStmt {
ForeignPartState* part_state;
} CreateForeignTableStmt;
#ifdef ENABLE_MOT
typedef struct AlterForeingTableCmd {
NodeTag type;
AlterTableType subtype;
Relation rel;
const char* name;
Node* def;
Oid colTypeOid;
Expr* defValue;
} AlterForeingTableCmd;
typedef struct RenameForeingTableCmd {
NodeTag type;
Oid relid;
ObjectType renameType;
char* oldname;
char* newname;
} RenameForeingTableCmd;
#endif
/* ----------------------
* Create/Drop USER MAPPING Statements
* ----------------------

View File

@ -30,28 +30,38 @@
#ifdef ENABLE_MOT
class MotJitSelectFusion : public OpFusion {
public:
MotJitSelectFusion(MemoryContext context, CachedPlanSource *psrc, List *plantree_list, ParamListInfo params);
MotJitSelectFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params);
~MotJitSelectFusion() {};
~MotJitSelectFusion()
{}
bool execute(long max_rows, char *completionTag);
bool execute(long max_rows, char* completionTag);
void InitLocals(ParamListInfo params);
void InitGlobals();
private:
struct MotJitSelectFusionGlobalVariable {
int64 m_limitCount;
int64 m_limitOffset;
};
MotJitSelectFusionGlobalVariable* m_c_global;
};
class MotJitModifyFusion : public OpFusion {
public:
MotJitModifyFusion(MemoryContext context, CachedPlanSource *psrc, List *plantree_list, ParamListInfo params);
MotJitModifyFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params);
~MotJitModifyFusion() {};
~MotJitModifyFusion()
{}
bool execute(long max_rows, char *completionTag);
bool execute(long max_rows, char* completionTag);
void InitLocals(ParamListInfo params);
void InitGlobals();
private:
struct MotJitModifyFusionLocaleVariable {
CmdType m_cmdType;

View File

@ -46,7 +46,6 @@ extern void applyLockingClause(Query* qry, Index rtindex, LockClauseStrength str
int waitSec);
#ifdef ENABLE_MOT
extern void CheckTablesStorageEngine(Query* qry, StorageEngineType* type);
extern bool CheckMotIndexedColumnUpdate(Query* qry);
typedef struct RTEDetectorContext {
bool isMotTable;
@ -54,12 +53,6 @@ typedef struct RTEDetectorContext {
List* queryNodes;
int sublevelsUp;
} RTEDetectorContext;
typedef struct UpdateDetectorContext {
bool isIndexedColumnUpdate;
List* queryNodes;
int sublevelsUp;
} UpdateDetectorContext;
#endif
/* Record the rel name and corresponding columan name info */

View File

@ -2358,6 +2358,8 @@ extern void getSessionID(char* sessid, pg_time_t startTime, ThreadId Threadid);
extern void getThrdID(char* thrdid, pg_time_t startTime, ThreadId Threadid);
#define NUM_MOT_SESSION_MEMORY_DETAIL_ELEM 4
#define NUM_MOT_JIT_DETAIL_ELEM 11
#define NUM_MOT_JIT_PROFILE_ELEM 12
typedef struct MotSessionMemoryDetail {
ThreadId threadid;
@ -2383,8 +2385,39 @@ typedef struct MotMemoryDetailPad {
MotMemoryDetail* memoryDetail;
} MotMemoryDetailPad;
typedef struct MotJitDetail {
Oid procOid;
char* query;
char* nameSpace;
char* jittableStatus;
char* validStatus;
TimestampTz lastUpdatedTimestamp;
char* planType;
int64 codegenTime;
int64 verifyTime;
int64 finalizeTime;
int64 compileTime;
} MotJitDetail;
typedef struct MotJitProfile {
Oid procOid;
int32 id;
int32 parentId;
char* query;
char* nameSpace;
float4 weight;
int64 totalTime;
int64 selfTime;
int64 childGrossTime;
int64 childNetTime;
int64 defVarsTime;
int64 initVarsTime;
} MotJitProfile;
extern MotSessionMemoryDetail* GetMotSessionMemoryDetail(uint32* num);
extern MotMemoryDetail* GetMotMemoryDetail(uint32* num, bool isGlobal);
extern MotJitDetail* GetMotJitDetail(uint32* num);
extern MotJitProfile* GetMotJitProfile(uint32* num);
#ifdef MEMORY_CONTEXT_CHECKING
typedef enum { STANDARD_DUMP, SHARED_DUMP } DUMP_TYPE;

View File

@ -27,37 +27,93 @@
#include <stdint.h>
/*---------------------- Generic Constants -------------------*/
/** @define Impose a hard coded limit on depth of parsed expression. */
#define MOT_JIT_MAX_EXPR_DEPTH 10
/** @define We support up to 8 arguments for NULL management in expressions. */
#define MOT_JIT_EXPR_ARG_COUNT 8
/** @define The maximum number of registers used in a pseudo-function execution. */
#define MOT_JIT_MAX_FUNC_REGISTERS 4096
/** @define The maximum number of arguments in a Boolean expression. */
#define MOT_JIT_MAX_BOOL_EXPR_ARGS 2
/** @define The maximum number of arguments in a function call expression. */
#define MOT_JIT_MAX_FUNC_EXPR_ARGS 3
/** @define The global query name-space name. */
#define MOT_JIT_GLOBAL_QUERY_NS "GLOBAL"
/** @define The maximum nesting level of compiled stored procedures. */
#define MOT_JIT_MAX_COMPILE_DEPTH 10
/** @define The maximum nesting level of compiled stored procedure blocks. */
#define MOT_JIT_MAX_BLOCK_DEPTH 10
/*---------------------- Optional Compile-Time Configuration -------------------*/
/*
* To enable generating JIT code for full-scan queries, #define MOT_JIT_FULL_SCAN
*/
/*
* To debug JIT execution, #define MOT_JIT_DEBUG
*/
/*
* To enable features required for JIT testing, #define MOT_JIT_TEST
*/
/** @define Enable advanced WHERE clause operators (comment to disable). */
#define MOT_JIT_ADVANCED_WHERE_OP
/*---------------------- JIT Parse Errors -------------------*/
/** @define JIT encountered generic parsing error. */
#define MOT_JIT_GENERIC_PARSE_ERROR 1
/** @define JIT encountered "table not found" error. */
#define MOT_JIT_TABLE_NOT_FOUND 2
/*---------------------- JIT Profiler Constants -------------------*/
/** @define Invalid profile function identifier. */
#define MOT_JIT_PROFILE_INVALID_FUNCTION_ID ((uint32_t)-1)
/** @define Invalid profile region identifier. */
#define MOT_JIT_PROFILE_INVALID_REGION_ID ((uint32_t)-1)
/** @define The predefined "total" profile region. */
#define MOT_JIT_PROFILE_REGION_TOTAL "total"
/** @define The predefined "def-vars" profile region. */
#define MOT_JIT_PROFILE_REGION_DEF_VARS "def-vars"
/** @define The predefined "init-vars" profile region. */
#define MOT_JIT_PROFILE_REGION_INIT_VARS "init-vars"
/** @define The predefined "child-call" profile region. */
#define MOT_JIT_PROFILE_REGION_CHILD_CALL "child-call"
namespace JitExec {
/** @enum JIT context state constants. */
enum JitContextState : uint8_t {
/** @var Denotes initial context state.*/
JIT_CONTEXT_STATE_INIT,
// To debug JIT execution, #define MOT_JIT_DEBUG
// To use advanced WHERE clause operators, #define MOT_JIT_ADVANCED_WHERE_OP
// To enable features required for JIT testing, #define MOT_JIT_TEST
/** @var Denotes JIT context is ready for use. */
JIT_CONTEXT_STATE_READY,
/** @enum JIT execution mode constants. */
enum JitExecMode : uint32_t {
/** @var Invalid execution mode. */
JIT_EXEC_MODE_INVALID,
/** @var Denotes JIT context is pending compilation to finish. */
JIT_CONTEXT_STATE_PENDING,
/** @var LLVM execution mode. */
JIT_EXEC_MODE_LLVM,
/** @var Denotes JIT context finished compilation successfully. */
JIT_CONTEXT_STATE_DONE,
/** @var TVM execution mode. */
JIT_EXEC_MODE_TVM
/** @var Denotes JIT context is invalid and needs revalidation. */
JIT_CONTEXT_STATE_INVALID,
/** @var Denotes JIT context revalidation or compilation failed. */
JIT_CONTEXT_STATE_ERROR,
/** @var Denotes final context state. */
JIT_CONTEXT_STATE_FINAL
};
/** @enum JitCommandType Command types supported by jitted queries. */
@ -83,6 +139,9 @@ enum JitCommandType : uint8_t {
/** @var Unordered range select command. */
JIT_COMMAND_RANGE_SELECT,
/** @var Range delete command. */
JIT_COMMAND_RANGE_DELETE,
/** @var Unordered full-scan select command. */
JIT_COMMAND_FULL_SELECT,
@ -99,7 +158,13 @@ enum JitCommandType : uint8_t {
JIT_COMMAND_AGGREGATE_JOIN,
/** @var Compound select command (point-select with sub-queries). */
JIT_COMMAND_COMPOUND_SELECT
JIT_COMMAND_COMPOUND_SELECT,
/** @var Function (stored-procedure) execution command. */
JIT_COMMAND_FUNCTION,
/** @var Invoke stored-procedure command. */
JIT_COMMAND_INVOKE
};
/** @enum JIT context usage constants. */
@ -107,10 +172,57 @@ enum JitContextUsage : uint8_t {
/** @var JIT context is used in global context. */
JIT_CONTEXT_GLOBAL,
/** @var JIT context is used in global context (but not as the primary stencil). */
JIT_CONTEXT_GLOBAL_SECONDARY,
/** @var JIT context is used in session-local context. */
JIT_CONTEXT_LOCAL
};
/** @enum JIT purge scope constants. */
enum JitPurgeScope {
/** @var Denotes that JIT query source objects are directly affected by the purge action. */
JIT_PURGE_SCOPE_QUERY,
/** @var Denotes that JIT stored procedure source objects are directly affected by the purge action. */
JIT_PURGE_SCOPE_SP
};
/** @enum JIT purge action constants. */
enum JitPurgeAction {
/** @var Denotes purge-only action. */
JIT_PURGE_ONLY,
/** @var Denotes purge and set-as-expired action. */
JIT_PURGE_EXPIRE,
/** @var Denotes purge and set-as-replaced action (stored procedures only). */
JIT_PURGE_REPLACE
};
/** @brief Helper function to determine whether JIT context usage is global. */
inline bool IsJitContextUsageGlobal(JitContextUsage usage)
{
return ((usage == JIT_CONTEXT_GLOBAL) || (usage == JIT_CONTEXT_GLOBAL_SECONDARY));
}
inline const char* JitContextUsageToString(JitContextUsage usage)
{
return (usage == JIT_CONTEXT_GLOBAL)
? "global"
: ((usage == JIT_CONTEXT_GLOBAL_SECONDARY) ? "secondary-global" : "session-local");
}
inline const char* JitPurgeScopeToString(JitPurgeScope purgeScope)
{
return (purgeScope == JIT_PURGE_SCOPE_QUERY) ? "query" : "sp";
}
inline const char* JitPurgeActionToString(JitPurgeAction purgeAction)
{
return (purgeAction == JIT_PURGE_ONLY) ? "purge" : ((purgeAction == JIT_PURGE_EXPIRE) ? "expire" : "replace");
}
/** @enum Constants for classifying operators in WHERE clause. */
enum JitWhereOperatorClass : uint8_t {
/** @var Invalid where operator class. */

View File

@ -29,13 +29,15 @@
#include "nodes/params.h"
#include "executor/tuptable.h"
#include "nodes/parsenodes.h"
#include "nodes/execnodes.h"
#include "pgstat.h"
#include "jit_def.h"
namespace JitExec {
// forward declaration
struct JitContext;
struct MotJitContext;
struct JitContextPool;
struct JitPlan;
@ -48,8 +50,11 @@ extern void JitDestroy();
/** @brief Queries whether MOT JIT compilation and execution is enabled. */
extern bool IsMotCodegenEnabled();
/** @brief Quereis whether pseudo-LLVM is forced on platforms where LLVM is natively supported. */
extern bool IsMotPseudoCodegenForced();
/** @brief Queries whether MOT JIT compilation and execution of prepared queries is enabled. */
extern bool IsMotQueryCodegenEnabled();
/** @brief Queries whether MOT JIT compilation and execution of stored procedures is enabled. */
extern bool IsMotSPCodegenEnabled();
/** @brief Queries whether informative printing is enabled for MOT JIT compilation. */
extern bool IsMotCodegenPrintEnabled();
@ -61,21 +66,57 @@ extern uint32_t GetMotCodegenLimit();
* @brief Queries whether a SQL query to be executed by MM Engine is jittable.
* @param query The parsed SQL query to examine.
* @param queryString The query text.
* @return The JIT plan if the query is jittable, otherwise NULL.
* @param forcePlan[opt] Specifies whether to force plan generation, even if a JIT source exists.
* @return The JIT plan if the query is jittable, otherwise null.
*/
extern JitPlan* IsJittable(Query* query, const char* queryString);
extern JitPlan* IsJittableQuery(Query* query, const char* queryString, bool forcePlan = false);
/**
* @brief Queries whether a stored procedure to be executed by MM Engine is jittable.
* @param procTuple The stored procedure entry in the system catalog.
* @param functionOid The function identifier.
* @param forcePlan[opt] Specifies whether to force plan generation, even if a JIT source exists.
* @return The JIT plan if the stored procedure is jittable, otherwise null.
*/
extern JitPlan* IsJittableFunction(
PLpgSQL_function* function, HeapTuple procTuple, Oid functionOid, bool forcePlan = false);
/** @brief Queries whether this is an invoke query that invokes an already jitted stored procedure. */
extern bool IsInvokeReadyFunction(Query* query);
/**
* @brief Generate jitted code for a query.
* @param query The parsed SQL query for which jitted code is to be generated.
* @param queryString The query text.
* @param jitPlan The JIT plan produced during the call to @ref IsJittable().
* @param The required resulting context usage.
* @return The context of the jitted code required for later execution.
*/
extern JitContext* JitCodegenQuery(Query* query, const char* queryString, JitPlan* jitPlan);
extern MotJitContext* JitCodegenQuery(Query* query, const char* queryString, JitPlan* jitPlan, JitContextUsage usage);
/**
* @brief Utility helper for generating jitted code for a query. It packs together the calls for @ref IsJittableQuery
* and @ref JitCodegenQuery.
* @param query The parsed SQL query for which jitted code is to be generated.
* @param queryString The query text.
* @return The context of the jitted code required for later execution.
*/
extern MotJitContext* TryJitCodegenQuery(Query* query, const char* queryString);
/**
* @brief Generate jitted code for a stored procedure.
* @param function The parsed stored procedure.
* @param procTuple The stored procedure entry in the system catalog.
* @param functionOid The function identifier.
* @param returnSetInfo Return set information for the function (required during parsing).
* @param jitPlan The JIT plan produced during the call to @ref IsJittable().
* @return The context of the jitted code required for later execution.
*/
extern MotJitContext* JitCodegenFunction(PLpgSQL_function* function, HeapTuple procTuple, Oid functionOid,
ReturnSetInfo* returnSetInfo, JitPlan* jitPlan, JitContextUsage usage);
/** @brief Resets the scan iteration counter for the JIT context. */
extern void JitResetScan(JitContext* jitContext);
extern void JitResetScan(MotJitContext* jitContext);
/**
* @brief Executed a previously jitted query.
@ -88,26 +129,108 @@ extern void JitResetScan(JitContext* jitContext);
* @note This function may cause transaction abort.
*/
extern int JitExecQuery(
JitContext* jitContext, ParamListInfo params, TupleTableSlot* slot, uint64_t* tuplesProcessed, int* scanEnded);
MotJitContext* jitContext, ParamListInfo params, TupleTableSlot* slot, uint64_t* tuplesProcessed, int* scanEnded);
/**
* @brief Purges the global cache of JIT source stencils from all entries that refer the given relation id.
* @param relationId The external identifier of the relation to be purged.
* @param purgeOnly Specifies whether to just purge all keys/indexes referring to the given relation, or should the JIT
* context also be set as expired (which triggers re-compilation of the JIT function).
* @brief Executed a previously jitted stored procedure.
* @param jitContext The context produced by a previous call to @ref JitCodegenFunction().
* @param params The list of bound parameters passed to the query.
* @param[out] slot The slot used for reporting select result.
* @param[out] tuplesProcessed The variable used to report the number of processed tuples.
* @param[out] scanEnded The variable used to report if a range scan ended.
* @return Zero if succeeded, otherwise an error code.
* @note This function may cause transaction abort.
*/
extern void PurgeJitSourceCache(uint64_t relationId, bool purgeOnly);
extern int JitExecFunction(
MotJitContext* jitContext, ParamListInfo params, TupleTableSlot* slot, uint64_t* tuplesProcessed, int* scanEnded);
/**
* @brief Purges the global cache of JIT source stencils from all entries that refer the given relation or stored
* procedure id.
* @param objectId The external identifier of the relation or stored procedure that triggers the purge.
* @param purgeScope The directly affected JIT source objects. In case of JIT query source, then the object identifier
* parameter denotes a relation id, otherwise it denotes a stored procedure id.
* @param purgeAction Specifies whether to just purge all keys/indexes referring to the given relation, or should the
* JIT context also be set as expired (which triggers re-compilation of the JIT function on sub-sequent access).
* @param funcName The stored procedure name (applicable only if purgeScope is JIT_PURGE_SCOPE_SP).
*/
extern void PurgeJitSourceCache(
uint64_t objectId, JitPurgeScope purgeScope, JitPurgeAction purgeAction, const char* funcName);
/**
* @brief Re-Generate JIT code for all invalidated sub-queries of a stored procedure.
* @param jitContext The context produced by a previous call to @ref JitCodegenFunction().
* @return True if operations succeeded, otherwise false.
*/
extern bool JitReCodegenFunctionQueries(MotJitContext* jitContext);
// externalize functions defined elsewhere
/** @brief Destroys a jit context produced by a previous call to JitCodegenQuery. */
extern void DestroyJitContext(JitContext* jitContext);
/** @brief Forces JIT context full invalidation (purge and invalidate). */
extern void ForceJitContextInvalidation(MotJitContext* jitContext);
/** @brief De-allocates a jit context pool for a specific session. */
/** @brief Queries whether a JIT context is valid. */
extern bool IsJitContextValid(MotJitContext* jitContext);
/** @brief Queries whether a JIT context is a sub-context. */
extern bool IsJitSubContext(MotJitContext* jitContext);
/** @brief Trigger code-generation of any missing sub-query. */
extern bool TryRevalidateJitContext(MotJitContext* jitContext, TransactionId functionTxnId = InvalidTransactionId);
/** @brief Queries whether this context is still waiting for source compilation to finish. */
extern bool IsJitContextPendingCompile(MotJitContext* jitContext);
/** @brief Queries whether this context is done waiting for source compilation to finish. */
extern bool IsJitContextDoneCompile(MotJitContext* jitContext);
/** @brief Queries whether this compilation for this context finished with error. */
extern bool IsJitContextErrorCompile(MotJitContext* jitContext);
/** @brief Queries current JIT context compile state. Returns true if any of the 3 possible states is true.*/
extern bool GetJitContextCompileState(MotJitContext* jitContext, bool* isPending, bool* isDone, bool* isError);
/** @brief Updates and retrieves the current context state. */
extern JitContextState GetJitContextState(MotJitContext* jitContext);
/**
* @brief Returns a JIT context back to its source pool.
* @param jitContext The JIT context to free.
*/
extern void FreeJitContext(MotJitContext* jitContext);
/**
* @brief Destroys a JIT context produced by a previous call to JitCodegenQuery.
* @detail All internal resources associated with the context object are released, and the context
* is returned to its source context pool.
* @param jitContext The JIT context to destroy.
* @param[optional] isDropCachedPlan Specifies whether this is from DropCachedPlan (deallocate prepared statement).
*/
extern void DestroyJitContext(MotJitContext* jitContext, bool isDropCachedPlan = false);
/** @brief De-allocates a JIT context pool for a specific session. */
extern void FreeSessionJitContextPool(JitContextPool* jitContextPool);
/** @brief Releases all resources associated with a plan.*/
/**
* @brief Releases all resources associated with a plan.
* @param plan The plan to destroy.
*/
extern void JitDestroyPlan(JitPlan* plan);
/** @brief Get JIT global status.*/
extern MotJitDetail* MOTGetJitDetail(uint32_t* num);
/** @brief Get JIT profile data. */
extern MotJitProfile* MOTGetJitProfile(uint32_t* num);
/** @brief Reports sub-query parse error. */
extern void JitReportParseError(ErrorData* edata, const char* queryString);
/** @brief Cleans up all resource associated with JIT transactional behavior. */
extern void CleanupJitSourceTxnState();
/** @brief Queries whether this is an invoke query plan. */
extern bool IsInvokeQueryPlan(CachedPlanSource* planSource, Oid* functionOid, TransactionId* functionTxnId);
} // namespace JitExec
#endif // JIT_EXEC_H

View File

@ -26,6 +26,7 @@
#ifndef MOT_FDW_H
#define MOT_FDW_H
#include <stddef.h>
#include <stdint.h>
/** @brief Initializes MOT engine. */
@ -82,4 +83,14 @@ extern void MOTCheckpointFetchUnlock();
extern bool MOTCheckpointExists(
char* ctrlFilePath, size_t ctrlLen, char* checkpointDir, size_t checkpointLen, size_t& basePathLen);
/**
* The following helpers APIs are used for validating MOT GUC parameters.
*/
extern bool MOTValidateLogLevel(const char* logLevelStr);
extern bool MOTValidateAffinityMode(const char* affinityModeStr);
extern bool MOTValidateMemReserveMode(const char* reserveModeStr);
extern bool MOTValidateMemStorePolicy(const char* storePolicyStr);
extern bool MOTValidateMemAllocPolicy(const char* allocPolicyStr);
extern void MOTCheckTransactionAborted();
#endif // MOT_FDW_H

View File

@ -1750,6 +1750,8 @@ extern Datum hypopg_reset_index(PG_FUNCTION_ARGS);
extern Datum mot_global_memory_detail(PG_FUNCTION_ARGS);
extern Datum mot_local_memory_detail(PG_FUNCTION_ARGS);
extern Datum mot_session_memory_detail(PG_FUNCTION_ARGS);
extern Datum mot_jit_detail(PG_FUNCTION_ARGS);
extern Datum mot_jit_profile(PG_FUNCTION_ARGS);
/* UBtree index */
Datum gs_index_verify(PG_FUNCTION_ARGS);

View File

@ -378,7 +378,6 @@ private:
void FreeDeadCts();
void HandleDeadGlobalCatCTup(GlobalCatCTup *ct);
void RemoveTailTupleElements(Index hash_index);
void InvalidLSC(uint32 hash_value);
void FreeDeadCls();
void HandleDeadGlobalCatCList(GlobalCatCList *cl);

View File

@ -28,7 +28,7 @@
// forward declaration for MOT JitContext
namespace JitExec
{
struct JitContext;
struct MotJitContext;
}
#endif
@ -376,7 +376,8 @@ typedef struct CachedPlanSource {
bool is_oneshot; /* is it a "oneshot" plan? */
#ifdef ENABLE_MOT
StorageEngineType storageEngineType; /* which storage engine is used*/
JitExec::JitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */
bool checkedMotJitCodegen;
JitExec::MotJitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */
#endif
int generation; /* increments each time we create a plan */
/* If CachedPlanSource has been saved, it is a member of a global list */
@ -432,7 +433,7 @@ typedef struct CachedPlan {
#ifdef ENABLE_MOT
StorageEngineType storageEngineType; /* which storage engine is used*/
JitExec::JitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */
JitExec::MotJitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */
#endif
bool dependsOnRole; /* is plan specific to that role? */

View File

@ -1661,6 +1661,9 @@ extern void exec_eval_datum(PLpgSQL_execstate *estate,
bool *isnull,
bool isretry);
extern void exec_eval_cleanup(PLpgSQL_execstate *estate);
extern void plpgsql_estate_setup(PLpgSQL_execstate* estate, PLpgSQL_function* func, ReturnSetInfo* rsi);
extern void plpgsql_destroy_econtext(PLpgSQL_execstate* estate);
extern PLpgSQL_datum* copy_plpgsql_datum(PLpgSQL_datum* datum);
extern void free_expr(PLpgSQL_expr* expr);
extern void free_assignlist(List* assignlist);
extern HeapTuple make_tuple_from_row(PLpgSQL_execstate* estate, PLpgSQL_row* row, TupleDesc tupdesc);
@ -1669,6 +1672,9 @@ extern int getTableOfIndexByDatumValue(TableOfIndexKey key, HTAB* tableOfIndex,
extern Datum fillNestedTableArray(ArrayType* arrayval, Oid parenttypoid, Oid elemtypoid, int value, int idx);
extern int plpgsql_estate_adddatum(PLpgSQL_execstate* estate, PLpgSQL_datum* newm);
extern void CheckCurrCompileDependOnPackage(Oid pkgOid);
extern bool needRecompilePlan(SPIPlanPtr plan);
extern void plpgsql_param_fetch(ParamListInfo params, int paramid);
extern Datum pl_coerce_type_typmod(Datum value, Oid targetTypeId, int32 targetTypMod);
#ifndef ENABLE_MULTIPLE_NODES
extern void estate_cursor_set(FormatCallStack* plcallstack);
#endif