patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -20,39 +20,33 @@
#include "lib/utility/ob_print_utils.h"
#include "lib/container/ob_fixed_array.h"
#include "share/schema/ob_schema_struct.h"
#include "sql/plan_cache/ob_param_info.h"
#include "sql/resolver/ob_stmt_type.h"
#include "sql/plan_cache/ob_pc_ref_handle.h"
#include "share/stat/ob_opt_stat_manager.h"
#include "sql/plan_cache/ob_i_lib_cache_object.h"
#include "sql/plan_cache/ob_plan_cache_struct.h"
namespace test {
namespace test
{
class MockCacheObjectFactory;
}
namespace oceanbase {
namespace common {
namespace oceanbase
{
namespace common
{
struct ObExprCtx;
} // namespace common
namespace sql {
namespace sql
{
class ObSqlExpression;
class ObPreCalcExprFrameInfo;
struct ObPreCalcExprFrameInfo;
struct ObPreCalcExprConstraint;
enum ObCacheObjType {
T_CO_SQL_CRSR = 0, // sql physical plan
T_CO_PRCR = 1, // store procedure cache
T_CO_SFC = 2, // store function cache
T_CO_PKG = 3, // store package cache
T_CO_ANON = 4, // anonymous cache
T_CO_MAX
};
struct ObOutlineState {
struct ObOutlineState
{
OB_UNIS_VERSION(1);
public:
ObOutlineState() : outline_version_(), is_plan_fixed_(false)
{}
~ObOutlineState()
{}
ObOutlineState() : outline_version_(), is_plan_fixed_(false) {}
~ObOutlineState(){}
void reset()
{
outline_version_.reset();
@ -60,321 +54,189 @@ public:
}
TO_STRING_KV(K(outline_version_), K(is_plan_fixed_));
share::schema::ObSchemaObjVersion outline_version_;
bool is_plan_fixed_; // whether the plan will be fixed with outline_content
bool is_plan_fixed_;//whether the plan will be fixed with outline_content
};
typedef oceanbase::common::ObFixedArray<common::ObOptTableStatVersion, common::ObIAllocator> TableStatVersions;
typedef oceanbase::common::Ob2DArray<common::ObObjParam, common::OB_MALLOC_BIG_BLOCK_SIZE, common::ObWrapperAllocator,
false>
ParamStore;
struct DeletedCacheObjInfo {
struct AllocCacheObjInfo {
uint64_t obj_id_;
uint64_t tenant_id_;
int64_t log_del_time_;
int64_t real_del_time_;
int64_t ref_count_;
int64_t mem_used_;
bool added_to_pc_;
bool added_to_lc_;
DeletedCacheObjInfo(uint64_t obj_id, uint64_t tenant_id, int64_t log_del_time, int64_t real_del_time,
int64_t ref_count, int64_t mem_used, bool added_to_pc)
AllocCacheObjInfo(uint64_t obj_id, uint64_t tenant_id,
int64_t log_del_time, int64_t real_del_time,
int64_t ref_count, int64_t mem_used, bool added_to_pc)
: obj_id_(obj_id),
tenant_id_(tenant_id),
log_del_time_(log_del_time),
real_del_time_(real_del_time),
ref_count_(ref_count),
mem_used_(mem_used),
added_to_pc_(added_to_pc)
{}
added_to_lc_(added_to_pc) {}
DeletedCacheObjInfo()
: obj_id_(OB_INVALID_ID),
tenant_id_(OB_INVALID_ID),
AllocCacheObjInfo()
: obj_id_(common::OB_INVALID_ID),
tenant_id_(common::OB_INVALID_ID),
log_del_time_(INT64_MAX),
real_del_time_(INT64_MAX),
ref_count_(0),
mem_used_(0),
added_to_pc_(false)
{}
added_to_lc_(false) {}
TO_STRING_KV(
K_(obj_id), K_(tenant_id), K_(log_del_time), K_(real_del_time), K_(ref_count), K_(added_to_pc), K_(mem_used));
TO_STRING_KV(K_(obj_id), K_(tenant_id), K_(log_del_time),
K_(real_del_time), K_(ref_count), K_(added_to_lc),
K_(mem_used));
};
class ObCacheObject {
friend class ObCacheObjectFactory;
friend class ::test::MockCacheObjectFactory;
/**
* @brief The PreCalcPolicy enum
* PRE_CALC_DEFAULT: add frame to phy plan, add result to datum store & param store
* PRE_CALC_CHECK: add nothing to phy plan / datum store & param store
*/
enum PreCalcPolicy {
PRE_CALC_DEFAULT = 0,
PRE_CALC_CHECK = 1 << 0,
};
public:
ObCacheObject(ObCacheObjType co_type, lib::MemoryContext& mem_context = CURRENT_CONTEXT);
virtual ~ObCacheObject()
struct ObParamInfo
{
ObParamInfo()
: scale_(0),
type_(common::ObNullType),
ext_real_type_(common::ObNullType),
is_oracle_empty_string_(false),
col_type_(common::CS_TYPE_INVALID)
{}
virtual ~ObParamInfo() {}
void reset();
TO_STRING_KV(K_(flag),
K_(scale),
K_(type),
K_(ext_real_type),
K_(is_oracle_empty_string),
K_(col_type));
static const int64_t MAX_STR_DES_LEN = 17;
//存放是否需要check type和bool 值,以及期望的bool值
common::ParamFlag flag_;
common::ObScale scale_;
common::ObObjType type_;
common::ObObjType ext_real_type_;
//处理Oracle模式空串在plan_cache中的匹配
bool is_oracle_empty_string_;
common::ObCollationType col_type_;
OB_UNIS_VERSION_V(1);
};
class ObPlanCacheObject : public ObILibCacheObject
{
friend class ::test::MockCacheObjectFactory;
public:
ObPlanCacheObject(ObLibCacheNameSpace ns, lib::MemoryContext &mem_context);
virtual ~ObPlanCacheObject() {}
inline bool is_sql_crsr() const { return ObLibCacheNameSpace::NS_CRSR == ns_; }
inline bool is_prcr() const { return ObLibCacheNameSpace::NS_PRCR == ns_; }
inline bool is_sfc() const { return ObLibCacheNameSpace::NS_SFC == ns_; }
inline bool is_pkg() const { return ObLibCacheNameSpace::NS_PKG == ns_; }
inline bool is_anon() const { return ObLibCacheNameSpace::NS_ANON == ns_; }
inline int64_t get_dependency_table_size() const { return dependency_tables_.count(); }
inline const DependenyTableStore &get_dependency_table() const { return dependency_tables_; }
inline void set_sys_schema_version(int64_t schema_version) { sys_schema_version_ = schema_version; }
inline void set_tenant_schema_version(int64_t schema_version) { tenant_schema_version_ = schema_version; }
inline int64_t get_tenant_schema_version() const { return tenant_schema_version_; }
inline int64_t get_sys_schema_version() const { return sys_schema_version_; }
int init_dependency_table_store(int64_t dependency_table_cnt) { return dependency_tables_.init(dependency_table_cnt); }
inline DependenyTableStore &get_dependency_table() { return dependency_tables_; }
int get_audit_objects(common::ObIArray<share::schema::ObObjectStruct> &object_ids) const;
bool has_sequence() const;
int get_base_table_version(const uint64_t table_id, int64_t &table_version) const;
inline ObOutlineState &get_outline_state() { return outline_state_; }
inline const ObOutlineState &get_outline_state() const { return outline_state_; }
inline void set_outline_state(const ObOutlineState &state) { outline_state_ = state; }
int set_params_info(const ParamStore &params);
const common::Ob2DArray<ObParamInfo,
common::OB_MALLOC_BIG_BLOCK_SIZE,
common::ObWrapperAllocator, false> &get_params_info() const { return params_info_; }
inline void set_is_contain_virtual_table(bool is_contain_virtual_table) { is_contain_virtual_table_ = is_contain_virtual_table; }
inline void set_is_contain_inner_table(bool is_contain_inner_table) { is_contain_inner_table_ = is_contain_inner_table; }
inline bool is_contain_virtual_table() const { return is_contain_virtual_table_; }
inline bool is_contain_inner_table() const { return is_contain_inner_table_; }
virtual void inc_pre_expr_ref_count() {}
virtual void dec_pre_expr_ref_count() {}
virtual int64_t get_pre_expr_ref_count() const {return -1;}
virtual void set_pre_calc_expr_handler(PreCalcExprHandler* handler) {UNUSED(handler);}
virtual PreCalcExprHandler* get_pre_calc_expr_handler(){return NULL;}
inline const common::ObDList<ObPreCalcExprFrameInfo> &get_pre_calc_frames() const
{
return pre_calc_frames_;
}
inline common::ObDList<ObPreCalcExprFrameInfo> &get_pre_calc_frames()
{
return pre_calc_frames_;
}
inline void set_fetch_cur_time(bool fetch_cur_time) { fetch_cur_time_ = fetch_cur_time; }
inline bool get_fetch_cur_time() const { return fetch_cur_time_; }
inline void set_ignore(bool ignore) { is_ignore_stmt_ = ignore; }
inline bool is_ignore() const { return is_ignore_stmt_; }
inline void set_stmt_type(stmt::StmtType stmt_type) { stmt_type_ = stmt_type; }
inline stmt::StmtType get_stmt_type() const { return stmt_type_; }
inline void set_need_param(bool need_param) { need_param_ = need_param; }
inline bool need_param() const { return need_param_; }
static int check_pre_calc_cons(const bool is_ignore_stmt,
bool &is_match,
ObPreCalcExprConstraint &pre_calc_con,
ObExecContext &exec_ctx);
static int pre_calculation(const bool is_ignore_stmt,
ObPreCalcExprFrameInfo &pre_calc_frame,
ObExecContext &exec_ctx,
const uint64_t calc_types = PRE_CALC_DEFAULT);
virtual void reset();
inline ObCacheObjType get_type() const
{
return type_;
}
inline void set_type(ObCacheObjType co_type)
{
type_ = co_type;
}
inline bool is_sql_crsr() const
{
return T_CO_SQL_CRSR == type_;
}
inline bool is_prcr() const
{
return T_CO_PRCR == type_;
}
inline bool is_sfc() const
{
return T_CO_SFC == type_;
}
inline bool is_pkg() const
{
return T_CO_PKG == type_;
}
inline bool is_anon() const
{
return T_CO_ANON == type_;
}
inline uint64_t get_object_id() const
{
return object_id_;
}
inline int64_t get_dependency_table_size() const
{
return dependency_tables_.count();
}
inline const DependenyTableStore& get_dependency_table() const
{
return dependency_tables_;
}
inline void set_sys_schema_version(int64_t schema_version)
{
sys_schema_version_ = schema_version;
}
inline void set_tenant_schema_version(int64_t schema_version)
{
tenant_schema_version_ = schema_version;
}
inline int64_t get_tenant_schema_version() const
{
return tenant_schema_version_;
}
inline int64_t get_sys_schema_version() const
{
return sys_schema_version_;
}
int init_dependency_table_store(int64_t dependency_table_cnt)
{
return dependency_tables_.init(dependency_table_cnt);
}
int add_dependency_table_version(const common::ObIArray<uint64_t>& dependency_ids,
share::schema::ObDependencyTableType table_type, share::schema::ObSchemaGetterGuard& schema_guard);
inline DependenyTableStore& get_dependency_table()
{
return dependency_tables_;
}
inline TableStatVersions& get_table_stat_versions()
{
return table_stat_versions_;
}
inline const TableStatVersions& get_table_stat_versions() const
{
return table_stat_versions_;
}
bool has_sequence() const;
int set_synonym_version(
const common::ObIArray<uint64_t>& dependency_ids, share::schema::ObSchemaGetterGuard& schema_guard);
int get_base_table_version(const uint64_t table_id, int64_t& table_version) const;
inline const ObOutlineState& get_outline_state() const
{
return outline_state_;
}
inline void set_outline_state(const ObOutlineState& state)
{
outline_state_ = state;
}
inline int64_t get_merged_version() const
{
return merged_version_;
}
inline void set_merged_version(int64_t merged_version)
{
merged_version_ = merged_version;
}
int set_params_info(const ParamStore& params);
const common::Ob2DArray<ObParamInfo, common::OB_MALLOC_BIG_BLOCK_SIZE, ObWrapperAllocator, false>& get_params_info()
const
{
return params_info_;
}
inline void set_is_contain_virtual_table(bool is_contain_virtual_table)
{
is_contain_virtual_table_ = is_contain_virtual_table;
}
inline void set_is_contain_inner_table(bool is_contain_inner_table)
{
is_contain_inner_table_ = is_contain_inner_table;
}
inline bool is_contain_virtual_table() const
{
return is_contain_virtual_table_;
}
inline bool is_contain_inner_table() const
{
return is_contain_inner_table_;
}
inline int64_t get_mem_size() const
{
return allocator_.total();
}
int64_t get_ref_count() const
{
return ATOMIC_LOAD(&ref_count_);
}
int64_t inc_ref_count(const CacheRefHandleID ref_handle);
virtual void inc_pre_expr_ref_count()
{}
virtual void dec_pre_expr_ref_count()
{}
virtual int64_t get_pre_expr_ref_count() const
{
return -1;
}
virtual void set_pre_calc_expr_handler(PreCalcExprHandler* handler)
{
UNUSED(handler);
}
virtual PreCalcExprHandler* get_pre_calc_expr_handler()
{
return NULL;
}
inline common::ObIAllocator& get_allocator()
{
return allocator_;
}
inline lib::MemoryContext& get_mem_context()
{
return mem_context_;
}
inline const common::ObDList<ObSqlExpression>& get_pre_calc_exprs() const
{
return pre_calc_exprs_;
}
inline common::ObDList<ObSqlExpression>& get_pre_calc_exprs()
{
return pre_calc_exprs_;
}
inline const common::ObDList<ObPreCalcExprFrameInfo>& get_pre_calc_frames() const
{
return pre_calc_frames_;
}
inline common::ObDList<ObPreCalcExprFrameInfo>& get_pre_calc_frames()
{
return pre_calc_frames_;
}
inline void set_fetch_cur_time(bool fetch_cur_time)
{
fetch_cur_time_ = fetch_cur_time;
}
inline bool get_fetch_cur_time() const
{
return fetch_cur_time_;
}
inline void set_ignore(bool ignore)
{
is_ignore_stmt_ = ignore;
}
inline bool is_ignore() const
{
return is_ignore_stmt_;
}
inline void set_stmt_type(stmt::StmtType stmt_type)
{
stmt_type_ = stmt_type;
}
inline stmt::StmtType get_stmt_type() const
{
return stmt_type_;
}
inline bool added_pc() const
{
return added_to_pc_;
}
inline void set_added_pc(const bool added_to_pc)
{
added_to_pc_ = added_to_pc;
}
inline int64_t get_logical_del_time() const
{
return log_del_time_;
}
inline void set_logical_del_time(const int64_t timestamp)
{
log_del_time_ = timestamp;
}
inline bool should_release(const int64_t safe_timestamp) const
{
// only free leaked cache object
return 0 != get_ref_count() && get_logical_del_time() < safe_timestamp;
}
inline uint64_t get_tenant_id() const
{
return tenant_id_;
}
inline void set_tenant_id(const uint64_t tenant_id)
{
tenant_id_ = tenant_id;
}
static int pre_calculation(const stmt::StmtType& stmt_type, const bool is_ignore_stmt,
const common::ObDList<ObSqlExpression>& pre_calc_exprs, ObExecContext& ctx);
static int pre_calculation(
const bool is_ignore_stmt, ObPreCalcExprFrameInfo& pre_calc_frame, ObExecContext& exec_ctx);
static int type_to_name(const ObCacheObjType type, common::ObIAllocator& allocator, common::ObString& type_name);
void dump_deleted_log_info(const bool is_debug_log = true) const;
VIRTUAL_TO_STRING_KV(K_(type), K_(ref_count), K_(tenant_schema_version), K_(sys_schema_version), K_(merged_version),
K_(object_id), K_(dependency_tables), K_(outline_state), K_(pre_calc_exprs), K_(params_info),
K_(is_contain_virtual_table), K_(is_contain_inner_table), K_(fetch_cur_time));
virtual void dump_deleted_log_info(const bool is_debug_log = true) const;
virtual int check_need_add_cache_obj_stat(ObILibCacheCtx &ctx, bool &need_real_add);
static int type_to_name(const ObLibCacheNameSpace ns,
common::ObIAllocator &allocator,
common::ObString &type_name);
VIRTUAL_TO_STRING_KV(K_(tenant_schema_version),
K_(sys_schema_version),
K_(dependency_tables),
K_(outline_state),
K_(params_info),
K_(is_contain_virtual_table),
K_(is_contain_inner_table),
K_(fetch_cur_time));
protected:
static int construct_array_params(const ObSqlExpression &expr,
common::ObIAllocator &allocator,
common::ObExprCtx &expr_ctx,
common::ObNewRow &row,
common::ObObjParam &result);
protected:
static int construct_array_params(const ObSqlExpression& expr, common::ObIAllocator& allocator,
common::ObExprCtx& expr_ctx, common::ObNewRow& row, common::ObObjParam& result);
private:
int64_t dec_ref_count(const CacheRefHandleID ref_handle);
protected:
lib::MemoryContext mem_context_;
common::ObIAllocator& allocator_;
ObCacheObjType type_;
volatile int64_t ref_count_;
int64_t tenant_schema_version_;
int64_t sys_schema_version_;
int64_t merged_version_;
uint64_t object_id_;
DependenyTableStore dependency_tables_;
TableStatVersions table_stat_versions_;
// for outline use
ObOutlineState outline_state_; // TODO:check this need to be
//for outline use
ObOutlineState outline_state_;//TODO:check this need to be
// store the expressions need to be calculated when plan beginning
common::ObDList<ObSqlExpression> pre_calc_exprs_;
common::ObDList<ObPreCalcExprFrameInfo> pre_calc_frames_;
common::Ob2DArray<ObParamInfo, common::OB_MALLOC_BIG_BLOCK_SIZE, common::ObWrapperAllocator, false> params_info_;
bool is_contain_virtual_table_;
bool is_contain_inner_table_;
//存放参数化后的参数以及可计算表达式的结果值的信息
common::Ob2DArray<ObParamInfo,
common::OB_MALLOC_BIG_BLOCK_SIZE,
common::ObWrapperAllocator, false> params_info_;
bool is_contain_virtual_table_;//为虚拟表服务,如果判断出语句中涉及虚拟表
bool is_contain_inner_table_;//为内部表服务,如果判断出语句中涉及内部表
bool fetch_cur_time_;
bool is_ignore_stmt_;
stmt::StmtType stmt_type_;
int64_t log_del_time_;
bool added_to_pc_;
uint64_t tenant_id_;
bool need_param_;
};
} // namespace sql
} // namespace oceanbase