From eed677c16e15f6146c5fce31e47fd16904bfd1df Mon Sep 17 00:00:00 2001 From: 0xacc Date: Tue, 9 Apr 2024 12:38:43 +0000 Subject: [PATCH] [to #53391711] patch persist PL compile result from 4_2_x_release to master --- deps/oblib/src/lib/oblog/ob_log_module.h | 6 +- src/objit/include/objit/ob_llvm_helper.h | 7 +- src/objit/src/core/ob_orc_jit.cpp | 18 +- src/objit/src/core/ob_orc_jit.h | 11 +- src/objit/src/ob_llvm_helper.cpp | 15 + src/pl/CMakeLists.txt | 1 + src/pl/ob_pl.cpp | 35 +- src/pl/ob_pl.h | 2 + src/pl/ob_pl_code_generator.cpp | 121 ++-- src/pl/ob_pl_code_generator.h | 19 +- src/pl/ob_pl_compile.cpp | 103 ++- src/pl/ob_pl_compile.h | 6 +- src/pl/ob_pl_persistent.cpp | 598 ++++++++++++++++++ src/pl/ob_pl_persistent.h | 147 +++++ src/pl/ob_pl_resolver.cpp | 4 + src/pl/pl_cache/ob_pl_cache_mgr.cpp | 8 +- src/rootserver/ob_ddl_operator.cpp | 30 +- .../ob_inner_table_schema.451_500.cpp | 186 ++++++ .../ob_inner_table_schema.50451_50500.cpp | 135 ++++ .../ob_inner_table_schema.60451_60500.cpp | 90 +++ src/share/inner_table/ob_inner_table_schema.h | 24 +- .../inner_table/ob_inner_table_schema.lob.cpp | 2 +- .../ob_inner_table_schema_constants.h | 6 + .../inner_table/ob_inner_table_schema_def.py | 22 +- src/share/inner_table/table_id_to_name | 1 + src/share/parameter/ob_parameter_seed.ipp | 4 + src/sql/ob_spi.cpp | 310 +++++++-- src/sql/ob_spi.h | 85 ++- .../cmd/ob_call_procedure_resolver.cpp | 5 +- src/sql/session/ob_basic_session_info.cpp | 6 + src/sql/session/ob_basic_session_info.h | 12 + .../r/mysql/information_schema.result | 14 + .../all_virtual_sys_parameter_stat.result | 1 + .../r/mysql/inner_table_overall.result | 1 + 34 files changed, 1848 insertions(+), 187 deletions(-) create mode 100644 src/pl/ob_pl_persistent.cpp create mode 100644 src/pl/ob_pl_persistent.h diff --git a/deps/oblib/src/lib/oblog/ob_log_module.h b/deps/oblib/src/lib/oblog/ob_log_module.h index 6baf858f17..49f51cbf08 100644 --- a/deps/oblib/src/lib/oblog/ob_log_module.h +++ b/deps/oblib/src/lib/oblog/ob_log_module.h @@ -241,6 +241,7 @@ DEFINE_LOG_SUB_MOD(PACK) // package DEFINE_LOG_SUB_MOD(TYPE) // type DEFINE_LOG_SUB_MOD(DEBUG) // debug DEFINE_LOG_SUB_MOD(CACHE) // cache +DEFINE_LOG_SUB_MOD(STORAGEROUTINE) // storage routine LOG_MOD_END(PL) } //namespace common @@ -628,7 +629,10 @@ LOG_MOD_END(PL) info_string, ##args) #define _PL_CACHE_LOG(level, _fmt_, args...) _OB_SUB_MOD_LOG(PL, CACHE, level, \ _fmt_, ##args) - +#define PL_STORAGEROUTINE_LOG(level, info_string, args...) OB_SUB_MOD_LOG(PL, STORAGEROUTINE, level, \ + info_string, ##args) +#define _PL_STORAGEROUTINE_LOG(level, _fmt_, args...) _OB_SUB_MOD_LOG(PL, STORAGEROUTINE, level, \ + _fmt_, ##args) #define RPC_FRAME_LOG(level, _fmt_, args...) \ OB_SUB_MOD_LOG(RPC, FRAME, level, _fmt_, ##args) diff --git a/src/objit/include/objit/ob_llvm_helper.h b/src/objit/include/objit/ob_llvm_helper.h index d916242884..7bd520e4c6 100644 --- a/src/objit/include/objit/ob_llvm_helper.h +++ b/src/objit/include/objit/ob_llvm_helper.h @@ -18,6 +18,7 @@ #include "lib/container/ob_fast_array.h" #include "lib/string/ob_string.h" #include "common/object/ob_object.h" +#include "share/rc/ob_tenant_base.h" namespace llvm { @@ -353,7 +354,7 @@ public: ObLLVMHelper(common::ObIAllocator &allocator) : allocator_(allocator), jc_(NULL), - jit_(NULL){} + jit_(NULL) {} virtual ~ObLLVMHelper(); int init(); void final(); @@ -368,6 +369,10 @@ public: ObDIRawData get_debug_info() const; + const ObString &get_compiled_object(); + + int add_compiled_object(size_t length, const char *ptr); + public: //指令 int create_br(const ObLLVMBasicBlock &dest); diff --git a/src/objit/src/core/ob_orc_jit.cpp b/src/objit/src/core/ob_orc_jit.cpp index 94dc0ce854..8b0ca4b734 100644 --- a/src/objit/src/core/ob_orc_jit.cpp +++ b/src/objit/src/core/ob_orc_jit.cpp @@ -61,7 +61,7 @@ ObOrcJit::ObOrcJit(common::ObIAllocator &Allocator) : DebugBuf(nullptr), DebugLen(0), JITAllocator(), - NotifyLoaded(Allocator, DebugBuf, DebugLen), + NotifyLoaded(Allocator, DebugBuf, DebugLen, SoObject), TheContext(), ObResolver(createLegacyLookupResolver( ObES, @@ -148,6 +148,11 @@ void ObNotifyLoaded::operator()( const object::ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &Info) { + char *obj_buf = static_cast(Allocator.alloc(Obj.getData().size())); + if (OB_NOT_NULL(obj_buf)) { + MEMCPY(obj_buf, Obj.getData().data(), Obj.getData().size()); + SoObject.assign_ptr(obj_buf, Obj.getData().size()); + } // object::ObjectFile *ObjBinary = Obj.getBinary(); // if (ObjBinary != nullptr) { object::OwningBinary DebugObj = Info.getObjectForDebug(Obj); @@ -164,6 +169,15 @@ void ObNotifyLoaded::operator()( // } } -} // core +void ObOrcJit::add_compiled_object(size_t length, const char *ptr) +{ + ObVModuleKey Key = ObES.allocateVModule(); + + cantFail(ObObjectLayer.addObject( + Key, MemoryBuffer::getMemBuffer(StringRef(ptr, length), "", false))); + ObModuleKeys.push_back(Key); +} + +} // namespace core } // objit } // oceanbase diff --git a/src/objit/src/core/ob_orc_jit.h b/src/objit/src/core/ob_orc_jit.h index 564782ccd3..4667cf2699 100644 --- a/src/objit/src/core/ob_orc_jit.h +++ b/src/objit/src/core/ob_orc_jit.h @@ -46,8 +46,8 @@ class ObNotifyLoaded { public: explicit ObNotifyLoaded( - common::ObIAllocator &Allocator, char *&DebugBuf, int64_t &DebugLen) - : Allocator(Allocator), DebugBuf(DebugBuf), DebugLen(DebugLen) {} + common::ObIAllocator &Allocator, char *&DebugBuf, int64_t &DebugLen, ObString &SoObject) + : Allocator(Allocator), DebugBuf(DebugBuf), DebugLen(DebugLen), SoObject(SoObject) {} virtual ~ObNotifyLoaded() {} void operator()(ObVModuleKey Key, @@ -57,6 +57,7 @@ private: common::ObIAllocator &Allocator; char* &DebugBuf; int64_t &DebugLen; + ObString &SoObject; }; @@ -80,6 +81,10 @@ public: char* get_debug_info_data() { return DebugBuf; } int64_t get_debug_info_size() { return DebugLen; } + void add_compiled_object(size_t length, const char *ptr); + + const ObString& get_compiled_object() const { return SoObject; } + private: std::string mangle(const std::string &Name) { @@ -119,6 +124,8 @@ private: ObObjLayerT ObObjectLayer; ObCompileLayerT ObCompileLayer; std::vector ObModuleKeys; + + ObString SoObject; }; #else diff --git a/src/objit/src/ob_llvm_helper.cpp b/src/objit/src/ob_llvm_helper.cpp index 025b3e39dc..8cb88f4d71 100644 --- a/src/objit/src/ob_llvm_helper.cpp +++ b/src/objit/src/ob_llvm_helper.cpp @@ -2226,5 +2226,20 @@ ObDWARFHelper::~ObDWARFHelper() { } } +int ObLLVMHelper::add_compiled_object(size_t length, const char *ptr) +{ + int ret = OB_SUCCESS; + CK (OB_NOT_NULL(jit_)); + CK (OB_NOT_NULL(ptr)); + CK (OB_LIKELY(length > 0)); + OX (jit_->add_compiled_object(length, ptr)); + return ret; +} + +const ObString& ObLLVMHelper::get_compiled_object() +{ + return jit_->get_compiled_object(); +} + } // namespace jit } // namespace oceanbase diff --git a/src/pl/CMakeLists.txt b/src/pl/CMakeLists.txt index e8a6e6f263..253ec365ed 100644 --- a/src/pl/CMakeLists.txt +++ b/src/pl/CMakeLists.txt @@ -34,6 +34,7 @@ ob_set_subtarget(ob_pl common ob_pl_stmt.cpp ob_pl_type.cpp ob_pl_user_type.cpp + ob_pl_persistent.cpp ) ob_set_subtarget(ob_pl pl_cache diff --git a/src/pl/ob_pl.cpp b/src/pl/ob_pl.cpp index cd72c36a14..2e6c714e97 100644 --- a/src/pl/ob_pl.cpp +++ b/src/pl/ob_pl.cpp @@ -70,24 +70,25 @@ int ObPL::init(common::ObMySQLProxy &sql_proxy) { int ret = OB_SUCCESS; jit::ObLLVMHelper::initialize(); - jit::ObLLVMHelper::add_symbol(ObString("spi_calc_expr"), - (void*)(sql::ObSPIService::spi_calc_expr)); + + jit::ObLLVMHelper::add_symbol(ObString("spi_calc_expr_at_idx"), + (void*)(sql::ObSPIService::spi_calc_expr_at_idx)); jit::ObLLVMHelper::add_symbol(ObString("spi_calc_package_expr"), (void*)(sql::ObSPIService::spi_calc_package_expr)); - jit::ObLLVMHelper::add_symbol(ObString("spi_set_variable"), - (void*)(sql::ObSPIService::spi_set_variable)); - jit::ObLLVMHelper::add_symbol(ObString("spi_query"), - (void*)(sql::ObSPIService::spi_query)); + jit::ObLLVMHelper::add_symbol(ObString("spi_set_variable_to_expr"), + (void*)(sql::ObSPIService::spi_set_variable_to_expr)); + jit::ObLLVMHelper::add_symbol(ObString("spi_query_into_expr_idx"), + (void*)(sql::ObSPIService::spi_query_into_expr_idx)); jit::ObLLVMHelper::add_symbol(ObString("spi_check_autonomous_trans"), (void*)(sql::ObSPIService::spi_check_autonomous_trans)); - jit::ObLLVMHelper::add_symbol(ObString("spi_execute"), - (void*)(sql::ObSPIService::spi_execute)); + jit::ObLLVMHelper::add_symbol(ObString("spi_execute_with_expr_idx"), + (void*)(sql::ObSPIService::spi_execute_with_expr_idx)); jit::ObLLVMHelper::add_symbol(ObString("spi_execute_immediate"), (void*)(sql::ObSPIService::spi_execute_immediate)); jit::ObLLVMHelper::add_symbol(ObString("spi_cursor_init"), (void*)(sql::ObSPIService::spi_cursor_init)); - jit::ObLLVMHelper::add_symbol(ObString("spi_cursor_open"), - (void*)(sql::ObSPIService::spi_cursor_open)); + jit::ObLLVMHelper::add_symbol(ObString("spi_cursor_open_with_param_idx"), + (void*)(sql::ObSPIService::spi_cursor_open_with_param_idx)); jit::ObLLVMHelper::add_symbol(ObString("spi_dynamic_open"), (void*)(sql::ObSPIService::spi_dynamic_open)); jit::ObLLVMHelper::add_symbol(ObString("spi_cursor_fetch"), @@ -106,8 +107,6 @@ int ObPL::init(common::ObMySQLProxy &sql_proxy) (void*)(sql::ObSPIService::spi_process_resignal)); jit::ObLLVMHelper::add_symbol(ObString("spi_destruct_collection"), (void*)(sql::ObSPIService::spi_destruct_collection)); - jit::ObLLVMHelper::add_symbol(ObString("spi_init_collection"), - (void*)(sql::ObSPIService::spi_init_collection)); jit::ObLLVMHelper::add_symbol(ObString("spi_reset_collection"), (void*)(sql::ObSPIService::spi_reset_collection)); jit::ObLLVMHelper::add_symbol(ObString("spi_copy_datum"), @@ -144,8 +143,6 @@ int ObPL::init(common::ObMySQLProxy &sql_proxy) (void*)(sql::ObSPIService::spi_update_package_change_info)); jit::ObLLVMHelper::add_symbol(ObString("spi_check_composite_not_null"), (void*)(sql::ObSPIService::spi_check_composite_not_null)); - jit::ObLLVMHelper::add_symbol(ObString("spi_update_location"), - (void*)(sql::ObSPIService::spi_update_location)), jit::ObLLVMHelper::add_symbol(ObString("pl_execute"), (void*)(ObPL::execute_proc)); jit::ObLLVMHelper::add_symbol(ObString("set_user_type_var"), @@ -183,8 +180,6 @@ int ObPL::init(common::ObMySQLProxy &sql_proxy) (void*)(ObPLEH::eh_debug_obj)); jit::ObLLVMHelper::add_symbol(ObString("eh_debug_objparam"), (void*)(ObPLEH::eh_debug_objparam)); - jit::ObLLVMHelper::add_symbol(ObString("spi_copy_ref_cursor"), - (void*)(sql::ObSPIService::spi_copy_ref_cursor)); jit::ObLLVMHelper::add_symbol(ObString("spi_add_ref_cursor_refcount"), (void*)(sql::ObSPIService::spi_add_ref_cursor_refcount)); jit::ObLLVMHelper::add_symbol(ObString("spi_handle_ref_cursor_refcount"), @@ -4543,5 +4538,13 @@ int ObPL::check_session_alive(const ObBasicSessionInfo &session) { return ret; } +int ObPLFunction::gen_action_from_precompiled(const ObString &name, size_t length, + const char *ptr) { + int ret = OB_SUCCESS; + OZ (helper_.add_compiled_object(length, ptr)); + OX (set_action(helper_.get_function_address(name))); + return ret; +} + } // namespace pl } diff --git a/src/pl/ob_pl.h b/src/pl/ob_pl.h index 46d66d53b7..655f412d47 100644 --- a/src/pl/ob_pl.h +++ b/src/pl/ob_pl.h @@ -498,6 +498,8 @@ public: */ int is_special_pkg_invoke_right(ObSchemaGetterGuard &guard, bool &flag); + int gen_action_from_precompiled(const ObString &name, size_t length, const char *ptr); + common::ObFixedArray& get_sql_infos() { return sql_infos_; diff --git a/src/pl/ob_pl_code_generator.cpp b/src/pl/ob_pl_code_generator.cpp index 90bc011da4..ac32a4dc43 100644 --- a/src/pl/ob_pl_code_generator.cpp +++ b/src/pl/ob_pl_code_generator.cpp @@ -1649,7 +1649,7 @@ int ObPLCodeGenerateVisitor::visit(const ObPLExecuteStmt &s) ObLLVMValue null_pointer; ObLLVMValue int_value; ObSEArray args; - ObLLVMValue sql_addr; + ObLLVMValue sql_idx; ObLLVMValue params; ObLLVMType params_type; @@ -1676,8 +1676,8 @@ int ObPLCodeGenerateVisitor::visit(const ObPLExecuteStmt &s) * 这是因为直接传rawexpr,由spi_execute_immediate进行计算会省掉一次spi交互。 * 而using不仅是传入参数,还可以做传出参数,所以必须用obobjparam向外传递结果。 */ - OZ (generator_.generate_pointer(generator_.get_expr(s.get_sql()), sql_addr)); - OZ (args.push_back(sql_addr)); + OZ (generator_.get_helper().get_int64(s.get_sql(), sql_idx)); + OZ (args.push_back(sql_idx)); // param exprs & param count ObLLVMType param_mode_arr_type; //param mode array elem type @@ -1870,7 +1870,7 @@ int ObPLCodeGenerateVisitor::visit(const ObPLExtendStmt &s) ObSEArray args; if (OB_FAIL(args.push_back(generator_.get_vars().at(generator_.CTX_IDX)))) { //PL的执行环境 LOG_WARN("push_back error", K(ret)); - } else if (OB_FAIL(generator_.generate_pointer(generator_.get_expr(s.get_extend()), int_value))) { + } else if (OB_FAIL(generator_.get_helper().get_int64(s.get_extend(), int_value))) { LOG_WARN("failed to generate a pointer", K(ret)); } else if (OB_FAIL(args.push_back(int_value))) { LOG_WARN("push_back error", K(ret)); @@ -1878,11 +1878,11 @@ int ObPLCodeGenerateVisitor::visit(const ObPLExtendStmt &s) LOG_WARN("failed to get int64", K(ret)); } else if (OB_FAIL(args.push_back(int_value))) { LOG_WARN("push_back error", K(ret)); - } else if (OB_FAIL(generator_.generate_pointer(generator_.get_expr(s.get_n()), int_value))) { + } else if (OB_FAIL(generator_.get_helper().get_int64(s.get_n(), int_value))) { LOG_WARN("failed to get int64", K(ret)); } else if (OB_FAIL(args.push_back(int_value))) { LOG_WARN("push_back error", K(ret)); - } else if (OB_FAIL(generator_.generate_pointer(generator_.get_expr(s.get_i()), int_value))) { + } else if (OB_FAIL(generator_.get_helper().get_int64(s.get_i(), int_value))) { LOG_WARN("failed to get int64", K(ret)); } else if (OB_FAIL(args.push_back(int_value))) { LOG_WARN("push_back error", K(ret)); @@ -1925,11 +1925,11 @@ int ObPLCodeGenerateVisitor::visit(const ObPLTrimStmt &s) ObSEArray args; ObLLVMValue ret_err; OZ (args.push_back(generator_.get_vars().at(generator_.CTX_IDX))); - OZ (generator_.generate_pointer(generator_.get_expr(s.get_trim()), int_value)); + OZ (generator_.get_helper().get_int64(s.get_trim(), int_value)); OZ (args.push_back(int_value)); OZ (generator_.get_helper().get_int64(row_size, int_value)); OZ (args.push_back(int_value)); - OZ (generator_.generate_pointer(generator_.get_expr(s.get_n()), int_value)); + OZ (generator_.get_helper().get_int64(s.get_n(), int_value)); OZ (args.push_back(int_value)); OZ (generator_.get_helper().create_call(ObString("spi_trim_collection"), @@ -1961,13 +1961,13 @@ int ObPLCodeGenerateVisitor::visit(const ObPLDeleteStmt &s) ObSEArray args; ObLLVMValue ret_err; OZ (args.push_back(generator_.get_vars().at(generator_.CTX_IDX))); - OZ (generator_.generate_pointer(generator_.get_expr(s.get_delete()), int_value)); + OZ (generator_.get_helper().get_int64(s.get_delete(), int_value)); OZ (args.push_back(int_value)); OZ (generator_.get_helper().get_int64(row_size, int_value)); OZ (args.push_back(int_value)); - OZ (generator_.generate_pointer(generator_.get_expr(s.get_m()), int_value)); + OZ (generator_.get_helper().get_int64(s.get_m(), int_value)); OZ (args.push_back(int_value)); - OZ (generator_.generate_pointer(generator_.get_expr(s.get_n()), int_value)); + OZ (generator_.get_helper().get_int64(s.get_n(), int_value)); OZ (args.push_back(int_value)); OZ (generator_.get_helper().create_call(ObString("spi_delete_collection"), @@ -2465,9 +2465,9 @@ int ObPLCodeGenerateVisitor::visit(const ObPLSignalStmt &s) OZ (generator_.get_helper().get_llvm_type(ObInt32Type, int32_type)); OZ (int32_type.get_pointer_to(int32_type_ptr)); OZ (args.push_back(generator_.get_vars().at(generator_.CTX_IDX))); - OZ (generator_.generate_pointer(NULL != err_idx ? generator_.get_expr(*err_idx) : NULL, int_value)); + OZ (generator_.get_helper().get_int64(nullptr != err_idx ? *err_idx : OB_INVALID_ID, int_value)); OZ (args.push_back(int_value)); - OZ (generator_.generate_pointer(NULL != msg_idx ? generator_.get_expr(*msg_idx) : NULL, int_value)); + OZ (generator_.get_helper().get_int64(nullptr != msg_idx ? *msg_idx : OB_INVALID_ID, int_value)); OZ (args.push_back(int_value)); OZ (generator_.generate_string(ObString(s.get_str_len(), s.get_sql_state()), sql_state, str_len)); OZ (args.push_back(sql_state)); @@ -2538,9 +2538,9 @@ int ObPLCodeGenerateVisitor::visit(const ObPLRaiseAppErrorStmt &s) ObSEArray args; ObLLVMValue ret_err; OZ (args.push_back(generator_.get_vars().at(generator_.CTX_IDX))); - OZ (generator_.generate_pointer(generator_.get_expr(s.get_params().at(0)), int_value)); + OZ (generator_.get_helper().get_int64(s.get_params().at(0), int_value)); OZ (args.push_back(int_value)); - OZ (generator_.generate_pointer(generator_.get_expr(s.get_params().at(1)), int_value)); + OZ (generator_.get_helper().get_int64(s.get_params().at(1), int_value)); OZ (args.push_back(int_value)); OZ (generator_.get_helper().create_call(ObString("spi_raise_application_error"), generator_.get_spi_service().spi_raise_application_error_, args, ret_err)); OZ (generator_.check_success(ret_err, s.get_stmt_id(), s.get_block()->in_notfound(), s.get_block()->in_warning())); @@ -3741,7 +3741,7 @@ int ObPLCodeGenerator::init_spi_service() LOG_WARN("push_back error", K(ret)); } else if (OB_FAIL(ObLLVMFunctionType::get(int32_type, arg_types, ft))) { LOG_WARN("failed to get function type", K(ret)); - } else if (OB_FAIL(helper_.create_function(ObString("spi_calc_expr"), ft, spi_service_.spi_calc_expr_))) { + } else if (OB_FAIL(helper_.create_function(ObString("spi_calc_expr_at_idx"), ft, spi_service_.spi_calc_expr_at_idx_))) { LOG_WARN("failed to create function", K(ret)); } else { /*do nothing*/ } } @@ -3788,7 +3788,7 @@ int ObPLCodeGenerator::init_spi_service() LOG_WARN("push_back error", K(ret)); } else if (OB_FAIL(ObLLVMFunctionType::get(int32_type, arg_types, ft))) { LOG_WARN("failed to get function type", K(ret)); - } else if (OB_FAIL(helper_.create_function(ObString("spi_set_variable"), ft, spi_service_.spi_set_variable_))) { + } else if (OB_FAIL(helper_.create_function(ObString("spi_set_variable_to_expr"), ft, spi_service_.spi_set_variable_to_expr_))) { LOG_WARN("failed to create function", K(ret)); } else { /*do nothing*/ } } @@ -3821,7 +3821,7 @@ int ObPLCodeGenerator::init_spi_service() LOG_WARN("push_back error", K(ret)); } else if (OB_FAIL(ObLLVMFunctionType::get(int32_type, arg_types, ft))) { LOG_WARN("failed to get function type", K(ret)); - } else if (OB_FAIL(helper_.create_function(ObString("spi_query"), ft, spi_service_.spi_query_))) { + } else if (OB_FAIL(helper_.create_function(ObString("spi_query_into_expr_idx"), ft, spi_service_.spi_query_into_expr_idx_))) { LOG_WARN("failed to create function", K(ret)); } else { /*do nothing*/ } } @@ -3869,7 +3869,7 @@ int ObPLCodeGenerator::init_spi_service() LOG_WARN("push_back error", K(ret)); } else if (OB_FAIL(ObLLVMFunctionType::get(int32_type, arg_types, ft))) { LOG_WARN("failed to get function type", K(ret)); - } else if (OB_FAIL(helper_.create_function(ObString("spi_execute"), ft, spi_service_.spi_execute_))) { + } else if (OB_FAIL(helper_.create_function(ObString("spi_execute_with_expr_idx"), ft, spi_service_.spi_execute_with_expr_idx_))) { LOG_WARN("failed to create function", K(ret)); } else { /*do nothing*/ } } @@ -4028,7 +4028,7 @@ int ObPLCodeGenerator::init_spi_service() OZ (arg_types.push_back(int64_type));//cursor_param_count OZ (arg_types.push_back(bool_type));//skip_locked OZ (ObLLVMFunctionType::get(int32_type, arg_types, ft)); - OZ (helper_.create_function(ObString("spi_cursor_open"), ft, spi_service_.spi_cursor_open_)); + OZ (helper_.create_function(ObString("spi_cursor_open_with_param_idx"), ft, spi_service_.spi_cursor_open_with_param_idx_)); } if (OB_SUCC(ret)) { @@ -4089,25 +4089,6 @@ int ObPLCodeGenerator::init_spi_service() } else { /*do nothing*/ } } - if (OB_SUCC(ret)) { - arg_types.reset(); - if (OB_FAIL(arg_types.push_back(pl_exec_context_pointer_type))) { //函数第一个参数必须是基础环境信息隐藏参数 - LOG_WARN("push_back error", K(ret)); - } else if (OB_FAIL(arg_types.push_back(int64_type))) { //src - LOG_WARN("push_back error", K(ret)); - } else if (OB_FAIL(arg_types.push_back(int64_type))) { //dest - LOG_WARN("push_back error", K(ret)); - } else if (OB_FAIL(arg_types.push_back(int64_type))) { //row_size - LOG_WARN("push_back error", K(ret)); - } else if (OB_FAIL(arg_types.push_back(int64_type))) { // package id - LOG_WARN("push_back error", K(ret)); - } else if (OB_FAIL(ObLLVMFunctionType::get(int32_type, arg_types, ft))) { - LOG_WARN("failed to get function type", K(ret)); - } else if (OB_FAIL(helper_.create_function(ObString("spi_init_collection"), ft, spi_service_.spi_init_collection_))) { - LOG_WARN("failed to create function", K(ret)); - } else { /*do nothing*/ } - } - if (OB_SUCC(ret)) { arg_types.reset(); if (OB_FAIL(arg_types.push_back(int64_type))) { //src @@ -4235,17 +4216,7 @@ int ObPLCodeGenerator::init_spi_service() OZ (helper_.create_function(ObString("spi_process_nocopy_params"), ft, spi_service_.spi_process_nocopy_params_)); } - if (OB_SUCC(ret)) { - arg_types.reset(); - OZ (arg_types.push_back(pl_exec_context_pointer_type)); //函数第一个参数必须是基础环境信息隐藏参数 - OZ (arg_types.push_back(int64_type)); //allocator - OZ (arg_types.push_back(obj_pointer_type)); //src - OZ (arg_types.push_back(obj_pointer_type)); //dest - OZ (arg_types.push_back(data_type_pointer_type)); //dest type - OZ (arg_types.push_back(int64_type)); // package id - OZ (ObLLVMFunctionType::get(int32_type, arg_types, ft)); - OZ (helper_.create_function(ObString("spi_copy_ref_cursor"), ft, spi_service_.spi_copy_ref_cursor_)); - } + if (OB_SUCC(ret)) { arg_types.reset(); OZ (arg_types.push_back(pl_exec_context_pointer_type)); //函数第一个参数必须是基础环境信息隐藏参数 @@ -4281,14 +4252,6 @@ int ObPLCodeGenerator::init_spi_service() ft, spi_service_.spi_check_composite_not_null_)); } - if (OB_SUCC(ret)) { - arg_types.reset(); - OZ (arg_types.push_back(pl_exec_context_pointer_type)); - OZ (arg_types.push_back(int64_type)); - OZ (ObLLVMFunctionType::get(int32_type, arg_types, ft)); - OZ (helper_.create_function( - ObString("spi_update_location"), ft, spi_service_.spi_update_location_)); - } if (OB_SUCC(ret)) { arg_types.reset(); OZ (arg_types.push_back(pl_exec_context_pointer_type)); @@ -4952,7 +4915,7 @@ int ObPLCodeGenerator::generate_open( OZ (args.push_back(actual_params)); OZ (args.push_back(cursor_param_count)); OZ (args.push_back(skip_locked)); - OZ (get_helper().create_call(ObString("spi_cursor_open"), get_spi_service().spi_cursor_open_, args, ret_err)); + OZ (get_helper().create_call(ObString("spi_cursor_open_with_param_idx"), get_spi_service().spi_cursor_open_with_param_idx_, args, ret_err)); OZ (check_success(ret_err, s.get_stmt_id(), s.get_block()->in_notfound(), s.get_block()->in_warning())); } return ret; @@ -4980,7 +4943,7 @@ int ObPLCodeGenerator::generate_open_for(const ObPLOpenForStmt &s) } else { ObArray using_exprs; ObSEArray args; - ObLLVMValue sql_addr; + ObLLVMValue sql_idx; ObLLVMValue sql_params; ObLLVMValue sql_param_count; ObLLVMValue package_id_value; @@ -4988,8 +4951,8 @@ int ObPLCodeGenerator::generate_open_for(const ObPLOpenForStmt &s) ObLLVMValue cursor_index_value; ObLLVMValue ret_err; OZ (args.push_back(get_vars().at(CTX_IDX))); - OZ (generate_pointer(get_expr(s.get_dynamic_sql()), sql_addr)); - OZ (args.push_back(sql_addr)); + OZ (helper_.get_int64(s.get_dynamic_sql(), sql_idx)); + OZ (args.push_back(sql_idx)); for (int64_t i = 0; OB_SUCC(ret) && i < s.get_using().count(); ++i) { OZ (using_exprs.push_back(s.get_using_index(i))); } @@ -5616,7 +5579,7 @@ int ObPLCodeGenerator::generate_sql(const ObPLSqlStmt &s, ObLLVMValue &ret_err) OZ (get_helper().get_int8(static_cast(s.is_type_record()), is_type_record)); OZ (args.push_back(is_type_record)); OZ (args.push_back(for_update)); - OZ (get_helper().create_call(ObString("spi_query"), get_spi_service().spi_query_, args, ret_err)); + OZ (get_helper().create_call(ObString("spi_query_into_expr_idx"), get_spi_service().spi_query_into_expr_idx_, args, ret_err)); } else { //有外部变量,走prepare/execute接口 ObLLVMValue is_forall; OZ (get_helper().get_int8(static_cast(s.is_forall_sql()), is_forall)); @@ -5624,7 +5587,7 @@ int ObPLCodeGenerator::generate_sql(const ObPLSqlStmt &s, ObLLVMValue &ret_err) OZ (get_helper().get_int8(static_cast(s.is_type_record()), is_type_record)); OZ (args.push_back(is_type_record)); OZ (args.push_back(for_update)); - OZ (get_helper().create_call(ObString("spi_execute"), get_spi_service().spi_execute_, args, ret_err)); + OZ (get_helper().create_call(ObString("spi_execute_with_expr_idx"), get_spi_service().spi_execute_with_expr_idx_, args, ret_err)); } } } @@ -6176,8 +6139,8 @@ int ObPLCodeGenerator::generate_spi_calc(int64_t expr_idx, ret = OB_ERR_UNEXPECTED; LOG_WARN("expr is NULL", K(ret)); } else { - ObLLVMValue expr_addr; - if (OB_FAIL(generate_pointer(expr, expr_addr))) { + ObLLVMValue expr_idx_val; + if (OB_FAIL(helper_.get_int64(expr_idx, expr_idx_val))) { LOG_WARN("failed to generate a pointer", K(ret)); } else { ObSEArray args; @@ -6188,7 +6151,7 @@ int ObPLCodeGenerator::generate_spi_calc(int64_t expr_idx, if (OB_FAIL(args.push_back(vars_.at(CTX_IDX)))) { //PL的执行环境 LOG_WARN("push_back error", K(ret)); - } else if (OB_FAIL(args.push_back(expr_addr))) { //表达式的绝对地址 + } else if (OB_FAIL(args.push_back(expr_idx_val))) { //表达式的下标 LOG_WARN("push_back error", K(ret)); } else if (OB_FAIL(helper_.get_int64(result_idx, int_value))) { LOG_WARN("failed to get int64", K(ret)); @@ -6198,7 +6161,7 @@ int ObPLCodeGenerator::generate_spi_calc(int64_t expr_idx, LOG_WARN("failed to generate_new_objparam", K(ret)); } else if (OB_FAIL(args.push_back(p_result_obj))) { LOG_WARN("push_back error", K(ret)); - } else if (OB_FAIL(helper_.create_call(ObString("calc_expr"), get_spi_service().spi_calc_expr_, args, result))) { + } else if (OB_FAIL(helper_.create_call(ObString("calc_expr"), get_spi_service().spi_calc_expr_at_idx_, args, result))) { LOG_WARN("failed to create call", K(ret)); } else if (OB_FAIL(check_success(result, stmt_id, in_notfound, in_warning))) { LOG_WARN("failed to check success", K(ret)); @@ -6628,20 +6591,20 @@ int ObPLCodeGenerator::generate_expression_array(const ObIArray &exprs, jit::ObLLVMValue &count) { int ret = OB_SUCCESS; - ObSEArray expr_addrs; + ObSEArray expr_idx; for (int64_t i = 0; OB_SUCC(ret) && i < exprs.count(); ++i) { - if (OB_FAIL(expr_addrs.push_back(reinterpret_cast(get_expr(exprs.at(i)))))) { + if (OB_FAIL(expr_idx.push_back(exprs.at(i)))) { LOG_WARN("store expr addr failed", K(ret)); } } if (OB_SUCC(ret)) { ObLLVMValue first_addr; - if (expr_addrs.empty()) { + if (expr_idx.empty()) { if (OB_FAIL(generate_null_pointer(ObIntType, value))) { LOG_WARN("failed to generate_null_pointer", K(ret)); } } else { - if (OB_FAIL(generate_uint64_array(expr_addrs, value))) { + if (OB_FAIL(generate_uint64_array(expr_idx, value))) { LOG_WARN("failed to get_uint64_array", K(ret)); } } @@ -6992,14 +6955,14 @@ int ObPLCodeGenerator::generate_set_variable(int64_t expr, { int ret = OB_SUCCESS; ObSEArray args; - ObLLVMValue expr_addr; + ObLLVMValue expr_idx; ObLLVMValue is_default_value, need_copy; ObLLVMValue result; if (OB_FAIL(args.push_back(get_vars().at(CTX_IDX)))) { //PL的执行环境 LOG_WARN("push_back error", K(ret)); - } else if (OB_FAIL(generate_pointer(get_expr(expr), expr_addr))) { + } else if (OB_FAIL(helper_.get_int64(expr, expr_idx))) { LOG_WARN("failed to generate a pointer", K(ret)); - } else if (OB_FAIL(args.push_back(expr_addr))) { //expr + } else if (OB_FAIL(args.push_back(expr_idx))) { //expr LOG_WARN("push_back error", K(ret)); } else if (OB_FAIL(args.push_back(value))) { //value LOG_WARN("push_back error", K(ret)); @@ -7011,7 +6974,7 @@ int ObPLCodeGenerator::generate_set_variable(int64_t expr, LOG_WARN("failed tio get int8", K(ret)); } else if (OB_FAIL(args.push_back(need_copy))) { LOG_WARN("push_back error", K(ret)); - } else if (OB_FAIL(get_helper().create_call(ObString("spi_set_variable"), get_spi_service().spi_set_variable_, args, result))) { + } else if (OB_FAIL(get_helper().create_call(ObString("spi_set_variable_to_expr"), get_spi_service().spi_set_variable_to_expr_, args, result))) { LOG_WARN("failed to create call", K(ret)); } else if (OB_FAIL(check_success(result, stmt_id, in_notfound, in_warning))) { LOG_WARN("failed to check success", K(ret)); @@ -8363,7 +8326,7 @@ int ObPLCodeGenerator::generate_simple(ObPLFunction &pl_func) OZ (final_expression(pl_func)); OZ (pl_func.set_variables(get_ast().get_symbol_table())); OZ (pl_func.get_dependency_table().assign(get_ast().get_dependency_table())); - OX (pl_func.add_members(get_ast().get_flag())); + OZ (pl_func.add_members(get_ast().get_flag())); OX (pl_func.set_pipelined(get_ast().get_pipelined())); OX (pl_func.set_action((uint64_t)(&ObPL::simple_execute))); OX (pl_func.set_can_cached(get_ast().get_can_cached())); @@ -8474,7 +8437,7 @@ int ObPLCodeGenerator::generate_normal(ObPLFunction &pl_func) helper_.dump_module(); #endif OZ (helper_.verify_module(), pl_func); - OX (helper_.compile_module(!debug_mode_)); +OX (helper_.compile_module(!debug_mode_)); } if (OB_SUCC(ret)) { @@ -8490,7 +8453,7 @@ int ObPLCodeGenerator::generate_normal(ObPLFunction &pl_func) pl_func.add_members(get_ast().get_flag()); pl_func.set_pipelined(get_ast().get_pipelined()); pl_func.set_action(helper_.get_function_address(get_ast().get_name())); - pl_func.set_can_cached(get_ast().get_can_cached()); + pl_func.set_can_cached(get_ast().get_can_cached()); pl_func.set_is_all_sql_stmt(get_ast().get_is_all_sql_stmt()); pl_func.set_has_parallel_affect_factor(get_ast().has_parallel_affect_factor()); } diff --git a/src/pl/ob_pl_code_generator.h b/src/pl/ob_pl_code_generator.h index 2c460241f5..add42b8729 100644 --- a/src/pl/ob_pl_code_generator.h +++ b/src/pl/ob_pl_code_generator.h @@ -60,22 +60,20 @@ public: public: struct ObPLSPIService { - jit::ObLLVMFunction spi_calc_expr_; + jit::ObLLVMFunction spi_calc_expr_at_idx_; jit::ObLLVMFunction spi_calc_package_expr_; - jit::ObLLVMFunction spi_set_variable_; - jit::ObLLVMFunction spi_query_; - jit::ObLLVMFunction spi_prepare_; - jit::ObLLVMFunction spi_execute_; + jit::ObLLVMFunction spi_set_variable_to_expr_; + jit::ObLLVMFunction spi_query_into_expr_idx_; + jit::ObLLVMFunction spi_execute_with_expr_idx_; jit::ObLLVMFunction spi_execute_immediate_; jit::ObLLVMFunction spi_extend_collection_; jit::ObLLVMFunction spi_delete_collection_; jit::ObLLVMFunction spi_cursor_init_; - jit::ObLLVMFunction spi_cursor_open_; + jit::ObLLVMFunction spi_cursor_open_with_param_idx_; jit::ObLLVMFunction spi_dynamic_open_; jit::ObLLVMFunction spi_cursor_fetch_; jit::ObLLVMFunction spi_cursor_close_; jit::ObLLVMFunction spi_destruct_collection_; - jit::ObLLVMFunction spi_init_collection_; jit::ObLLVMFunction spi_reset_collection_; jit::ObLLVMFunction spi_copy_datum_; jit::ObLLVMFunction spi_destruct_obj_; @@ -94,12 +92,10 @@ public: jit::ObLLVMFunction spi_trim_collection_; jit::ObLLVMFunction spi_interface_impl_; jit::ObLLVMFunction spi_process_nocopy_params_; - jit::ObLLVMFunction spi_copy_ref_cursor_; jit::ObLLVMFunction spi_add_ref_cursor_refcount_; jit::ObLLVMFunction spi_handle_ref_cursor_refcount_; jit::ObLLVMFunction spi_update_package_change_info_; jit::ObLLVMFunction spi_check_composite_not_null_; - jit::ObLLVMFunction spi_update_location_; jit::ObLLVMFunction spi_process_resignal_error_; jit::ObLLVMFunction spi_check_autonomous_trans_; }; @@ -665,6 +661,8 @@ public: int64_t expr_idx, const ObPLStmt &s, jit::ObLLVMValue &p_result_obj); + int prepare_expression(ObPLCompileUnit &pl_func); + int final_expression(ObPLCompileUnit &pl_func); private: int init_spi_service(); @@ -678,8 +676,6 @@ private: int prepare_local_user_type(); int prepare_external(); int prepare_subprogram(ObPLFunction &pl_func); - int prepare_expression(ObPLCompileUnit &pl_func); - int final_expression(ObPLCompileUnit &pl_func); int generate_get_attr(jit::ObLLVMValue ¶m_array, const common::ObIArray &obj_access, bool for_write, @@ -786,6 +782,7 @@ public: uint32_t arg_no, uint32_t line, jit::ObLLVMValue &value); int generate_di_local_variable(const ObString &name, jit::ObLLVMDIType &di_type, uint32_t arg_no, uint32_t line, jit::ObLLVMValue &value); + bool get_debug_mode() { return debug_mode_; } private: int init_di_adt_service(); int generate_di_prototype(); diff --git a/src/pl/ob_pl_compile.cpp b/src/pl/ob_pl_compile.cpp index e16ca4b27e..738fab1bf4 100644 --- a/src/pl/ob_pl_compile.cpp +++ b/src/pl/ob_pl_compile.cpp @@ -24,6 +24,7 @@ #include "pl/ob_pl_code_generator.h" #include "pl/ob_pl_package.h" #include "lib/alloc/malloc_hook.h" +#include "pl/ob_pl_persistent.h" namespace oceanbase { using namespace common; @@ -481,16 +482,60 @@ int ObPLCompiler::compile(const uint64_t id, ObPLFunction &func) func.get_di_helper(), lib::is_oracle_mode()) { #endif + ObRoutinePersistentInfo routine_storage(tenant_id, + proc->get_database_id(), + session_info_.get_database_id(), + func_ast.get_id()); lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN))); - ObBucketHashWLockGuard compile_guard(GCTX.pl_engine_->get_jit_lock(), id); - // check session status after get lock + ObRoutinePersistentInfo::ObPLOperation op = ObRoutinePersistentInfo::ObPLOperation::NONE; + bool need_read_dll = GCONF._enable_persistent_compiled_routine && func_ast.get_can_cached() && + !cg.get_debug_mode() && (!func_ast.get_is_all_sql_stmt() || !func_ast.get_obj_access_exprs().empty()); + OZ (cg.init()); + // Step 4: try to obtain dll from disk + if (need_read_dll) { + OZ (routine_storage.read_dll_from_disk(&session_info_, schema_guard_, func.get_exec_env(), func_ast, func, op)); + } + +#define SET_FUNC \ + do { \ + OZ (cg.prepare_expression(func)); \ + OZ (cg.final_expression(func)); \ + OZ (func.set_variables(func_ast.get_symbol_table())); \ + OZ (func.set_types(func_ast.get_user_type_table())); \ + OZ (func.get_dependency_table().assign(func_ast.get_dependency_table())); \ + OZ (func.add_members(func_ast.get_flag())); \ + OX (func.set_pipelined(func_ast.get_pipelined())); \ + OX (func.set_can_cached(func_ast.get_can_cached())); \ + OX (func.set_is_all_sql_stmt(func_ast.get_is_all_sql_stmt())); \ + OX (func.set_has_parallel_affect_factor(func_ast.has_parallel_affect_factor())); \ + } while (0) + + if (OB_FAIL(ret)) { + } else if (0 != func.get_action()) { + SET_FUNC; + } else { + ObBucketHashWLockGuard compile_guard(GCTX.pl_engine_->get_jit_lock(), id); + if (OB_FAIL(ObPL::check_session_alive(session_info_))) { + LOG_WARN("query or session is killed after get PL jit lock", K(ret)); + } + + if (OB_SUCC(ret) && need_read_dll) { + OZ (routine_storage.read_dll_from_disk(&session_info_, schema_guard_, func.get_exec_env(), func_ast, func, op)); + } + // check session status after get lock if (OB_FAIL(ObPL::check_session_alive(session_info_))) { LOG_WARN("query or session is killed after get PL jit lock", K(ret)); - } else if (OB_FAIL(cg.init())) { - LOG_WARN("failed to init code generator", K(ret)); - } else if (OB_FAIL(cg.generate(func))) { - LOG_WARN("failed to code generate for stmt", K(ret)); - } else { + } else if (OB_FAIL(ret)) { + } else if (0 != func.get_action()) { + SET_FUNC; + } else { + OZ (cg.generate(func)); + if (need_read_dll) { + OZ (routine_storage.process_storage_dll(allocator_, schema_guard_, func, op)); + } + } + } + if (OB_SUCC(ret)) { int64_t tenant_id = session_info_.get_effective_tenant_id(); int64_t tenant_schema_version = OB_INVALID_VERSION; int64_t sys_schema_version = OB_INVALID_VERSION; @@ -744,12 +789,45 @@ int ObPLCompiler::generate_package(const ObString &exec_env, ObPLPackageAST &pac CK (OB_NOT_NULL(session_info_.get_pl_engine())); if (OB_SUCC(ret)) { WITH_CONTEXT(package.get_mem_context()) { + ObRoutinePersistentInfo routine_storage(get_tenant_id_by_object_id(package.get_id()), + session_info_.get_database_id(), + session_info_.get_database_id(), + package.get_id()); + ObRoutinePersistentInfo::ObPLOperation op = ObRoutinePersistentInfo::ObPLOperation::NONE; + bool need_read_dll = GCONF._enable_persistent_compiled_routine + && package_ast.get_can_cached() + && (!session_info_.is_pl_debug_on() || get_tenant_id_by_object_id(package.get_id()) == OB_SYS_TENANT_ID); CK (package.is_inited()); OZ (package.get_dependency_table().assign(package_ast.get_dependency_table())); OZ (generate_package_conditions(package_ast.get_condition_table(), package)); OZ (generate_package_vars(package_ast, package_ast.get_symbol_table(), package)); OZ (generate_package_types(package_ast.get_user_type_table(), package)); - OZ (generate_package_routines(exec_env, package_ast.get_routine_table(), package)); + if (need_read_dll) { + sql::ObExecEnv env; + OZ (env.init(exec_env)); + OZ (routine_storage.read_dll_from_disk(&session_info_, schema_guard_, env, package_ast, package, op)); + } + if (op == ObRoutinePersistentInfo::ObPLOperation::SUCC) { + //do nothing + } else { + ObBucketHashWLockGuard compile_guard(GCTX.pl_engine_->get_jit_lock(), package.get_id()); + OZ (ObPL::check_session_alive(session_info_)); + if (OB_SUCC(ret)) { + if (need_read_dll) { + sql::ObExecEnv env; + OZ (env.init(exec_env)); + OZ (routine_storage.read_dll_from_disk(&session_info_, schema_guard_, env, package_ast, package, op)); + } + if (op == ObRoutinePersistentInfo::ObPLOperation::SUCC) { + //do nothing + } else { + OZ (generate_package_routines(exec_env, package_ast.get_routine_table(), package)); + if (need_read_dll) { + OZ (routine_storage.process_storage_dll(allocator_, schema_guard_, package, op)); + } + } + } + } OZ (generate_package_cursors(package_ast, package_ast.get_cursor_table(), package)); } } @@ -797,8 +875,7 @@ int ObPLCompiler::compile_package(const ObPackageInfo &package_info, package_ast, package_info.is_for_trigger())); { - ObBucketHashWLockGuard compile_guard(GCTX.pl_engine_->get_jit_lock(), package.get_id()); - // check session status after get lock + // check session status after get lock if (OB_SUCC(ret) && OB_FAIL(ObPL::check_session_alive(session_info_))) { LOG_WARN("query or session is killed after get PL jit lock", K(ret)); } @@ -817,6 +894,10 @@ int ObPLCompiler::compile_package(const ObPackageInfo &package_info, lib::is_oracle_mode()) { #endif lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN))); + ObBucketHashWLockGuard compile_guard(GCTX.pl_engine_->get_jit_lock(), package.get_id()); + // check session status after get lock + OZ (ObPL::check_session_alive(session_info_)); + OZ (cg.init()); OZ (cg.generate(package)); } @@ -1302,6 +1383,7 @@ int ObPLCompiler::compile_subprogram_table(common::ObIAllocator &allocator, ObPLFunction *routine = NULL; if (OB_ISNULL(routine = static_cast(compile_unit.get_allocator().alloc(sizeof(ObPLFunction))))) { + ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("allocate memory failed", K(ret)); } else { new (routine) ObPLFunction(compile_unit.get_mem_context()); @@ -1423,6 +1505,7 @@ void ObPLCompilerEnvGuard::init(const Info &info, ObSQLSessionInfo &session_info bool need_set_db = true; OX (need_reset_exec_env_ = false); OX (need_reset_default_database_ = false); + OX (old_db_id_ = OB_INVALID_ID); OZ (old_exec_env_.load(session_info_)); OZ (env.init(info.get_exec_env())); if (OB_SUCC(ret) && old_exec_env_ != env) { diff --git a/src/pl/ob_pl_compile.h b/src/pl/ob_pl_compile.h index 15a26a110d..c8ad248d3a 100644 --- a/src/pl/ob_pl_compile.h +++ b/src/pl/ob_pl_compile.h @@ -87,13 +87,13 @@ public: uint64_t dep_obj_id, uint64_t schema_version, share::schema::ObObjectType dep_obj_type); -private: - int init_function(const share::schema::ObRoutineInfo *proc, ObPLFunction &func); - static int init_function(share::schema::ObSchemaGetterGuard &schema_guard, const sql::ObExecEnv &exec_env, const ObPLRoutineInfo &routine_signature, ObPLFunction &routine); +private: + int init_function(const share::schema::ObRoutineInfo *proc, ObPLFunction &func); + int generate_package_cursors(const ObPLPackageAST &package_ast, const ObPLCursorTable &ast_cursor_table, ObPLPackage &package); diff --git a/src/pl/ob_pl_persistent.cpp b/src/pl/ob_pl_persistent.cpp new file mode 100644 index 0000000000..499d7951c8 --- /dev/null +++ b/src/pl/ob_pl_persistent.cpp @@ -0,0 +1,598 @@ +/** + * Copyright (c) 2023 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ + +#define USING_LOG_PREFIX PL_STORAGEROUTINE +#include "ob_pl_persistent.h" +#include "lib/oblog/ob_log_module.h" +#include "observer/ob_inner_sql_connection_pool.h" +#include "observer/ob_inner_sql_connection.h" +#include "observer/ob_inner_sql_result.h" +#include "ob_pl_code_generator.h" +#include "ob_pl_compile.h" + +namespace oceanbase +{ +namespace pl +{ + +int ObRoutinePersistentInfo::get_total_size(ObPLCompileUnit &unit, int32_t &total_len) +{ + int ret = OB_SUCCESS; + + total_len += get_head_size(); + total_len += 4; + if (unit.is_pkg()) { + // do nothing + } else { + total_len += static_cast(unit).get_helper().get_compiled_object().length(); + } + + for (int64_t i = 0; OB_SUCC(ret) && i < unit.get_routine_table().count(); ++i) { + if (OB_NOT_NULL(unit.get_routine_table().at(i))) { + OZ (SMART_CALL(get_total_size(*unit.get_routine_table().at(i), total_len))); + } + } + + return ret; +} + +int ObRoutinePersistentInfo::encode_header(char *buf, const int64_t len, int64_t &pos, + int8_t flags, const int8_t level, const int16_t id, const int16_t nums) +{ + int ret = OB_SUCCESS; + flags = 0xff; + if (OB_ISNULL(buf)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid input args", K(ret), KP(buf)); + } else { + if (OB_LIKELY(6 < len - pos)) { + MEMCPY(buf + pos, &flags, 1); + ++pos; + MEMCPY(buf + pos, &level, 1); + ++pos; + MEMCPY(buf + pos, &id, 2); + pos += 2; + MEMCPY(buf + pos, &nums, 2); + pos += 2; + } else { + ret = OB_SIZE_OVERFLOW; + LOG_WARN("size overflow", K(ret), K(len), K(pos), KP(buf)); + } + } + + return ret; +} + +int ObRoutinePersistentInfo::encode_payload(char *buf, int64_t len, int64_t &pos, const ObString &binary) +{ + int ret = OB_SUCCESS; + int32_t length = binary.length(); + + if (OB_ISNULL(buf)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid input args", K(ret), KP(buf)); + } else if (OB_LIKELY(4 < len - pos)) { + if (0 != length) { + MEMCPY(buf + pos, &length, 4); + pos += 4; + if (OB_LIKELY(length < len - pos)) { + MEMCPY(buf + pos, binary.ptr(), length); + pos += length; + } else { + ret = OB_SIZE_OVERFLOW; + LOG_WARN("size overflow", K(ret), K(len), K(pos), KP(buf)); + } + } else { + length = 0; + MEMCPY(buf + pos, &length, 4); + pos += 4; + } + } else { + ret = OB_SIZE_OVERFLOW; + LOG_WARN("size overflow", K(ret), K(len), K(pos), KP(buf)); + } + + return ret; +} + +int ObRoutinePersistentInfo::encode_dll(ObPLCompileUnit &unit, ObString &dll, int64_t &pos, + const int8_t level, const int16_t id) +{ + int ret = OB_SUCCESS; + int16_t nums = unit.get_routine_table().count(); + ObString binary; + if (unit.is_pkg()) { + binary.reset(); + } else { + binary = static_cast(unit).get_helper().get_compiled_object(); + } + OZ (encode_header(dll.ptr(), dll.length(), pos, 0, level, id, nums)); + OZ (encode_payload(dll.ptr(), dll.length(), pos, binary)); + for (int64_t i = 0; OB_SUCC(ret) && i < nums; ++i) { + if (OB_NOT_NULL(unit.get_routine_table().at(i))) { + OZ (SMART_CALL(encode_dll(*unit.get_routine_table().at(i), dll, pos, level + 1, i + 1))); + } + } + + return ret; +} + +int ObRoutinePersistentInfo::decode_header(char *buf, const int64_t len, int64_t &pos, + int8_t &flags, int8_t &level, int16_t &id, int16_t &nums) +{ + int ret = OB_SUCCESS; + + if (OB_ISNULL(buf)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid input args", K(ret), KP(buf)); + } else { + if (OB_LIKELY(6 < len - pos)) { + MEMCPY(&flags, buf + pos, 1); + ++pos; + MEMCPY(&level, buf + pos, 1); + ++pos; + MEMCPY(&id, buf + pos, 2); + pos += 2; + MEMCPY(&nums, buf + pos, 2); + pos += 2; + } else { + ret = OB_SIZE_OVERFLOW; + LOG_WARN("size overflow", K(ret), K(len), K(pos), KP(buf)); + } + } + + return ret; +} + +int ObRoutinePersistentInfo::decode_payload(char *buf, int64_t len, int64_t &pos, ObString &binary) +{ + int ret = OB_SUCCESS; + int32_t length = 0; + + if (OB_ISNULL(buf)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid input args", K(ret), KP(buf)); + } else if (OB_LIKELY(4 < len - pos)) { + MEMCPY(&length, buf + pos, 4); + pos += 4; + if (0 != length) { + if (OB_LIKELY(length < len - pos)) { + binary.assign_ptr(buf + pos, length); + pos += length; + } else { + ret = OB_SIZE_OVERFLOW; + LOG_WARN("size overflow", K(ret), K(len), K(pos), KP(buf)); + } + } else { + binary.reset(); + } + } else { + ret = OB_SIZE_OVERFLOW; + LOG_WARN("size overflow", K(ret), K(len), K(pos), KP(buf)); + } + + return ret; +} + +int ObRoutinePersistentInfo::decode_dll(ObSQLSessionInfo &session_info, + schema::ObSchemaGetterGuard &schema_guard, + ObExecEnv &exec_env, + ObPLCompileUnitAST &unit_ast, ObPLCompileUnit &unit, + char *buf, const int64_t len, int64_t &pos, + int8_t &level, int16_t &id) +{ + int ret = OB_SUCCESS; + int16_t nums = 0; + int8_t flags = 0; + ObString binary; + + OZ (decode_header(buf, len, pos, flags, level, id, nums)); + CK (nums == unit_ast.get_routine_table().get_count()); + OZ (decode_payload(buf, len, pos, binary)); + if (OB_FAIL(ret)) { + } else if (0 == binary.length() && + ObPLCompileUnitAST::UnitType::ROUTINE_TYPE == unit_ast.get_type()) { + CK (0 == nums); + } else { + // generate action pointer from binary + // set action + if (ObPLCompileUnitAST::UnitType::ROUTINE_TYPE == unit_ast.get_type() && + 0 != binary.length()) { + OZ (static_cast(unit).gen_action_from_precompiled(static_cast(unit_ast).get_name(), binary.length(), binary.ptr())); + } + if (OB_SUCC(ret) && nums > 0) { + ObPLRoutineTable &routine_table = unit_ast.get_routine_table(); + unit.init_routine_table(nums); + for(int64_t routine_idx = 0; OB_SUCC(ret) && routine_idx < nums; routine_idx++) { + ObPLFunctionAST *routine_ast = NULL; + const ObPLRoutineInfo *routine_info = NULL; + if (OB_FAIL(routine_table.get_routine_info(routine_idx, routine_info))) { + LOG_WARN("get routine info failed", K(ret), K(routine_idx)); + } else if (OB_ISNULL(routine_info)) { + if (OB_FAIL(unit.add_routine(NULL))) { + LOG_WARN("package add routine failed", K(ret), K(routine_idx)); + } + } else if (OB_FAIL(routine_table.get_routine_ast(routine_idx, routine_ast))) { + LOG_WARN("get routine ast failed", K(routine_idx), K(ret)); + } else if (OB_ISNULL(routine_ast)) { + if (OB_FAIL(unit.add_routine(NULL))) { + LOG_WARN("add routine failed", K(ret), K(routine_idx)); + } + } else { + ObPLFunction *routine = NULL; + if (OB_ISNULL(routine + = static_cast(unit.get_allocator().alloc(sizeof(ObPLFunction))))) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("allocate memory failed", K(ret)); + } else { + new (routine) ObPLFunction(unit.get_mem_context()); + OZ (ObPLCompiler::init_function(schema_guard, exec_env, *routine_info, *routine)); + if (OB_SUCC(ret)) { + + #ifdef USE_MCJIT + HEAP_VAR(ObPLCodeGenerator, cg ,unit.get_allocator(), session_info) { + #else + HEAP_VAR(ObPLCodeGenerator, cg, unit.get_allocator(), + session_info, + schema_guard, + *routine_ast, + routine->get_expressions(), + routine->get_helper(), + routine->get_di_helper(), + lib::is_oracle_mode()) { + #endif + int8_t cur_level = 0; + int16_t sub_id = 0; + OZ (cg.init()); + if (cg.get_debug_mode() + || !routine_ast->get_is_all_sql_stmt() + || !routine_ast->get_obj_access_exprs().empty()) { + OZ (SMART_CALL(decode_dll(session_info, schema_guard, routine->get_exec_env(), *routine_ast, *routine, buf, len, pos, cur_level, sub_id))); + CK (sub_id == routine_idx + 1); + OZ (cg.prepare_expression(*routine)); + OZ (cg.final_expression(*routine)); + OZ (routine->set_variables(routine_ast->get_symbol_table())); + OZ (routine->get_dependency_table().assign(routine_ast->get_dependency_table())); + OZ (routine->add_members(routine_ast->get_flag())); + OX (routine->set_pipelined(routine_ast->get_pipelined())); + OX (routine->set_can_cached(routine_ast->get_can_cached())); + OX (routine->set_is_all_sql_stmt(routine_ast->get_is_all_sql_stmt())); + OX (routine->set_has_parallel_affect_factor(routine_ast->has_parallel_affect_factor())); + OX (routine->set_ret_type(routine_ast->get_ret_type())); + OZ (routine->set_types(routine_ast->get_user_type_table())); + } else { + // simple routine(generate by generate_simpile interface), skip encode header byte + OZ (SMART_CALL(decode_dll(session_info, schema_guard, routine->get_exec_env(), *routine_ast, *routine, buf, len, pos, cur_level, sub_id))); + CK (sub_id == routine_idx + 1); + CK (0 == routine->get_action()); + OZ (cg.generate_simple(*routine)); + OX (routine->set_ret_type(routine_ast->get_ret_type())); + } + OZ (unit.add_routine(routine)); + } // end of HEAP_VAR + } + } + if (OB_FAIL(ret) && OB_NOT_NULL(routine)) { + routine->~ObPLFunction(); + unit.get_allocator().free(routine); + routine = NULL; + } + } + } + } + } + + return ret; +} + +int ObRoutinePersistentInfo::gen_routine_storage_dml(const uint64_t exec_tenant_id, + ObDMLSqlSplicer &dml, + int64_t merge_version, + const ObString &binary) +{ + int ret = OB_SUCCESS; + + if (OB_FAIL(dml.add_pk_column("database_id", database_id_)) + || OB_FAIL(dml.add_pk_column("key_id", key_id_)) + || OB_FAIL(dml.add_pk_column("compile_db_id", compile_db_id_)) + || OB_FAIL(dml.add_pk_column("arch_type", arch_type_)) + || OB_FAIL(dml.add_column("merge_version", merge_version)) + || OB_FAIL(dml.add_column("dll", ObHexEscapeSqlStr(binary)))) { + LOG_WARN("add column failed", K(ret)); + } + return ret; +} + +int ObRoutinePersistentInfo::check_dep_schema(ObSchemaGetterGuard &schema_guard, + const ObPLDependencyTable &dep_schema_objs, + int64_t merge_version, + bool &match) +{ + int ret = OB_SUCCESS; + uint64_t tenant_id = OB_INVALID_ID; + match = true; + for (int64_t i = 0; OB_SUCC(ret) && match && i < dep_schema_objs.count(); ++i) { + tenant_id = MTL_ID(); + if (TABLE_SCHEMA != dep_schema_objs.at(i).get_schema_type()) { + int64_t new_version = 0; + if (PACKAGE_SCHEMA == dep_schema_objs.at(i).get_schema_type() + || UDT_SCHEMA == dep_schema_objs.at(i).get_schema_type() + || ROUTINE_SCHEMA == dep_schema_objs.at(i).get_schema_type()) { + tenant_id = pl::get_tenant_id_by_object_id(dep_schema_objs.at(i).object_id_); + } + if (OB_FAIL(schema_guard.get_schema_version(dep_schema_objs.at(i).get_schema_type(), + tenant_id, + dep_schema_objs.at(i).object_id_, + new_version))) { + LOG_WARN("failed to get schema version", + K(ret), K(tenant_id), K(dep_schema_objs.at(i))); + } else if (new_version <= merge_version) { + match = true; + } else { + match = false; + } + } else { + const ObSimpleTableSchemaV2 *table_schema = nullptr; + if (OB_FAIL(schema_guard.get_simple_table_schema(MTL_ID(), + dep_schema_objs.at(i).object_id_, + table_schema))) { + LOG_WARN("failed to get table schema", K(ret), K(dep_schema_objs.at(i))); + } else if (nullptr == table_schema) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get an unexpected null table schema", K(dep_schema_objs.at(i).object_id_)); + } else if (table_schema->is_index_table()) { + // do nothing + } else if (table_schema->get_schema_version() <= merge_version) { + match = true; + } else { + match = false; + } + } + } + + return ret; +} + +int ObRoutinePersistentInfo::read_dll_from_disk(ObSQLSessionInfo *session_info, + schema::ObSchemaGetterGuard &schema_guard, + ObExecEnv &exec_env, + ObPLCompileUnitAST &unit_ast, + ObPLCompileUnit &unit, + ObRoutinePersistentInfo::ObPLOperation &op) +{ + int ret = OB_SUCCESS; + + uint64_t data_version = 0; + if (OB_FAIL(GET_MIN_DATA_VERSION(tenant_id_, data_version))) { + LOG_WARN("failed to get data version", K(ret)); + } else if (!((GET_MIN_CLUSTER_VERSION() >= CLUSTER_VERSION_4_2_2_0 && GET_MIN_CLUSTER_VERSION() < CLUSTER_VERSION_4_3_0_0) || GET_MIN_CLUSTER_VERSION() >= CLUSTER_VERSION_4_3_1_0) || + !((data_version >= DATA_VERSION_4_2_2_0 && data_version < DATA_VERSION_4_3_0_0) || data_version >= DATA_VERSION_4_3_1_0)) { + // do nothing + } else { + uint64_t action = 0; + + ObMySQLProxy *sql_proxy = NULL; + ObSqlString query_inner_sql; + ObString binary; + int64_t merge_version; + + if (OB_ISNULL(session_info)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid args", K(ret), KP(session_info)); + } else if (OB_ISNULL(sql_proxy = GCTX.sql_proxy_)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("sql proxy must not null", K(ret), KP(GCTX.sql_proxy_)); + } else if (OB_FAIL(query_inner_sql.assign_fmt( + "select merge_version, dll from OCEANBASE.%s where database_id = %ld and key_id = %ld and compile_db_id = %ld and arch_type = %d", + OB_ALL_NCOMP_DLL_TNAME, database_id_, key_id_, compile_db_id_, arch_type_))) { + LOG_WARN("assign format failed", K(ret)); + } else { + SMART_VAR(ObMySQLProxy::MySQLResult, result) { + if (OB_FAIL(sql_proxy->read(result, tenant_id_, query_inner_sql.ptr()))) { + LOG_WARN("execute query failed", K(ret), K(query_inner_sql), K(tenant_id_)); + } else if (OB_NOT_NULL(result.get_result())) { + if (OB_FAIL(result.get_result()->next())) { + if (OB_ITER_END == ret) { + op = ObRoutinePersistentInfo::ObPLOperation::INSERT; + ret = OB_SUCCESS; + } else { + LOG_WARN("failed to get next", K(ret), K(tenant_id_)); + } + } else { + EXTRACT_INT_FIELD_MYSQL(*(result.get_result()), "merge_version", merge_version, int64_t); + EXTRACT_VARCHAR_FIELD_MYSQL(*(result.get_result()), "dll", binary); + if (OB_SUCC(ret)) { + bool match = false; + int64_t tenant_schema_version = OB_INVALID_VERSION; + if (OB_FAIL(schema_guard.get_schema_version(tenant_id_, tenant_schema_version))) { + LOG_WARN("fail to get schema version"); + } else if (merge_version == tenant_schema_version) { + match = true; + op = ObRoutinePersistentInfo::ObPLOperation::NONE; + } else if (merge_version < tenant_schema_version) { + if (OB_FAIL(check_dep_schema(schema_guard, unit_ast.get_dependency_table(), merge_version, match))) { + LOG_WARN("fail to check dep schema", K(ret)); + } else if (!match) { + op = ObRoutinePersistentInfo::ObPLOperation::UPDATE; + } else { + op = ObRoutinePersistentInfo::ObPLOperation::NONE; + } + } else { + match = false; + op = ObRoutinePersistentInfo::ObPLOperation::NONE; + } + if (OB_SUCC(ret) && match) { + // gen action using dll column + int64_t pos = 0; + int8_t level = 0; + int16_t id = 0; + if (OB_FAIL(decode_dll(*session_info, schema_guard, exec_env, unit_ast, unit, binary.ptr(), binary.length(), pos, level, id))) { + LOG_WARN("fail to decode dll", K(ret), K(level), K(id)); + } else if (0 != level || 0 != id) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("fail to decode dll", K(ret), K(level), K(id)); + } else { + op = ObRoutinePersistentInfo::ObPLOperation::SUCC; + LOG_INFO("succ decode dll from disk", K(ret), K(key_id_), K(merge_version)); + } + } + } + } + } + } + } + if (OB_FAIL(ret) && + OB_ERR_UNEXPECTED != ret && + OB_ALLOCATE_MEMORY_FAILED != ret) { + ret = OB_SUCCESS; + } + } + + return ret; +} + +int ObRoutinePersistentInfo::insert_or_update_dll_to_disk(schema::ObSchemaGetterGuard &schema_guard, + const ObString &binary, + const ObRoutinePersistentInfo::ObPLOperation op) +{ + int ret = OB_SUCCESS; + + ObMySQLProxy *sql_proxy = nullptr; + + if (OB_ISNULL(sql_proxy = GCTX.sql_proxy_)) { + ret = OB_ERR_UNEXPECTED; + } else { + const uint64_t exec_tenant_id = ObSchemaUtils::get_exec_tenant_id(tenant_id_); + ObDMLSqlSplicer dml; + int64_t tenant_schema_version = OB_INVALID_VERSION; + if (OB_FAIL(schema_guard.get_schema_version(tenant_id_, tenant_schema_version))) { + LOG_WARN("fail to get schema version"); + } else if (OB_FAIL(gen_routine_storage_dml(exec_tenant_id, dml, tenant_schema_version, binary))) { + LOG_WARN("gen table dml failed", K(ret)); + } else { + ObDMLExecHelper exec(*sql_proxy, exec_tenant_id); + int64_t affected_rows = 0; + if (ObPLOperation::UPDATE == op) { + if (OB_FAIL(exec.exec_update(OB_ALL_NCOMP_DLL_TNAME, dml, affected_rows))) { + LOG_WARN("execute update failed", K(ret)); + } + } else { + if (OB_FAIL(exec.exec_insert(OB_ALL_NCOMP_DLL_TNAME, dml, affected_rows))) { + LOG_WARN("execute insert failed", K(ret)); + } + } + if (OB_SUCC(ret) && !is_single_row(affected_rows) && !is_zero_row(affected_rows)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("affected_rows unexpected to be one", K(affected_rows), K(ret), K(op), K(key_id_)); + } + } + // ignore duplicate key error + if (OB_ERR_PRIMARY_KEY_DUPLICATE == ret) { + LOG_TRACE("has a duplicate key error", K(ret), K(op), K(key_id_)); + ret = OB_SUCCESS; + } + } + + return ret; +} + +int ObRoutinePersistentInfo::process_storage_dll(ObIAllocator &alloc, + schema::ObSchemaGetterGuard &schema_guard, + ObPLCompileUnit &unit, + const ObRoutinePersistentInfo::ObPLOperation op) +{ + int ret = OB_SUCCESS; + uint64_t data_version = 0; + if (OB_FAIL(GET_MIN_DATA_VERSION(tenant_id_, data_version))) { + LOG_WARN("failed to get data version", K(ret)); + } else if (!((GET_MIN_CLUSTER_VERSION() >= CLUSTER_VERSION_4_2_2_0 && GET_MIN_CLUSTER_VERSION() < CLUSTER_VERSION_4_3_0_0) || GET_MIN_CLUSTER_VERSION() >= CLUSTER_VERSION_4_3_1_0) || + !((data_version >= DATA_VERSION_4_2_2_0 && data_version < DATA_VERSION_4_3_0_0) || data_version >= DATA_VERSION_4_3_1_0)) { + // do nothing + } else if (!MTL_TENANT_ROLE_CACHE_IS_PRIMARY()) { + // do nothing + } else if (GCONF._enable_persistent_compiled_routine && ObRoutinePersistentInfo::ObPLOperation::NONE != op) { + // insert/update so to inner table + int64_t pos = 0; + int32_t total_size = 1; + char *buf = NULL; + ObString dll; + OZ (get_total_size(unit, total_size)); + if (OB_SUCC(ret)) { + if (OB_ISNULL(buf = (char *)alloc.alloc(total_size))) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("fail to alloc memory", K(ret), K(total_size)); + } else { + buf[total_size - 1] = '\0'; + dll.assign_ptr(buf, total_size); + } + } + OZ (encode_dll(unit, dll, pos, 0, 0)); + OZ (insert_or_update_dll_to_disk(schema_guard, dll, op)); + if (OB_FAIL(ret) && + OB_ERR_UNEXPECTED != ret && + OB_ALLOCATE_MEMORY_FAILED != ret) { + ret = OB_SUCCESS; + } + } + + return ret; +} + +int ObRoutinePersistentInfo::delete_dll_from_disk(common::ObISQLClient &trans, + uint64_t tenant_id, + uint64_t key_id) +{ + int ret = OB_SUCCESS; + + uint64_t data_version = 0; + share::ObTenantRole tenant_role; + ObMySQLProxy *sql_proxy = nullptr; + if (OB_FAIL(GET_MIN_DATA_VERSION(tenant_id, data_version))) { + LOG_WARN("failed to get data version", K(ret)); + } else if (!((GET_MIN_CLUSTER_VERSION() >= CLUSTER_VERSION_4_2_2_0 && GET_MIN_CLUSTER_VERSION() < CLUSTER_VERSION_4_3_0_0) || GET_MIN_CLUSTER_VERSION() >= CLUSTER_VERSION_4_3_1_0) || + !((data_version >= DATA_VERSION_4_2_2_0 && data_version < DATA_VERSION_4_3_0_0) || data_version >= DATA_VERSION_4_3_1_0)) { + // do nothing + } else if (OB_ISNULL(sql_proxy = GCTX.sql_proxy_)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected sql proxy", K(ret)); + } else if (OB_FAIL(ObAllTenantInfoProxy::get_tenant_role(sql_proxy, tenant_id, tenant_role))) { + LOG_WARN("fail to get tenant role", K(ret)); + } else if (!tenant_role.is_valid()) { + ret = OB_NEED_WAIT; + LOG_WARN("tenant role is not ready", K(ret)); + } else if (tenant_role.is_standby()) { + // do nothing + } else { + const uint64_t exec_tenant_id = ObSchemaUtils::get_exec_tenant_id(tenant_id); + ObSqlString sql; + int64_t affected_rows = 0; + ObMySQLProxy *sql_proxy = nullptr; + if (OB_INVALID_ID == key_id) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected key id.", K(ret)); + } else if (OB_FAIL(sql.assign_fmt("delete FROM %s where key_id = %ld", OB_ALL_NCOMP_DLL_TNAME, key_id))) { + LOG_WARN("delete from __all_ncomp_dll table failed.", K(ret), K(key_id)); + } else { + if (OB_FAIL(trans.write(exec_tenant_id, sql.ptr(), affected_rows))) { + LOG_WARN("execute query failed", K(ret), K(sql)); + } else { + // do nothing + LOG_INFO("succ to delete dll", K(key_id), K(tenant_id), K(affected_rows)); + } + } + } + + return ret; +} + +} +} \ No newline at end of file diff --git a/src/pl/ob_pl_persistent.h b/src/pl/ob_pl_persistent.h new file mode 100644 index 0000000000..2a271ab000 --- /dev/null +++ b/src/pl/ob_pl_persistent.h @@ -0,0 +1,147 @@ +/** + * Copyright (c) 2023 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ + +#ifndef OCEANBASE_PL_ROUTINE_STORAGE_H_ +#define OCEANBASE_PL_ROUTINE_STORAGE_H_ + +#include "share/ob_define.h" +#include "lib/mysqlclient/ob_isql_client.h" +#include "ob_pl_stmt.h" + +namespace oceanbase +{ + +namespace common +{ +class ObIAllocator; +class ObISQLClient; +class ObMySQLTransaction; +} + +namespace share +{ +class ObDMLSqlSplicer; +} + +namespace pl +{ + +enum ObPLArchType +{ + OB_INVALID_ARCH_TYPE = -1, + OB_X86_ARCH_TYPE, + OB_ARM_ARCH_TYPE, +}; + +class ObRoutinePersistentInfo +{ +public: + enum ObPLOperation + { + NONE = 0, + INSERT, + UPDATE, + SUCC, + }; + + ObRoutinePersistentInfo() + : tenant_id_(OB_INVALID_ID), + database_id_(OB_INVALID_ID), + compile_db_id_(OB_INVALID_ID), + key_id_(OB_INVALID_ID), +#if defined(__aarch64__) + arch_type_(ObPLArchType::OB_ARM_ARCH_TYPE) +#else + arch_type_(ObPLArchType::OB_X86_ARCH_TYPE) +#endif + {} + ObRoutinePersistentInfo(uint64_t tenant_id, + uint64_t database_id, + uint64_t compile_db_id, + uint64_t key_id) + : tenant_id_(tenant_id), + database_id_(database_id), + compile_db_id_(compile_db_id), + key_id_(key_id), +#if defined(__aarch64__) + arch_type_(ObPLArchType::OB_ARM_ARCH_TYPE) +#else + arch_type_(ObPLArchType::OB_X86_ARCH_TYPE) +#endif + {} + + int64_t get_head_size() { return 1 + 1 + 2 + 2;/* 8bit flags + 8bit level + 8bit id + 8bit nums*/ } + int get_total_size(ObPLCompileUnit &unit, int32_t &total_len); + + int encode_header(char *buf, const int64_t len, int64_t &pos, + int8_t flags, const int8_t level, const int16_t id, const int16_t nums); + + int encode_payload(char *buf, int64_t len, int64_t &pos, const ObString &binary); + + int encode_dll(ObPLCompileUnit &unit, ObString &dll, int64_t &pos, + const int8_t level, const int16_t id); + + int decode_header(char *buf, const int64_t len, int64_t &pos, + int8_t &flags, int8_t &level, int16_t &id, int16_t &nums); + + int decode_payload(char *buf, int64_t len, int64_t &pos, ObString &binary); + + int decode_dll(ObSQLSessionInfo &session_info, + schema::ObSchemaGetterGuard &schema_guard, + ObExecEnv &exec_env, + ObPLCompileUnitAST &unit_ast, ObPLCompileUnit &unit, + char *buf, const int64_t len, int64_t &pos, + int8_t &level, int16_t &id); + + int gen_routine_storage_dml(const uint64_t exec_tenant_id, + ObDMLSqlSplicer &dml, + int64_t merge_version, + const ObString &binary); + + int check_dep_schema(ObSchemaGetterGuard &schema_guard, + const ObPLDependencyTable &dep_schema_objs, + int64_t merge_version, + bool &match); + + int read_dll_from_disk(ObSQLSessionInfo *session_info, + schema::ObSchemaGetterGuard &schema_guard, + ObExecEnv &exec_env, + ObPLCompileUnitAST &unit_ast, + ObPLCompileUnit &unit, + ObRoutinePersistentInfo::ObPLOperation &op); + + int insert_or_update_dll_to_disk(schema::ObSchemaGetterGuard &schema_guard, + const ObString &binary, + const ObRoutinePersistentInfo::ObPLOperation op); + + int process_storage_dll(ObIAllocator &alloc, + schema::ObSchemaGetterGuard &schema_guard, + ObPLCompileUnit &unit, + const ObRoutinePersistentInfo::ObPLOperation op); + + static int delete_dll_from_disk(common::ObISQLClient &trans, + uint64_t tenant_id, + uint64_t key_id); + +private: + uint64_t tenant_id_; + uint64_t database_id_; + uint64_t compile_db_id_; + uint64_t key_id_; + ObPLArchType arch_type_; +}; + +} + +} + +#endif \ No newline at end of file diff --git a/src/pl/ob_pl_resolver.cpp b/src/pl/ob_pl_resolver.cpp index dab66b8d20..f23ec57c1f 100644 --- a/src/pl/ob_pl_resolver.cpp +++ b/src/pl/ob_pl_resolver.cpp @@ -562,6 +562,8 @@ int ObPLResolver::resolve(const ObStmtNodeTree *parse_tree, ObPLFunctionAST &fun ObPLRoutineInfo *routine_info = NULL; if (OB_FAIL(resolve_routine_decl(parse_tree, func, routine_info, false))) { LOG_WARN("resolve routine declaration failed", K(parse_tree), K(ret)); + } else { + func.set_is_all_sql_stmt(false); } } break; @@ -570,6 +572,8 @@ int ObPLResolver::resolve(const ObStmtNodeTree *parse_tree, ObPLFunctionAST &fun // must be nested routine, because udt member is process in package ast resolve if (OB_FAIL(resolve_routine_def(parse_tree, func, false))) { LOG_WARN("resolve procedure definition failed", K(parse_tree), K(ret)); + } else { + func.set_is_all_sql_stmt(false); } } break; diff --git a/src/pl/pl_cache/ob_pl_cache_mgr.cpp b/src/pl/pl_cache/ob_pl_cache_mgr.cpp index e6677fd7f7..972c2ff518 100644 --- a/src/pl/pl_cache/ob_pl_cache_mgr.cpp +++ b/src/pl/pl_cache/ob_pl_cache_mgr.cpp @@ -81,7 +81,10 @@ int ObPLCacheMgr::get_pl_cache(ObPlanCache *lib_cache, ObCacheObjGuard& guard, O int ret = OB_SUCCESS; ObGlobalReqTimeService::check_req_timeinfo(); pc_ctx.handle_id_ = guard.get_ref_handle(); - if (OB_FAIL(get_pl_object(lib_cache, pc_ctx, guard))) { + if (OB_NOT_NULL(pc_ctx.session_info_) && + false == pc_ctx.session_info_->get_local_ob_enable_pl_cache()) { + // do nothing + } else if (OB_FAIL(get_pl_object(lib_cache, pc_ctx, guard))) { PL_CACHE_LOG(DEBUG, "fail to get plan", K(ret)); } else if (OB_ISNULL(guard.get_cache_obj())) { ret = OB_ERR_UNEXPECTED; @@ -133,6 +136,9 @@ int ObPLCacheMgr::add_pl_cache(ObPlanCache *lib_cache, ObILibCacheObject *pl_obj if (OB_ISNULL(lib_cache)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("lib cache is null"); + } else if (OB_NOT_NULL(pc_ctx.session_info_) && + false == pc_ctx.session_info_->get_local_ob_enable_pl_cache()) { + // do nothing } else if (OB_ISNULL(pl_object)) { ret = OB_INVALID_ARGUMENT; PL_CACHE_LOG(WARN, "invalid physical plan", K(ret)); diff --git a/src/rootserver/ob_ddl_operator.cpp b/src/rootserver/ob_ddl_operator.cpp index 5d69db843f..f47b8dd1b2 100644 --- a/src/rootserver/ob_ddl_operator.cpp +++ b/src/rootserver/ob_ddl_operator.cpp @@ -79,6 +79,7 @@ #include "share/schema/ob_mview_info.h" #include "share/schema/ob_mview_refresh_stats_params.h" #include "storage/mview/ob_mview_sched_job_utils.h" +#include "pl/ob_pl_persistent.h" namespace oceanbase { @@ -8487,6 +8488,7 @@ int ObDDLOperator::drop_routine(const ObRoutineInfo &routine_info, routine_info, new_schema_version, trans, ddl_stmt_str))) { LOG_WARN("drop routine info failed", K(routine_info), K(ret)); } + OZ (pl::ObRoutinePersistentInfo::delete_dll_from_disk(trans, routine_info.get_tenant_id(), routine_info.get_routine_id())); OZ (ObDependencyInfo::delete_schema_object_dependency(trans, routine_info.get_tenant_id(), routine_info.get_routine_id(), new_schema_version, @@ -8820,21 +8822,27 @@ int ObDDLOperator::drop_package(const ObPackageInfo &package_info, new_schema_version, trans))) { LOG_WARN("drop package body info failed", K(package_body_info), K(ret)); } - } else { + } + if (OB_SUCC(ret)) { // package spec OZ (ObDependencyInfo::delete_schema_object_dependency(trans, tenant_id, package_info.get_package_id(), new_schema_version, package_info.get_object_type())); + OZ (pl::ObRoutinePersistentInfo::delete_dll_from_disk(trans, tenant_id, package_info.get_package_id())); if (OB_NOT_NULL(package_body_info)) { OZ (ObDependencyInfo::delete_schema_object_dependency(trans, tenant_id, package_body_info->get_package_id(), new_schema_version, package_body_info->get_object_type())); + OZ (pl::ObRoutinePersistentInfo::delete_dll_from_disk(trans, tenant_id, package_body_info->get_package_id())); } } + } else { + OZ (pl::ObRoutinePersistentInfo::delete_dll_from_disk(trans, tenant_id, package_info.get_package_id())); } } + if (OB_SUCC(ret)) { if (OB_FAIL(schema_service_.gen_new_schema_version(tenant_id, new_schema_version))) { LOG_WARN("fail to gen new schema_version", K(ret), K(tenant_id)); @@ -9004,6 +9012,10 @@ int ObDDLOperator::drop_trigger(const ObTriggerInfo &trigger_info, trigger_info.get_trigger_id(), new_schema_version, trigger_info.get_object_type())); + OZ (pl::ObRoutinePersistentInfo::delete_dll_from_disk(trans, tenant_id, + share::schema::ObTriggerInfo::get_trigger_spec_package_id(trigger_info.get_trigger_id()))); + OZ (pl::ObRoutinePersistentInfo::delete_dll_from_disk(trans, tenant_id, + share::schema::ObTriggerInfo::get_trigger_body_package_id(trigger_info.get_trigger_id()))); if (OB_SUCC(ret) && !trigger_info.is_system_type() && is_update_table_schema_version) { uint64_t base_table_id = trigger_info.get_base_object_id(); OZ (schema_service->get_table_sql_service().update_data_table_schema_version(trans, @@ -9502,6 +9514,22 @@ int ObDDLOperator::drop_udt(const ObUDTTypeInfo &udt_info, trans, ddl_stmt_str))) { LOG_WARN("drop udt info failed", K(udt_info), K(ret)); } + if (OB_SUCC(ret)) { + if (udt_info.is_object_spec_ddl() && + OB_INVALID_ID != ObUDTObjectType::mask_object_id(udt_info.get_object_spec_id(tenant_id))) { + OZ (pl::ObRoutinePersistentInfo::delete_dll_from_disk(trans, tenant_id, + ObUDTObjectType::mask_object_id(udt_info.get_object_spec_id(tenant_id)))); + if (udt_info.has_type_body() && + OB_INVALID_ID != ObUDTObjectType::mask_object_id(udt_info.get_object_body_id(tenant_id))) { + OZ (pl::ObRoutinePersistentInfo::delete_dll_from_disk(trans, tenant_id, + ObUDTObjectType::mask_object_id(udt_info.get_object_body_id(tenant_id)))); + } + } else if (udt_info.is_object_body_ddl() && + OB_INVALID_ID != ObUDTObjectType::mask_object_id(udt_info.get_object_body_id(tenant_id))) { + OZ (pl::ObRoutinePersistentInfo::delete_dll_from_disk(trans, tenant_id, + ObUDTObjectType::mask_object_id(udt_info.get_object_body_id(tenant_id)))); + } + } if (OB_FAIL(ret)) { } else if (udt_info.is_object_spec_ddl() diff --git a/src/share/inner_table/ob_inner_table_schema.451_500.cpp b/src/share/inner_table/ob_inner_table_schema.451_500.cpp index d6cb4d3840..32c1c5dd7b 100644 --- a/src/share/inner_table/ob_inner_table_schema.451_500.cpp +++ b/src/share/inner_table/ob_inner_table_schema.451_500.cpp @@ -10721,6 +10721,192 @@ int ObInnerTableSchema::all_clone_job_history_schema(ObTableSchema &table_schema return ret; } +int ObInnerTableSchema::all_ncomp_dll_schema(ObTableSchema &table_schema) +{ + int ret = OB_SUCCESS; + uint64_t column_id = OB_APP_MIN_COLUMN_ID - 1; + + //generated fields: + table_schema.set_tenant_id(OB_SYS_TENANT_ID); + table_schema.set_tablegroup_id(OB_SYS_TABLEGROUP_ID); + table_schema.set_database_id(OB_SYS_DATABASE_ID); + table_schema.set_table_id(OB_ALL_NCOMP_DLL_TID); + table_schema.set_rowkey_split_pos(0); + table_schema.set_is_use_bloomfilter(false); + table_schema.set_progressive_merge_num(0); + table_schema.set_rowkey_column_num(4); + table_schema.set_load_type(TABLE_LOAD_TYPE_IN_DISK); + table_schema.set_table_type(SYSTEM_TABLE); + table_schema.set_index_type(INDEX_TYPE_IS_NOT); + table_schema.set_def_type(TABLE_DEF_TYPE_INTERNAL); + + if (OB_SUCC(ret)) { + if (OB_FAIL(table_schema.set_table_name(OB_ALL_NCOMP_DLL_TNAME))) { + LOG_ERROR("fail to set table_name", K(ret)); + } + } + + if (OB_SUCC(ret)) { + if (OB_FAIL(table_schema.set_compress_func_name(OB_DEFAULT_COMPRESS_FUNC_NAME))) { + LOG_ERROR("fail to set compress_func_name", K(ret)); + } + } + table_schema.set_part_level(PARTITION_LEVEL_ZERO); + table_schema.set_charset_type(ObCharset::get_default_charset()); + table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset())); + + if (OB_SUCC(ret)) { + ObObj gmt_create_default; + ObObj gmt_create_default_null; + + gmt_create_default.set_ext(ObActionFlag::OP_DEFAULT_NOW_FLAG); + gmt_create_default_null.set_null(); + ADD_COLUMN_SCHEMA_TS_T("gmt_create", //column_name + ++column_id, //column_id + 0, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObTimestampType, //column_type + CS_TYPE_BINARY,//collation_type + 0, //column length + -1, //column_precision + 6, //column_scale + true,//is nullable + false, //is_autoincrement + false, //is_on_update_for_timestamp + gmt_create_default_null, + gmt_create_default) + } + + if (OB_SUCC(ret)) { + ObObj gmt_modified_default; + ObObj gmt_modified_default_null; + + gmt_modified_default.set_ext(ObActionFlag::OP_DEFAULT_NOW_FLAG); + gmt_modified_default_null.set_null(); + ADD_COLUMN_SCHEMA_TS_T("gmt_modified", //column_name + ++column_id, //column_id + 0, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObTimestampType, //column_type + CS_TYPE_BINARY,//collation_type + 0, //column length + -1, //column_precision + 6, //column_scale + true,//is nullable + false, //is_autoincrement + true, //is_on_update_for_timestamp + gmt_modified_default_null, + gmt_modified_default) + } + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("database_id", //column_name + ++column_id, //column_id + 1, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObIntType, //column_type + CS_TYPE_INVALID, //column_collation_type + sizeof(int64_t), //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("key_id", //column_name + ++column_id, //column_id + 2, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObIntType, //column_type + CS_TYPE_INVALID, //column_collation_type + sizeof(int64_t), //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("compile_db_id", //column_name + ++column_id, //column_id + 3, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObIntType, //column_type + CS_TYPE_INVALID, //column_collation_type + sizeof(int64_t), //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("arch_type", //column_name + ++column_id, //column_id + 4, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObIntType, //column_type + CS_TYPE_INVALID, //column_collation_type + sizeof(int64_t), //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("merge_version", //column_name + ++column_id, //column_id + 0, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObIntType, //column_type + CS_TYPE_INVALID, //column_collation_type + sizeof(int64_t), //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + + if (OB_SUCC(ret)) { + ObObj dll_default; + dll_default.set_lob_value(ObLongTextType, "", static_cast(strlen(""))); dll_default.set_collation_type(CS_TYPE_BINARY);; + ADD_COLUMN_SCHEMA_T("dll", //column_name + ++column_id, //column_id + 0, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObLongTextType, //column_type + CS_TYPE_BINARY, //column_collation_type + 0, //column_length + -1, //column_precision + -1, //column_scale + true, //is_nullable + false, //is_autoincrement + dll_default, + dll_default); //default_value + } + table_schema.set_index_using_type(USING_BTREE); + table_schema.set_row_store_type(ENCODING_ROW_STORE); + table_schema.set_store_format(OB_STORE_FORMAT_DYNAMIC_MYSQL); + table_schema.set_progressive_merge_round(1); + table_schema.set_storage_format_version(3); + table_schema.set_tablet_id(OB_ALL_NCOMP_DLL_TID); + table_schema.set_aux_lob_meta_tid(OB_ALL_NCOMP_DLL_AUX_LOB_META_TID); + table_schema.set_aux_lob_piece_tid(OB_ALL_NCOMP_DLL_AUX_LOB_PIECE_TID); + + table_schema.set_max_used_column_id(column_id); + return ret; +} + int ObInnerTableSchema::all_aux_stat_schema(ObTableSchema &table_schema) { int ret = OB_SUCCESS; diff --git a/src/share/inner_table/ob_inner_table_schema.50451_50500.cpp b/src/share/inner_table/ob_inner_table_schema.50451_50500.cpp index c8a5c19ed2..633bf294fd 100644 --- a/src/share/inner_table/ob_inner_table_schema.50451_50500.cpp +++ b/src/share/inner_table/ob_inner_table_schema.50451_50500.cpp @@ -4210,6 +4210,141 @@ int ObInnerTableSchema::all_clone_job_history_aux_lob_meta_schema(ObTableSchema return ret; } +int ObInnerTableSchema::all_ncomp_dll_aux_lob_meta_schema(ObTableSchema &table_schema) +{ + int ret = OB_SUCCESS; + uint64_t column_id = OB_APP_MIN_COLUMN_ID - 1; + + //generated fields: + table_schema.set_tenant_id(OB_SYS_TENANT_ID); + table_schema.set_tablegroup_id(OB_SYS_TABLEGROUP_ID); + table_schema.set_database_id(OB_SYS_DATABASE_ID); + table_schema.set_table_id(OB_ALL_NCOMP_DLL_AUX_LOB_META_TID); + table_schema.set_rowkey_split_pos(0); + table_schema.set_is_use_bloomfilter(false); + table_schema.set_progressive_merge_num(0); + table_schema.set_rowkey_column_num(2); + table_schema.set_load_type(TABLE_LOAD_TYPE_IN_DISK); + table_schema.set_table_type(AUX_LOB_META); + table_schema.set_index_type(INDEX_TYPE_IS_NOT); + table_schema.set_def_type(TABLE_DEF_TYPE_INTERNAL); + + if (OB_SUCC(ret)) { + if (OB_FAIL(table_schema.set_table_name(OB_ALL_NCOMP_DLL_AUX_LOB_META_TNAME))) { + LOG_ERROR("fail to set table_name", K(ret)); + } + } + + if (OB_SUCC(ret)) { + if (OB_FAIL(table_schema.set_compress_func_name(OB_DEFAULT_COMPRESS_FUNC_NAME))) { + LOG_ERROR("fail to set compress_func_name", K(ret)); + } + } + table_schema.set_part_level(PARTITION_LEVEL_ZERO); + table_schema.set_charset_type(ObCharset::get_default_charset()); + table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset())); + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("lob_id", //column_name + ++column_id, //column_id + 1, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObVarcharType, //column_type + CS_TYPE_BINARY, //column_collation_type + 16, //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("seq_id", //column_name + ++column_id, //column_id + 2, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObVarcharType, //column_type + CS_TYPE_BINARY, //column_collation_type + 8192, //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("binary_len", //column_name + ++column_id, //column_id + 0, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObUInt32Type, //column_type + CS_TYPE_INVALID, //column_collation_type + sizeof(uint32_t), //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("char_len", //column_name + ++column_id, //column_id + 0, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObUInt32Type, //column_type + CS_TYPE_INVALID, //column_collation_type + sizeof(uint32_t), //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("piece_id", //column_name + ++column_id, //column_id + 0, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObUInt64Type, //column_type + CS_TYPE_INVALID, //column_collation_type + sizeof(uint64_t), //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("lob_data", //column_name + ++column_id, //column_id + 0, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObVarcharType, //column_type + CS_TYPE_BINARY, //column_collation_type + 262144, //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + table_schema.set_index_using_type(USING_BTREE); + table_schema.set_row_store_type(ENCODING_ROW_STORE); + table_schema.set_store_format(OB_STORE_FORMAT_DYNAMIC_MYSQL); + table_schema.set_progressive_merge_round(1); + table_schema.set_storage_format_version(3); + table_schema.set_tablet_id(OB_ALL_NCOMP_DLL_AUX_LOB_META_TID); + table_schema.set_data_table_id(OB_ALL_NCOMP_DLL_TID); + + table_schema.set_max_used_column_id(column_id); + return ret; +} + int ObInnerTableSchema::all_aux_stat_aux_lob_meta_schema(ObTableSchema &table_schema) { int ret = OB_SUCCESS; diff --git a/src/share/inner_table/ob_inner_table_schema.60451_60500.cpp b/src/share/inner_table/ob_inner_table_schema.60451_60500.cpp index ee71bbd768..a9b082a256 100644 --- a/src/share/inner_table/ob_inner_table_schema.60451_60500.cpp +++ b/src/share/inner_table/ob_inner_table_schema.60451_60500.cpp @@ -2815,6 +2815,96 @@ int ObInnerTableSchema::all_clone_job_history_aux_lob_piece_schema(ObTableSchema return ret; } +int ObInnerTableSchema::all_ncomp_dll_aux_lob_piece_schema(ObTableSchema &table_schema) +{ + int ret = OB_SUCCESS; + uint64_t column_id = OB_APP_MIN_COLUMN_ID - 1; + + //generated fields: + table_schema.set_tenant_id(OB_SYS_TENANT_ID); + table_schema.set_tablegroup_id(OB_SYS_TABLEGROUP_ID); + table_schema.set_database_id(OB_SYS_DATABASE_ID); + table_schema.set_table_id(OB_ALL_NCOMP_DLL_AUX_LOB_PIECE_TID); + table_schema.set_rowkey_split_pos(0); + table_schema.set_is_use_bloomfilter(false); + table_schema.set_progressive_merge_num(0); + table_schema.set_rowkey_column_num(1); + table_schema.set_load_type(TABLE_LOAD_TYPE_IN_DISK); + table_schema.set_table_type(AUX_LOB_PIECE); + table_schema.set_index_type(INDEX_TYPE_IS_NOT); + table_schema.set_def_type(TABLE_DEF_TYPE_INTERNAL); + + if (OB_SUCC(ret)) { + if (OB_FAIL(table_schema.set_table_name(OB_ALL_NCOMP_DLL_AUX_LOB_PIECE_TNAME))) { + LOG_ERROR("fail to set table_name", K(ret)); + } + } + + if (OB_SUCC(ret)) { + if (OB_FAIL(table_schema.set_compress_func_name(OB_DEFAULT_COMPRESS_FUNC_NAME))) { + LOG_ERROR("fail to set compress_func_name", K(ret)); + } + } + table_schema.set_part_level(PARTITION_LEVEL_ZERO); + table_schema.set_charset_type(ObCharset::get_default_charset()); + table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset())); + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("piece_id", //column_name + ++column_id, //column_id + 1, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObUInt64Type, //column_type + CS_TYPE_INVALID, //column_collation_type + sizeof(uint64_t), //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("data_len", //column_name + ++column_id, //column_id + 0, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObUInt32Type, //column_type + CS_TYPE_INVALID, //column_collation_type + sizeof(uint32_t), //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + + if (OB_SUCC(ret)) { + ADD_COLUMN_SCHEMA("lob_data", //column_name + ++column_id, //column_id + 0, //rowkey_id + 0, //index_id + 0, //part_key_pos + ObVarcharType, //column_type + CS_TYPE_BINARY, //column_collation_type + 32, //column_length + -1, //column_precision + -1, //column_scale + false, //is_nullable + false); //is_autoincrement + } + table_schema.set_index_using_type(USING_BTREE); + table_schema.set_row_store_type(ENCODING_ROW_STORE); + table_schema.set_store_format(OB_STORE_FORMAT_DYNAMIC_MYSQL); + table_schema.set_progressive_merge_round(1); + table_schema.set_storage_format_version(3); + table_schema.set_tablet_id(OB_ALL_NCOMP_DLL_AUX_LOB_PIECE_TID); + table_schema.set_data_table_id(OB_ALL_NCOMP_DLL_TID); + + table_schema.set_max_used_column_id(column_id); + return ret; +} + int ObInnerTableSchema::all_aux_stat_aux_lob_piece_schema(ObTableSchema &table_schema) { int ret = OB_SUCCESS; diff --git a/src/share/inner_table/ob_inner_table_schema.h b/src/share/inner_table/ob_inner_table_schema.h index 0d47ceb6b9..39b45750a9 100644 --- a/src/share/inner_table/ob_inner_table_schema.h +++ b/src/share/inner_table/ob_inner_table_schema.h @@ -569,6 +569,7 @@ public: static int all_import_table_task_history_schema(share::schema::ObTableSchema &table_schema); static int all_clone_job_schema(share::schema::ObTableSchema &table_schema); static int all_clone_job_history_schema(share::schema::ObTableSchema &table_schema); + static int all_ncomp_dll_schema(share::schema::ObTableSchema &table_schema); static int all_aux_stat_schema(share::schema::ObTableSchema &table_schema); static int all_index_usage_info_schema(share::schema::ObTableSchema &table_schema); static int all_transfer_partition_task_schema(share::schema::ObTableSchema &table_schema); @@ -2402,6 +2403,7 @@ public: static int all_import_table_task_history_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema); static int all_clone_job_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema); static int all_clone_job_history_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema); + static int all_ncomp_dll_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema); static int all_aux_stat_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema); static int all_index_usage_info_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema); static int all_transfer_partition_task_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema); @@ -2686,6 +2688,7 @@ public: static int all_import_table_task_history_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema); static int all_clone_job_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema); static int all_clone_job_history_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema); + static int all_ncomp_dll_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema); static int all_aux_stat_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema); static int all_index_usage_info_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema); static int all_transfer_partition_task_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema); @@ -3179,6 +3182,7 @@ const schema_create_func sys_table_schema_creators [] = { ObInnerTableSchema::all_import_table_task_history_schema, ObInnerTableSchema::all_clone_job_schema, ObInnerTableSchema::all_clone_job_history_schema, + ObInnerTableSchema::all_ncomp_dll_schema, ObInnerTableSchema::all_aux_stat_schema, ObInnerTableSchema::all_index_usage_info_schema, ObInnerTableSchema::all_transfer_partition_task_schema, @@ -5207,6 +5211,7 @@ const uint64_t tenant_space_tables [] = { OB_ALL_IMPORT_TABLE_TASK_HISTORY_TID, OB_ALL_CLONE_JOB_TID, OB_ALL_CLONE_JOB_HISTORY_TID, + OB_ALL_NCOMP_DLL_TID, OB_ALL_AUX_STAT_TID, OB_ALL_INDEX_USAGE_INFO_TID, OB_ALL_TRANSFER_PARTITION_TASK_TID, @@ -6867,6 +6872,7 @@ const uint64_t tenant_space_tables [] = { OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_META_TID, OB_ALL_CLONE_JOB_AUX_LOB_META_TID, OB_ALL_CLONE_JOB_HISTORY_AUX_LOB_META_TID, + OB_ALL_NCOMP_DLL_AUX_LOB_META_TID, OB_ALL_AUX_STAT_AUX_LOB_META_TID, OB_ALL_INDEX_USAGE_INFO_AUX_LOB_META_TID, OB_ALL_TRANSFER_PARTITION_TASK_AUX_LOB_META_TID, @@ -7129,6 +7135,7 @@ const uint64_t tenant_space_tables [] = { OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_PIECE_TID, OB_ALL_CLONE_JOB_AUX_LOB_PIECE_TID, OB_ALL_CLONE_JOB_HISTORY_AUX_LOB_PIECE_TID, + OB_ALL_NCOMP_DLL_AUX_LOB_PIECE_TID, OB_ALL_AUX_STAT_AUX_LOB_PIECE_TID, OB_ALL_INDEX_USAGE_INFO_AUX_LOB_PIECE_TID, OB_ALL_TRANSFER_PARTITION_TASK_AUX_LOB_PIECE_TID, @@ -7689,6 +7696,7 @@ const char* const tenant_space_table_names [] = { OB_ALL_IMPORT_TABLE_TASK_HISTORY_TNAME, OB_ALL_CLONE_JOB_TNAME, OB_ALL_CLONE_JOB_HISTORY_TNAME, + OB_ALL_NCOMP_DLL_TNAME, OB_ALL_AUX_STAT_TNAME, OB_ALL_INDEX_USAGE_INFO_TNAME, OB_ALL_TRANSFER_PARTITION_TASK_TNAME, @@ -9349,6 +9357,7 @@ const char* const tenant_space_table_names [] = { OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_META_TNAME, OB_ALL_CLONE_JOB_AUX_LOB_META_TNAME, OB_ALL_CLONE_JOB_HISTORY_AUX_LOB_META_TNAME, + OB_ALL_NCOMP_DLL_AUX_LOB_META_TNAME, OB_ALL_AUX_STAT_AUX_LOB_META_TNAME, OB_ALL_INDEX_USAGE_INFO_AUX_LOB_META_TNAME, OB_ALL_TRANSFER_PARTITION_TASK_AUX_LOB_META_TNAME, @@ -9611,6 +9620,7 @@ const char* const tenant_space_table_names [] = { OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_PIECE_TNAME, OB_ALL_CLONE_JOB_AUX_LOB_PIECE_TNAME, OB_ALL_CLONE_JOB_HISTORY_AUX_LOB_PIECE_TNAME, + OB_ALL_NCOMP_DLL_AUX_LOB_PIECE_TNAME, OB_ALL_AUX_STAT_AUX_LOB_PIECE_TNAME, OB_ALL_INDEX_USAGE_INFO_AUX_LOB_PIECE_TNAME, OB_ALL_TRANSFER_PARTITION_TASK_AUX_LOB_PIECE_TNAME, @@ -12324,6 +12334,14 @@ LOBMapping const lob_aux_table_mappings [] = { ObInnerTableSchema::all_clone_job_history_aux_lob_piece_schema }, + { + OB_ALL_NCOMP_DLL_TID, + OB_ALL_NCOMP_DLL_AUX_LOB_META_TID, + OB_ALL_NCOMP_DLL_AUX_LOB_PIECE_TID, + ObInnerTableSchema::all_ncomp_dll_aux_lob_meta_schema, + ObInnerTableSchema::all_ncomp_dll_aux_lob_piece_schema + }, + { OB_ALL_AUX_STAT_TID, OB_ALL_AUX_STAT_AUX_LOB_META_TID, @@ -12417,12 +12435,12 @@ static inline int get_sys_table_lob_aux_schema(const uint64_t tid, } const int64_t OB_CORE_TABLE_COUNT = 4; -const int64_t OB_SYS_TABLE_COUNT = 281; +const int64_t OB_SYS_TABLE_COUNT = 282; const int64_t OB_VIRTUAL_TABLE_COUNT = 786; const int64_t OB_SYS_VIEW_COUNT = 854; -const int64_t OB_SYS_TENANT_TABLE_COUNT = 1926; +const int64_t OB_SYS_TENANT_TABLE_COUNT = 1927; const int64_t OB_CORE_SCHEMA_VERSION = 1; -const int64_t OB_BOOTSTRAP_SCHEMA_VERSION = 1929; +const int64_t OB_BOOTSTRAP_SCHEMA_VERSION = 1930; } // end namespace share } // end namespace oceanbase diff --git a/src/share/inner_table/ob_inner_table_schema.lob.cpp b/src/share/inner_table/ob_inner_table_schema.lob.cpp index f9ea8ee0d9..9ceb4f1b7e 100644 --- a/src/share/inner_table/ob_inner_table_schema.lob.cpp +++ b/src/share/inner_table/ob_inner_table_schema.lob.cpp @@ -21,7 +21,7 @@ inner_lob_map_t inner_lob_map; bool lob_mapping_init() { int ret = OB_SUCCESS; - if (OB_FAIL(inner_lob_map.create(284, ObModIds::OB_INNER_LOB_HASH_SET))) { + if (OB_FAIL(inner_lob_map.create(285, ObModIds::OB_INNER_LOB_HASH_SET))) { SERVER_LOG(WARN, "fail to create inner lob map", K(ret)); } else { for (int64_t i = 0; OB_SUCC(ret) && i < ARRAYSIZEOF(lob_aux_table_mappings); ++i) { diff --git a/src/share/inner_table/ob_inner_table_schema_constants.h b/src/share/inner_table/ob_inner_table_schema_constants.h index 2431a110f5..6ab79661f2 100644 --- a/src/share/inner_table/ob_inner_table_schema_constants.h +++ b/src/share/inner_table/ob_inner_table_schema_constants.h @@ -305,6 +305,7 @@ const uint64_t OB_ALL_IMPORT_TABLE_TASK_TID = 479; // "__all_import_table_task" const uint64_t OB_ALL_IMPORT_TABLE_TASK_HISTORY_TID = 480; // "__all_import_table_task_history" const uint64_t OB_ALL_CLONE_JOB_TID = 485; // "__all_clone_job" const uint64_t OB_ALL_CLONE_JOB_HISTORY_TID = 486; // "__all_clone_job_history" +const uint64_t OB_ALL_NCOMP_DLL_TID = 493; // "__all_ncomp_dll" const uint64_t OB_ALL_AUX_STAT_TID = 494; // "__all_aux_stat" const uint64_t OB_ALL_INDEX_USAGE_INFO_TID = 495; // "__all_index_usage_info" const uint64_t OB_ALL_TRANSFER_PARTITION_TASK_TID = 498; // "__all_transfer_partition_task" @@ -2138,6 +2139,7 @@ const uint64_t OB_ALL_IMPORT_TABLE_TASK_AUX_LOB_META_TID = 50479; // "__all_impo const uint64_t OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_META_TID = 50480; // "__all_import_table_task_history_aux_lob_meta" const uint64_t OB_ALL_CLONE_JOB_AUX_LOB_META_TID = 50485; // "__all_clone_job_aux_lob_meta" const uint64_t OB_ALL_CLONE_JOB_HISTORY_AUX_LOB_META_TID = 50486; // "__all_clone_job_history_aux_lob_meta" +const uint64_t OB_ALL_NCOMP_DLL_AUX_LOB_META_TID = 50493; // "__all_ncomp_dll_aux_lob_meta" const uint64_t OB_ALL_AUX_STAT_AUX_LOB_META_TID = 50494; // "__all_aux_stat_aux_lob_meta" const uint64_t OB_ALL_INDEX_USAGE_INFO_AUX_LOB_META_TID = 50495; // "__all_index_usage_info_aux_lob_meta" const uint64_t OB_ALL_TRANSFER_PARTITION_TASK_AUX_LOB_META_TID = 50498; // "__all_transfer_partition_task_aux_lob_meta" @@ -2422,6 +2424,7 @@ const uint64_t OB_ALL_IMPORT_TABLE_TASK_AUX_LOB_PIECE_TID = 60479; // "__all_imp const uint64_t OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_PIECE_TID = 60480; // "__all_import_table_task_history_aux_lob_piece" const uint64_t OB_ALL_CLONE_JOB_AUX_LOB_PIECE_TID = 60485; // "__all_clone_job_aux_lob_piece" const uint64_t OB_ALL_CLONE_JOB_HISTORY_AUX_LOB_PIECE_TID = 60486; // "__all_clone_job_history_aux_lob_piece" +const uint64_t OB_ALL_NCOMP_DLL_AUX_LOB_PIECE_TID = 60493; // "__all_ncomp_dll_aux_lob_piece" const uint64_t OB_ALL_AUX_STAT_AUX_LOB_PIECE_TID = 60494; // "__all_aux_stat_aux_lob_piece" const uint64_t OB_ALL_INDEX_USAGE_INFO_AUX_LOB_PIECE_TID = 60495; // "__all_index_usage_info_aux_lob_piece" const uint64_t OB_ALL_TRANSFER_PARTITION_TASK_AUX_LOB_PIECE_TID = 60498; // "__all_transfer_partition_task_aux_lob_piece" @@ -2902,6 +2905,7 @@ const char *const OB_ALL_IMPORT_TABLE_TASK_TNAME = "__all_import_table_task"; const char *const OB_ALL_IMPORT_TABLE_TASK_HISTORY_TNAME = "__all_import_table_task_history"; const char *const OB_ALL_CLONE_JOB_TNAME = "__all_clone_job"; const char *const OB_ALL_CLONE_JOB_HISTORY_TNAME = "__all_clone_job_history"; +const char *const OB_ALL_NCOMP_DLL_TNAME = "__all_ncomp_dll"; const char *const OB_ALL_AUX_STAT_TNAME = "__all_aux_stat"; const char *const OB_ALL_INDEX_USAGE_INFO_TNAME = "__all_index_usage_info"; const char *const OB_ALL_TRANSFER_PARTITION_TASK_TNAME = "__all_transfer_partition_task"; @@ -4735,6 +4739,7 @@ const char *const OB_ALL_IMPORT_TABLE_TASK_AUX_LOB_META_TNAME = "__all_import_ta const char *const OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_META_TNAME = "__all_import_table_task_history_aux_lob_meta"; const char *const OB_ALL_CLONE_JOB_AUX_LOB_META_TNAME = "__all_clone_job_aux_lob_meta"; const char *const OB_ALL_CLONE_JOB_HISTORY_AUX_LOB_META_TNAME = "__all_clone_job_history_aux_lob_meta"; +const char *const OB_ALL_NCOMP_DLL_AUX_LOB_META_TNAME = "__all_ncomp_dll_aux_lob_meta"; const char *const OB_ALL_AUX_STAT_AUX_LOB_META_TNAME = "__all_aux_stat_aux_lob_meta"; const char *const OB_ALL_INDEX_USAGE_INFO_AUX_LOB_META_TNAME = "__all_index_usage_info_aux_lob_meta"; const char *const OB_ALL_TRANSFER_PARTITION_TASK_AUX_LOB_META_TNAME = "__all_transfer_partition_task_aux_lob_meta"; @@ -5019,6 +5024,7 @@ const char *const OB_ALL_IMPORT_TABLE_TASK_AUX_LOB_PIECE_TNAME = "__all_import_t const char *const OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_PIECE_TNAME = "__all_import_table_task_history_aux_lob_piece"; const char *const OB_ALL_CLONE_JOB_AUX_LOB_PIECE_TNAME = "__all_clone_job_aux_lob_piece"; const char *const OB_ALL_CLONE_JOB_HISTORY_AUX_LOB_PIECE_TNAME = "__all_clone_job_history_aux_lob_piece"; +const char *const OB_ALL_NCOMP_DLL_AUX_LOB_PIECE_TNAME = "__all_ncomp_dll_aux_lob_piece"; const char *const OB_ALL_AUX_STAT_AUX_LOB_PIECE_TNAME = "__all_aux_stat_aux_lob_piece"; const char *const OB_ALL_INDEX_USAGE_INFO_AUX_LOB_PIECE_TNAME = "__all_index_usage_info_aux_lob_piece"; const char *const OB_ALL_TRANSFER_PARTITION_TASK_AUX_LOB_PIECE_TNAME = "__all_transfer_partition_task_aux_lob_piece"; diff --git a/src/share/inner_table/ob_inner_table_schema_def.py b/src/share/inner_table/ob_inner_table_schema_def.py index 4cec18caa6..da39a6a85a 100644 --- a/src/share/inner_table/ob_inner_table_schema_def.py +++ b/src/share/inner_table/ob_inner_table_schema_def.py @@ -6795,7 +6795,27 @@ def_table_schema(**all_clone_job_history_def) # 490: __all_routine_privilege # 491: __all_routine_privilege_history # 492: __wr_sqlstat -# 493: __all_ncomp_dll + +all_ncomp_dll = dict( + owner = 'hr351303', + table_name = '__all_ncomp_dll', + table_id = '493', + table_type = 'SYSTEM_TABLE', + gm_columns = ['gmt_create', 'gmt_modified'], + rowkey_columns = [ + ('database_id', 'int', 'false'), + ('key_id', 'int'), + ('compile_db_id', 'int'), + ('arch_type', 'int'), + ], + in_tenant_space = True, + + normal_columns = [ + ('merge_version', 'int'), + ('dll', 'longblob', 'true',''), + ], +) +def_table_schema(**all_ncomp_dll) def_table_schema( owner = 'zhenling.zzg', diff --git a/src/share/inner_table/table_id_to_name b/src/share/inner_table/table_id_to_name index e6b0bd89a4..e130dbc61f 100644 --- a/src/share/inner_table/table_id_to_name +++ b/src/share/inner_table/table_id_to_name @@ -331,6 +331,7 @@ # 480: __all_import_table_task_history # 485: __all_clone_job # 486: __all_clone_job_history +# 493: __all_ncomp_dll # 494: __all_aux_stat # 495: __all_index_usage_info # 498: __all_transfer_partition_task diff --git a/src/share/parameter/ob_parameter_seed.ipp b/src/share/parameter/ob_parameter_seed.ipp index 155d3800df..3dbc2e81c9 100644 --- a/src/share/parameter/ob_parameter_seed.ipp +++ b/src/share/parameter/ob_parameter_seed.ipp @@ -1810,6 +1810,10 @@ DEF_BOOL(enable_kv_ttl, OB_TENANT_PARAMETER, "False", DEF_INT(ttl_thread_score, OB_TENANT_PARAMETER, "0", "[0,100]", "the current work thread score of ttl thread. Range: [0,100] in integer. Especially, 0 means default value", ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE)); +DEF_BOOL(_enable_persistent_compiled_routine, OB_CLUSTER_PARAMETER, "true", + "specifies whether the feature of storeing dll to disk is turned on. " + "The default value is TRUE. Value: TRUE: turned on FALSE: turned off", + ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE)); DEF_STR_WITH_CHECKER(sql_protocol_min_tls_version, OB_CLUSTER_PARAMETER, "none", common::ObConfigSQLTlsVersionChecker, diff --git a/src/sql/ob_spi.cpp b/src/sql/ob_spi.cpp index b0090639e2..07c772fd0a 100644 --- a/src/sql/ob_spi.cpp +++ b/src/sql/ob_spi.cpp @@ -90,6 +90,46 @@ namespace sql } \ } while (0) +#define MAKE_EXPR_BUFFER(allocator, expr_idx, expr_count, result) \ + do { \ + CK (OB_NOT_NULL(ctx)); \ + CK (OB_NOT_NULL(ctx->func_)); \ + if (OB_SUCC(ret) && expr_idx != nullptr && expr_count > 0) { \ + int64_t alloc_size = expr_count * sizeof(decltype(*result)); \ + result = static_cast(allocator.alloc(alloc_size)); \ + if (OB_ISNULL(result)) { \ + ret = OB_ALLOCATE_MEMORY_FAILED; \ + LOG_WARN("failed to alloc memory for sql expr buffer", K(expr_count)); \ + } else { \ + MEMSET(result, 0, alloc_size); \ + for (int64_t i = 0; OB_SUCC(ret) && i < expr_count; ++i) { \ + if (OB_UNLIKELY(expr_idx[i] == OB_INVALID_ID)) { \ + ret = OB_ERR_UNEXPECTED; \ + LOG_WARN("invalid expr idx", K(expr_idx), K(expr_count), K(i)); \ + } else { \ + CK (OB_LIKELY(0 <= expr_idx[i] \ + && expr_idx[i] < ctx->func_->get_expressions().count())); \ + OX (result[i] = ctx->func_->get_expressions().at(expr_idx[i]);) \ + } \ + } \ + } \ + } \ + } while (0) + +#define GET_NULLABLE_EXPR_BY_IDX(ctx, expr_idx, result) \ + do { \ + CK (OB_NOT_NULL(ctx)); \ + CK (OB_NOT_NULL(ctx->func_)); \ + if (OB_FAIL(ret)) { \ + } else if (expr_idx == OB_INVALID_ID) { \ + result = nullptr; \ + } else { \ + CK (OB_LIKELY(0 <= expr_idx && \ + expr_idx < ctx->func_->get_expressions().count())); \ + OX (result = ctx->func_->get_expressions().at(expr_idx);) \ + } \ + } while (0) + int ObSPIService::PLPrepareResult::init(sql::ObSQLSessionInfo &session_info) { int ret = OB_SUCCESS; @@ -802,6 +842,22 @@ int ObSPIService::spi_convert_objparam(ObPLExecCtx *ctx, return ret; } +int ObSPIService::spi_calc_expr_at_idx(pl::ObPLExecCtx *ctx, + const int64_t expr_idx, + const int64_t result_idx, + ObObjParam *result) +{ + int ret = OB_SUCCESS; + CK (OB_NOT_NULL(ctx)); + CK (OB_NOT_NULL(ctx->func_)); + CK (expr_idx != OB_INVALID_ID); + CK (OB_LIKELY(0 <= expr_idx && expr_idx < ctx->func_->get_expressions().count())); + const ObSqlExpression *expr = nullptr; + OX (expr = ctx->func_->get_expressions().at(expr_idx)); + OZ (spi_calc_expr(ctx, expr, result_idx, result)); + return ret; +} + int ObSPIService::spi_calc_expr(ObPLExecCtx *ctx, const ObSqlExpression *expr, const int64_t result_idx, @@ -1199,6 +1255,23 @@ int ObSPIService::spi_set_package_variable( return ret; } +int ObSPIService::spi_set_variable_to_expr(ObPLExecCtx *ctx, + const int64_t expr_idx, + const ObObjParam *value, + bool is_default, + bool need_copy) +{ + int ret = OB_SUCCESS; + CK (OB_NOT_NULL(ctx)); + CK (OB_NOT_NULL(ctx->func_)); + CK (expr_idx != OB_INVALID_ID); + CK (OB_LIKELY(0 <= expr_idx && expr_idx < ctx->func_->get_expressions().count())); + const ObSqlExpression *expr = nullptr; + OX (expr = ctx->func_->get_expressions().at(expr_idx)); + OZ (spi_set_variable(ctx, expr, value, is_default, need_copy)); + return ret; +} + int ObSPIService::spi_set_variable(ObPLExecCtx *ctx, const ObSqlExpression* expr, const ObObjParam *value, @@ -2092,6 +2165,33 @@ int ObSPIService::spi_check_autonomous_trans(pl::ObPLExecCtx *ctx) return ret; } +int ObSPIService::spi_query_into_expr_idx(ObPLExecCtx *ctx, + const char *sql, + int64_t type, + const int64_t *into_exprs_idx, + int64_t into_count, + const ObDataType *column_types, + int64_t type_count, + const bool *exprs_not_null_flag, + const int64_t *pl_integer_ranges, + bool is_bulk, + bool is_type_record, + bool for_update) +{ + int ret = OB_SUCCESS; + + ObArenaAllocator alloc("SpiTemp", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID()); + const ObSqlExpression **into_exprs = nullptr; + + MAKE_EXPR_BUFFER(alloc, into_exprs_idx, into_count, into_exprs); + + OZ (spi_query(ctx, sql, type, into_exprs, into_count, column_types, + type_count, exprs_not_null_flag, pl_integer_ranges, is_bulk, + is_type_record, for_update)); + + return ret; +} + int ObSPIService::spi_query(ObPLExecCtx *ctx, const char *sql, int64_t type, @@ -2116,6 +2216,38 @@ int ObSPIService::spi_query(ObPLExecCtx *ctx, return ret; } +int ObSPIService::spi_execute_with_expr_idx(ObPLExecCtx *ctx, + const char *ps_sql, + int64_t type, + const int64_t *param_exprs_idx, + int64_t param_count, + const int64_t *into_exprs_idx, + int64_t into_count, + const ObDataType *column_types, + int64_t type_count, + const bool *exprs_not_null_flag, + const int64_t *pl_integer_ranges, + bool is_bulk, + bool is_forall, + bool is_type_record, + bool for_update) +{ + int ret = OB_SUCCESS; + + ObArenaAllocator alloc("SpiTemp", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID()); + const ObSqlExpression **param_exprs = nullptr; + const ObSqlExpression **into_exprs = nullptr; + + MAKE_EXPR_BUFFER(alloc, param_exprs_idx, param_count, param_exprs); + MAKE_EXPR_BUFFER(alloc, into_exprs_idx, into_count, into_exprs); + + OZ (spi_execute(ctx, ps_sql, type, param_exprs, param_count, into_exprs, + into_count, column_types, type_count, exprs_not_null_flag, + pl_integer_ranges, is_bulk, is_forall, is_type_record, + for_update)); + + return ret; +} int ObSPIService::spi_execute(ObPLExecCtx *ctx, const char *ps_sql, int64_t type, @@ -2714,11 +2846,11 @@ int ObSPIService::dynamic_out_params( } int ObSPIService::spi_execute_immediate(ObPLExecCtx *ctx, - const ObSqlExpression *sql, + const int64_t sql_idx, common::ObObjParam **params, const int64_t *params_mode, int64_t param_count, - const ObSqlExpression **into_exprs, + const int64_t *into_exprs_idx, int64_t into_count, const ObDataType *column_types, int64_t type_count, @@ -2733,9 +2865,13 @@ int ObSPIService::spi_execute_immediate(ObPLExecCtx *ctx, bool need_execute_sql = true; ObSQLSessionInfo *session = NULL; ObMySQLProxy *sql_proxy = NULL; + const ObSqlExpression *sql = nullptr; + const ObSqlExpression **into_exprs = nullptr; ObSqlString sql_str; + ObArenaAllocator allocator(GET_PL_MOD_STRING(PL_MOD_IDX::OB_PL_DYNAMIC_SQL_EXEC), OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID()); ObPLSubPLSqlTimeGuard guard(ctx); + HEAP_VAR(ObSPIResultSet, spi_result) { stmt::StmtType stmt_type = stmt::T_NONE; ObString ps_sql; @@ -2752,13 +2888,18 @@ int ObSPIService::spi_execute_immediate(ObPLExecCtx *ctx, stmt::StmtType saved_stmt_type = stmt::T_NONE; CK (OB_NOT_NULL(ctx), ctx->valid()); + CK (OB_NOT_NULL(ctx->func_)); CK ((OB_NOT_NULL(params) && param_count > 0) || (OB_ISNULL(params) && 0 == param_count)); CK (OB_NOT_NULL(session = ctx->exec_ctx_->get_my_session())); CK (OB_NOT_NULL(sql_proxy = ctx->exec_ctx_->get_sql_proxy())); + CK (sql_idx != OB_INVALID_ID); + CK (OB_LIKELY(0 <= sql_idx && sql_idx < ctx->func_->get_expressions().count())); + OX (sql = ctx->func_->get_expressions().at(sql_idx)); CK (OB_NOT_NULL(sql)); CK (OB_NOT_NULL(GCTX.sql_engine_)); OZ(spi_result.init(*session)); OX(saved_stmt_type = session->get_stmt_type()); + MAKE_EXPR_BUFFER(allocator, into_exprs_idx, into_count, into_exprs); // Step1: Prepare dynamic SQL! Only prepare once! OZ (prepare_dynamic(ctx, sql, @@ -3460,8 +3601,8 @@ int ObSPIService::spi_get_cursor_info(ObPLExecCtx *ctx, int64_t index, } int ObSPIService::spi_dynamic_open(ObPLExecCtx *ctx, - const ObSqlExpression *sql, - const ObSqlExpression **sql_param_exprs, + const int64_t sql_idx, + const int64_t *sql_param_exprs_idx, int64_t sql_param_count, uint64_t package_id, uint64_t routine_id, @@ -3477,8 +3618,13 @@ int ObSPIService::spi_dynamic_open(ObPLExecCtx *ctx, int64_t inner_into_cnt = 0; bool skip_locked = false; + CK (OB_NOT_NULL(ctx)); + CK (OB_NOT_NULL(ctx->func_)); + CK (sql_idx != OB_INVALID_ID); + CK (OB_LIKELY(0 <= sql_idx && sql_idx < ctx->func_->get_expressions().count())); + OZ (prepare_dynamic(ctx, - sql, + ctx->func_->get_expressions().at(sql_idx), allocator, false/*not returning*/, sql_param_count, @@ -3489,21 +3635,29 @@ int ObSPIService::spi_dynamic_open(ObPLExecCtx *ctx, hidden_rowid, inner_into_cnt, skip_locked)); - OZ (spi_cursor_open(ctx, - sql_param_count > 0 ? NULL : sql_str.ptr(), - ps_sql.ptr(),//trans to c-stype - stmt_type, - for_update, - hidden_rowid, - sql_param_exprs, - sql_param_count, - package_id, - routine_id, - cursor_index, - NULL/*formal_param_idxs*/, - NULL/*actual_param_exprs*/, - 0/*cursor_param_count*/, - skip_locked)); + + if (OB_SUCC(ret)) { + const ObSqlExpression **sql_param_exprs = nullptr; + ObArenaAllocator alloc("SpiTemp", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID()); + + MAKE_EXPR_BUFFER(alloc, sql_param_exprs_idx, sql_param_count, sql_param_exprs); + + OZ (spi_cursor_open(ctx, + sql_param_count > 0 ? NULL : sql_str.ptr(), + ps_sql.ptr(),//trans to c-stype + stmt_type, + for_update, + hidden_rowid, + sql_param_exprs, + sql_param_count, + package_id, + routine_id, + cursor_index, + NULL/*formal_param_idxs*/, + NULL/*actual_param_exprs*/, + 0/*cursor_param_count*/, + skip_locked)); + } return ret; } @@ -3577,6 +3731,40 @@ int ObSPIService::prepare_cursor_parameters(ObPLExecCtx *ctx, return ret; } +int ObSPIService::spi_cursor_open_with_param_idx(ObPLExecCtx *ctx, + const char *sql, + const char *ps_sql, + int64_t type, + bool for_update, + bool has_hidden_rowid, + const int64_t *sql_param_idx, + int64_t sql_param_count, + uint64_t package_id, + uint64_t routine_id, + int64_t cursor_index, + const int64_t *formal_param_idxs, + const int64_t *actual_param_idx, + int64_t cursor_param_count, + bool skip_locked) +{ + int ret = OB_SUCCESS; + + const ObSqlExpression **sql_param_exprs = nullptr; + const ObSqlExpression **actual_param_exprs = nullptr; + ObArenaAllocator alloc("SpiTemp", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID()); + + MAKE_EXPR_BUFFER(alloc, sql_param_idx, sql_param_count, sql_param_exprs); + MAKE_EXPR_BUFFER(alloc, actual_param_idx, cursor_param_count, + actual_param_exprs); + + OZ(spi_cursor_open(ctx, sql, ps_sql, type, for_update, has_hidden_rowid, + sql_param_exprs, sql_param_count, package_id, routine_id, + cursor_index, formal_param_idxs, actual_param_exprs, + cursor_param_count, skip_locked)); + + return ret; +} + int ObSPIService::spi_cursor_open(ObPLExecCtx *ctx, const char *sql, const char *ps_sql, @@ -4542,7 +4730,7 @@ int ObSPIService::spi_cursor_fetch(ObPLExecCtx *ctx, uint64_t package_id, uint64_t routine_id, int64_t cursor_index, - const ObSqlExpression **into_exprs, + const int64_t *into_exprs_idx, int64_t into_count, const ObDataType *column_types, int64_t type_count, @@ -4558,6 +4746,9 @@ int ObSPIService::spi_cursor_fetch(ObPLExecCtx *ctx, ObPLCursorInfo *cursor = NULL; ObObjParam cur_var; ObCusorDeclareLoc loc; + ObArenaAllocator alloc("SpiTemp", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID()); + const ObSqlExpression **into_exprs = nullptr; + MAKE_EXPR_BUFFER(alloc, into_exprs_idx, into_count, into_exprs); OZ (spi_get_cursor_info(ctx, package_id, routine_id, cursor_index, cursor, cur_var, loc)); if (OB_SUCC(ret) && OB_ISNULL(cursor)) { ret = OB_ERR_INVALID_CURSOR; @@ -4960,14 +5151,29 @@ if (OB_SUCC(ret)) { \ } int ObSPIService::spi_extend_collection(pl::ObPLExecCtx *ctx, - const ObSqlExpression *collection_expr, + const int64_t collection_expr_idx, int64_t column_count, - const ObSqlExpression *n_expr, - const ObSqlExpression *i_expr, + const int64_t n_expr_idx, + const int64_t i_expr_idx, uint64_t package_id) { int ret = OB_SUCCESS; - if (OB_ISNULL(ctx) + const ObSqlExpression *collection_expr = nullptr; + const ObSqlExpression *n_expr = nullptr; + const ObSqlExpression *i_expr = nullptr; + CK (OB_NOT_NULL(ctx)); + CK (OB_NOT_NULL(ctx->func_)); + CK (collection_expr_idx != OB_INVALID_ID); + CK (OB_LIKELY(0 <= collection_expr_idx && collection_expr_idx < ctx->func_->get_expressions().count())); + CK (n_expr_idx != OB_INVALID_ID); + CK (OB_LIKELY(0 <= n_expr_idx && n_expr_idx < ctx->func_->get_expressions().count())); + OX (collection_expr = ctx->func_->get_expressions().at(collection_expr_idx)); + OX (n_expr = ctx->func_->get_expressions().at(n_expr_idx)); + OX (GET_NULLABLE_EXPR_BY_IDX(ctx, i_expr_idx, i_expr)); + + if (OB_FAIL(ret)) { + // do nothing + }else if (OB_ISNULL(ctx) || OB_ISNULL(ctx->exec_ctx_) || OB_ISNULL(ctx->exec_ctx_->get_my_session()) || OB_ISNULL(collection_expr) @@ -5072,17 +5278,26 @@ int ObSPIService::spi_extend_collection(pl::ObPLExecCtx *ctx, } int ObSPIService::spi_raise_application_error(pl::ObPLExecCtx *ctx, - const ObSqlExpression *errcode_expr, - const ObSqlExpression *errmsg_expr) + const int64_t errcode_expr_idx, + const int64_t errmsg_expr_idx) { int ret = OB_SUCCESS; ObObjParam errcode_result; ObObjParam errmsg_result; ObPLSqlCodeInfo *sqlcode_info = NULL; ObSQLSessionInfo *session_info = NULL; + const ObSqlExpression *errcode_expr = nullptr; + const ObSqlExpression *errmsg_expr = nullptr; CK (OB_NOT_NULL(ctx), ctx->valid()); + CK (OB_NOT_NULL(ctx->func_)); CK (OB_NOT_NULL(session_info = ctx->exec_ctx_->get_my_session())); CK (OB_NOT_NULL(sqlcode_info = ctx->exec_ctx_->get_my_session()->get_pl_sqlcode_info())); + CK (errcode_expr_idx != OB_INVALID_ID); + CK (OB_LIKELY(0 <= errcode_expr_idx && errcode_expr_idx < ctx->func_->get_expressions().count())); + CK (errmsg_expr_idx != OB_INVALID_ID); + CK (OB_LIKELY(0 <= errmsg_expr_idx && errmsg_expr_idx < ctx->func_->get_expressions().count())); + OX (errcode_expr = ctx->func_->get_expressions().at(errcode_expr_idx)); + OX (errmsg_expr = ctx->func_->get_expressions().at(errmsg_expr_idx)); #define CALC(expr, type, result) \ do { \ @@ -5139,8 +5354,8 @@ int ObSPIService::spi_raise_application_error(pl::ObPLExecCtx *ctx, } int ObSPIService::spi_process_resignal(pl::ObPLExecCtx *ctx, - const ObSqlExpression *errcode_expr, - const ObSqlExpression *errmsg_expr, + const int64_t errcode_expr_idx, + const int64_t errmsg_expr_idx, const char *sql_state, int *error_code, const char *resignal_sql_state, @@ -5155,12 +5370,17 @@ int ObSPIService::spi_process_resignal(pl::ObPLExecCtx *ctx, int cur_err_code = OB_SUCCESS; static const uint32_t STR_LEN = 128; char err_msg[STR_LEN] = {0}; + const ObSqlExpression *errcode_expr = nullptr; + const ObSqlExpression *errmsg_expr = nullptr; CK (OB_NOT_NULL(ctx), ctx->valid()); + CK (OB_NOT_NULL(ctx->func_)); CK (OB_NOT_NULL(session_info = ctx->exec_ctx_->get_my_session())); CK (OB_NOT_NULL(sqlcode_info = ctx->exec_ctx_->get_my_session()->get_pl_sqlcode_info())); OX (wb = common::ob_get_tsi_warning_buffer()); CK (OB_NOT_NULL(error_code)); + OX (GET_NULLABLE_EXPR_BY_IDX(ctx, errcode_expr_idx, errcode_expr)); + OX (GET_NULLABLE_EXPR_BY_IDX(ctx, errmsg_expr_idx, errmsg_expr)); #define CALC(expr, type, result) \ do { \ @@ -5280,17 +5500,24 @@ int ObSPIService::spi_process_resignal(pl::ObPLExecCtx *ctx, } int ObSPIService::spi_trim_collection(pl::ObPLExecCtx *ctx, - const ObSqlExpression *collection_expr, + const int64_t collection_expr_idx, int64_t row_size, - const ObSqlExpression *n_expr) + const int64_t n_expr_idx) { int ret = OB_SUCCESS; + const ObSqlExpression *collection_expr = nullptr; + const ObSqlExpression *n_expr = nullptr; #ifndef OB_BUILD_ORACLE_PL - UNUSEDx(ctx, collection_expr, row_size, n_expr); + UNUSEDx(ctx, collection_expr_idx, row_size, n_expr_idx); #else UNUSED(row_size); CK (OB_NOT_NULL(ctx), OB_NOT_NULL(ctx->exec_ctx_)); + CK (OB_NOT_NULL(ctx->func_)); + CK (collection_expr_idx != OB_INVALID_ID); + CK (OB_LIKELY(0 <= collection_expr_idx && collection_expr_idx < ctx->func_->get_expressions().count())); + OX (collection_expr = ctx->func_->get_expressions().at(collection_expr_idx)); + OX (GET_NULLABLE_EXPR_BY_IDX(ctx, n_expr_idx, n_expr)); if (OB_SUCC(ret)) { ObObjParam result; ObPLCollection *table = NULL; @@ -5339,24 +5566,35 @@ int ObSPIService::spi_trim_collection(pl::ObPLExecCtx *ctx, } int ObSPIService::spi_delete_collection(pl::ObPLExecCtx *ctx, - const ObSqlExpression *collection_expr, + const int64_t collection_expr_idx, int64_t row_size, - const ObSqlExpression *m_expr, - const ObSqlExpression *n_expr) + const int64_t m_expr_idx, + const int64_t n_expr_idx) { int ret = OB_SUCCESS; #ifndef OB_BUILD_ORACLE_PL - UNUSEDx(ctx, collection_expr, row_size, m_expr, n_expr); + UNUSEDx(ctx, collection_expr_idx, row_size, m_expr_idx, n_expr_idx); #else UNUSED(row_size); + const ObSqlExpression *collection_expr = nullptr; + const ObSqlExpression *m_expr = nullptr; + const ObSqlExpression *n_expr = nullptr; CK (OB_NOT_NULL(ctx), OB_NOT_NULL(ctx->exec_ctx_)); + CK (OB_NOT_NULL(ctx->func_)); + CK (collection_expr_idx != OB_INVALID_ID); + CK (OB_LIKELY(0 <= collection_expr_idx && collection_expr_idx < ctx->func_->get_expressions().count())); + if (OB_SUCC(ret)) { ObObjParam result; ObPLCollection *table = NULL; int64_t m = OB_INVALID_INDEX; int64_t n = OB_INVALID_INDEX; + collection_expr = ctx->func_->get_expressions().at(collection_expr_idx); + OX (GET_NULLABLE_EXPR_BY_IDX(ctx, m_expr_idx, m_expr)); + OX (GET_NULLABLE_EXPR_BY_IDX(ctx, n_expr_idx, n_expr)); + OZ (spi_calc_expr(ctx, collection_expr, OB_INVALID_INDEX, &result)); CK (OB_LIKELY(result.get_type() == ObExtendType)); CK (OB_LIKELY(result.get_ext() != 0)); diff --git a/src/sql/ob_spi.h b/src/sql/ob_spi.h index 724edd739f..55da22b3b1 100644 --- a/src/sql/ob_spi.h +++ b/src/sql/ob_spi.h @@ -363,6 +363,10 @@ public: const ObSqlExpression *expr, const int64_t result_idx, ObObjParam *result); + static int spi_calc_expr_at_idx(pl::ObPLExecCtx *ctx, + const int64_t expr_idx, + const int64_t result_idx, + ObObjParam *result); static int spi_calc_subprogram_expr(pl::ObPLExecCtx *ctx, uint64_t package_id, @@ -400,11 +404,28 @@ public: static int check_and_deep_copy_result(ObIAllocator &alloc, const ObObj &src, ObObj &dst); + static int spi_set_variable_to_expr(pl::ObPLExecCtx *ctx, + const int64_t expr_idx, + const ObObjParam *value, + bool is_default = false, + bool need_copy = false); static int spi_set_variable(pl::ObPLExecCtx *ctx, const ObSqlExpression* expr, const ObObjParam *value, bool is_default = false, bool need_copy = false); + static int spi_query_into_expr_idx(pl::ObPLExecCtx *ctx, + const char* sql, + int64_t type, + const int64_t *into_exprs_idx = NULL, + int64_t into_count = 0, + const ObDataType *column_types = NULL, + int64_t type_count = 0, + const bool *exprs_not_null_flag = NULL, + const int64_t *pl_integer_ranges = NULL, + bool is_bulk = false, + bool is_type_record = false, + bool for_update = false); static int spi_query(pl::ObPLExecCtx *ctx, const char* sql, int64_t type, @@ -427,6 +448,21 @@ public: bool is_cursor, pl::ObPLBlockNS *secondary_namespace, ObSPIPrepareResult &prepare_result); + static int spi_execute_with_expr_idx(pl::ObPLExecCtx *ctx, + const char *ps_sql, + int64_t type, + const int64_t *param_exprs_idx, + int64_t param_count, + const int64_t *into_exprs_idx, + int64_t into_count, + const ObDataType *column_types, + int64_t type_count, + const bool *exprs_not_null_flag, + const int64_t *pl_integer_ranges, + bool is_bulk, + bool is_forall, + bool is_type_record, + bool for_update); static int spi_execute(pl::ObPLExecCtx *ctx, const char* ps_sql, int64_t type, @@ -444,11 +480,11 @@ public: bool for_update = false); static int spi_execute_immediate(pl::ObPLExecCtx *ctx, - const ObSqlExpression *sql, + const int64_t sql_dix, common::ObObjParam **params, const int64_t *params_mode, int64_t param_count, - const ObSqlExpression **into_exprs, + const int64_t *into_exprs_idx, int64_t into_count, const ObDataType *column_types, int64_t type_count, @@ -492,6 +528,21 @@ public: pl::ObPLCursorInfo *&cursor, common::ObObjParam &obj, ObCusorDeclareLoc loc); + static int spi_cursor_open_with_param_idx(pl::ObPLExecCtx *ctx, + const char *sql, + const char *ps_sql, + int64_t type, + bool for_update, + bool has_hidden_rowid, + const int64_t *sql_param_exprs, + int64_t sql_param_count, + uint64_t package_id, + uint64_t routine_id, + int64_t cursor_index, + const int64_t *formal_param_idxs, + const int64_t *actual_param_exprs, + int64_t cursor_param_count, + bool skip_locked); static int spi_cursor_open(pl::ObPLExecCtx *ctx, const char *sql, const char *ps_sql, @@ -514,8 +565,8 @@ public: bool for_update, bool has_hidden_rowid); static int spi_dynamic_open(pl::ObPLExecCtx *ctx, - const ObSqlExpression *sql, - const ObSqlExpression **sql_param_exprs, + const int64_t sql_idx, + const int64_t *sql_param_exprs_idx, int64_t sql_param_count, uint64_t package_id, uint64_t routine_id, @@ -530,7 +581,7 @@ public: uint64_t package_id, uint64_t routine_id, int64_t cursor_index, - const ObSqlExpression **into_exprs, + const int64_t *into_exprs, int64_t into_count, const ObDataType *column_types, int64_t type_count, @@ -557,10 +608,10 @@ public: int64_t *addr); static int spi_extend_collection(pl::ObPLExecCtx *ctx, - const ObSqlExpression *collection_expr, + const int64_t collection_expr_idx, int64_t column_count, - const ObSqlExpression *n_expr, - const ObSqlExpression *i_expr = NULL, + const int64_t n_expr_idx, + const int64_t i_expr_idx = OB_INVALID_ID, uint64_t package_id = OB_INVALID_ID); static int spi_set_collection(int64_t tenant_id, @@ -573,27 +624,27 @@ public: static int spi_reset_collection(pl::ObPLCollection *coll); static int spi_raise_application_error(pl::ObPLExecCtx *ctx, - const ObSqlExpression *errcode_expr, - const ObSqlExpression *errmsg_expr); + const int64_t errcode_expr_idx, + const int64_t errmsg_expr_idx); static int spi_process_resignal(pl::ObPLExecCtx *ctx, - const ObSqlExpression *errcode_expr, - const ObSqlExpression *errmsg_expr, + const int64_t errcode_expr, + const int64_t errmsg_expr, const char *sql_state, int *error_code, const char *resignal_sql_state, bool is_signal); static int spi_delete_collection(pl::ObPLExecCtx *ctx, - const ObSqlExpression *collection_expr, + const int64_t collection_expr_idx, int64_t row_size, - const ObSqlExpression *m_expr, - const ObSqlExpression *n_expr); + const int64_t m_expr_idx, + const int64_t n_expr_idx); static int spi_trim_collection(pl::ObPLExecCtx *ctx, - const ObSqlExpression *collection_expr, + const int64_t collection_expr_idx, int64_t row_size, - const ObSqlExpression *n_expr); + const int64_t n_expr_idx); static int acquire_spi_conn(ObMySQLProxy &sql_proxy, ObSQLSessionInfo &session_info, diff --git a/src/sql/resolver/cmd/ob_call_procedure_resolver.cpp b/src/sql/resolver/cmd/ob_call_procedure_resolver.cpp index 065f7064e1..88705f5496 100644 --- a/src/sql/resolver/cmd/ob_call_procedure_resolver.cpp +++ b/src/sql/resolver/cmd/ob_call_procedure_resolver.cpp @@ -305,8 +305,9 @@ int ObCallProcedureResolver::find_call_proc_info(ObCallProcedureStmt &stmt) ret = OB_ERR_UNEXPECTED != ret ? OB_SUCCESS : ret; } else { call_proc_info = static_cast(stmt.get_cacheobj_guard().get_cache_obj()); - CK (OB_NOT_NULL(call_proc_info)); - OX (stmt.set_call_proc_info(call_proc_info)); + if (OB_NOT_NULL(call_proc_info)) { + OX (stmt.set_call_proc_info(call_proc_info)); + } } return ret; } diff --git a/src/sql/session/ob_basic_session_info.cpp b/src/sql/session/ob_basic_session_info.cpp index 27aa82ecc1..feb1f4cb15 100644 --- a/src/sql/session/ob_basic_session_info.cpp +++ b/src/sql/session/ob_basic_session_info.cpp @@ -2329,6 +2329,12 @@ OB_INLINE int ObBasicSessionInfo::process_session_variable(ObSysVarClassType var OX (sys_vars_cache_.set_tx_read_only(int_val != 0)); break; } + case SYS_VAR_OB_ENABLE_PL_CACHE: { + int64_t int_val = 0; + OZ (val.get_int(int_val), val); + OX (sys_vars_cache_.set_ob_enable_pl_cache(int_val != 0)); + break; + } case SYS_VAR_OB_ENABLE_PLAN_CACHE: { int64_t int_val = 0; OZ (val.get_int(int_val), val); diff --git a/src/sql/session/ob_basic_session_info.h b/src/sql/session/ob_basic_session_info.h index c07f0de0c8..70729e2bc2 100644 --- a/src/sql/session/ob_basic_session_info.h +++ b/src/sql/session/ob_basic_session_info.h @@ -466,6 +466,7 @@ public: uint64_t get_local_auto_increment_increment() const; uint64_t get_local_auto_increment_offset() const; uint64_t get_local_last_insert_id() const; + bool get_local_ob_enable_pl_cache() const; bool get_local_ob_enable_plan_cache() const; bool get_local_ob_enable_sql_audit() const; bool get_local_cursor_sharing_mode() const; @@ -1589,6 +1590,7 @@ public: foreign_key_checks_(0), default_password_lifetime_(0), tx_read_only_(false), + ob_enable_pl_cache_(false), ob_enable_plan_cache_(false), optimizer_use_sql_plan_baselines_(false), optimizer_capture_sql_plan_baselines_(false), @@ -1646,6 +1648,7 @@ public: foreign_key_checks_ = 0; default_password_lifetime_ = 0; tx_read_only_ = false; + ob_enable_pl_cache_ = false; ob_enable_plan_cache_ = false; optimizer_use_sql_plan_baselines_ = false; optimizer_capture_sql_plan_baselines_ = false; @@ -1701,6 +1704,7 @@ public: foreign_key_checks_ == other.foreign_key_checks_ && default_password_lifetime_ == other.default_password_lifetime_ && tx_read_only_ == other.tx_read_only_ && + ob_enable_pl_cache_ == other.ob_enable_pl_cache_ && ob_enable_plan_cache_ == other.ob_enable_plan_cache_ && optimizer_use_sql_plan_baselines_ == other.optimizer_use_sql_plan_baselines_ && optimizer_capture_sql_plan_baselines_ == other.optimizer_capture_sql_plan_baselines_ && @@ -1866,6 +1870,7 @@ public: int64_t foreign_key_checks_; uint64_t default_password_lifetime_; bool tx_read_only_; + bool ob_enable_pl_cache_; bool ob_enable_plan_cache_; bool optimizer_use_sql_plan_baselines_; bool optimizer_capture_sql_plan_baselines_; @@ -1987,6 +1992,7 @@ private: DEF_SYS_VAR_CACHE_FUNCS(int64_t, foreign_key_checks); DEF_SYS_VAR_CACHE_FUNCS(uint64_t, default_password_lifetime); DEF_SYS_VAR_CACHE_FUNCS(bool, tx_read_only); + DEF_SYS_VAR_CACHE_FUNCS(bool, ob_enable_pl_cache); DEF_SYS_VAR_CACHE_FUNCS(bool, ob_enable_plan_cache); DEF_SYS_VAR_CACHE_FUNCS(bool, optimizer_use_sql_plan_baselines); DEF_SYS_VAR_CACHE_FUNCS(bool, optimizer_capture_sql_plan_baselines); @@ -2097,6 +2103,7 @@ private: bool inc_enable_rich_vector_format_:1; bool inc_ncharacter_set_connection_:1; bool inc_default_lob_inrow_threshold_:1; + bool inc_ob_enable_pl_cache_:1; }; }; }; @@ -2415,6 +2422,11 @@ inline uint64_t ObBasicSessionInfo::get_local_last_insert_id() const return sys_vars_cache_.get_last_insert_id(); } +inline bool ObBasicSessionInfo::get_local_ob_enable_pl_cache() const +{ + return sys_vars_cache_.get_ob_enable_pl_cache(); +} + inline bool ObBasicSessionInfo::get_local_ob_enable_plan_cache() const { return sys_vars_cache_.get_ob_enable_plan_cache(); diff --git a/tools/deploy/mysql_test/r/mysql/information_schema.result b/tools/deploy/mysql_test/r/mysql/information_schema.result index 2fa23223cc..7312a59562 100644 --- a/tools/deploy/mysql_test/r/mysql/information_schema.result +++ b/tools/deploy/mysql_test/r/mysql/information_schema.result @@ -547,6 +547,7 @@ select * from information_schema.tables where table_schema in ('oceanbase', 'mys | def | oceanbase | __all_mview_refresh_stats_params | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | | def | oceanbase | __all_mview_refresh_stats_sys_defaults | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | | def | oceanbase | __all_mview_refresh_stmt_stats | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | +| def | oceanbase | __all_ncomp_dll | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | | def | oceanbase | __all_optstat_global_prefs | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | | def | oceanbase | __all_optstat_user_prefs | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | | def | oceanbase | __all_ori_schema_version | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | @@ -1123,6 +1124,10 @@ select * from information_schema.statistics where table_schema in ('oceanbase', | def | oceanbase | __all_mview_refresh_stmt_stats | 0 | oceanbase | PRIMARY | 3 | mview_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_mview_refresh_stmt_stats | 0 | oceanbase | PRIMARY | 4 | retry_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_mview_refresh_stmt_stats | 0 | oceanbase | PRIMARY | 5 | step | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | +| def | oceanbase | __all_ncomp_dll | 0 | oceanbase | PRIMARY | 1 | database_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | +| def | oceanbase | __all_ncomp_dll | 0 | oceanbase | PRIMARY | 2 | key_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | +| def | oceanbase | __all_ncomp_dll | 0 | oceanbase | PRIMARY | 3 | compile_db_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | +| def | oceanbase | __all_ncomp_dll | 0 | oceanbase | PRIMARY | 4 | arch_type | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_optstat_global_prefs | 0 | oceanbase | PRIMARY | 1 | sname | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_optstat_user_prefs | 0 | oceanbase | PRIMARY | 1 | tenant_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_optstat_user_prefs | 0 | oceanbase | PRIMARY | 2 | table_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | @@ -1919,6 +1924,7 @@ select * from information_schema.tables where table_schema in ('oceanbase', 'mys | def | oceanbase | __all_mview_refresh_stats_params | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | | def | oceanbase | __all_mview_refresh_stats_sys_defaults | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | | def | oceanbase | __all_mview_refresh_stmt_stats | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | +| def | oceanbase | __all_ncomp_dll | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | | def | oceanbase | __all_optstat_global_prefs | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | | def | oceanbase | __all_optstat_user_prefs | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | | def | oceanbase | __all_ori_schema_version | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | | @@ -2698,6 +2704,10 @@ select * from information_schema.statistics where table_schema in ('oceanbase', | def | oceanbase | __all_mview_refresh_stmt_stats | 0 | oceanbase | PRIMARY | 3 | mview_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_mview_refresh_stmt_stats | 0 | oceanbase | PRIMARY | 4 | retry_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_mview_refresh_stmt_stats | 0 | oceanbase | PRIMARY | 5 | step | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | +| def | oceanbase | __all_ncomp_dll | 0 | oceanbase | PRIMARY | 1 | database_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | +| def | oceanbase | __all_ncomp_dll | 0 | oceanbase | PRIMARY | 2 | key_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | +| def | oceanbase | __all_ncomp_dll | 0 | oceanbase | PRIMARY | 3 | compile_db_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | +| def | oceanbase | __all_ncomp_dll | 0 | oceanbase | PRIMARY | 4 | arch_type | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_optstat_global_prefs | 0 | oceanbase | PRIMARY | 1 | sname | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_optstat_user_prefs | 0 | oceanbase | PRIMARY | 1 | tenant_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_optstat_user_prefs | 0 | oceanbase | PRIMARY | 2 | table_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | @@ -3501,6 +3511,10 @@ select * from information_schema.statistics where table_schema in ('oceanbase', | def | oceanbase | __all_mview_refresh_stmt_stats | 0 | oceanbase | PRIMARY | 3 | mview_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_mview_refresh_stmt_stats | 0 | oceanbase | PRIMARY | 4 | retry_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_mview_refresh_stmt_stats | 0 | oceanbase | PRIMARY | 5 | step | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | +| def | oceanbase | __all_ncomp_dll | 0 | oceanbase | PRIMARY | 1 | database_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | +| def | oceanbase | __all_ncomp_dll | 0 | oceanbase | PRIMARY | 2 | key_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | +| def | oceanbase | __all_ncomp_dll | 0 | oceanbase | PRIMARY | 3 | compile_db_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | +| def | oceanbase | __all_ncomp_dll | 0 | oceanbase | PRIMARY | 4 | arch_type | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_optstat_global_prefs | 0 | oceanbase | PRIMARY | 1 | sname | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_optstat_user_prefs | 0 | oceanbase | PRIMARY | 1 | tenant_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | | def | oceanbase | __all_optstat_user_prefs | 0 | oceanbase | PRIMARY | 2 | table_id | A | NULL | NULL | NULL | | BTREE | VALID | | YES | NULL | diff --git a/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/all_virtual_sys_parameter_stat.result b/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/all_virtual_sys_parameter_stat.result index bcdf0e4d6c..9b0f1c74e6 100644 --- a/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/all_virtual_sys_parameter_stat.result +++ b/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/all_virtual_sys_parameter_stat.result @@ -303,6 +303,7 @@ _enable_parallel_minor_merge _enable_parallel_redo_logging _enable_parallel_table_creation _enable_partition_level_retry +_enable_persistent_compiled_routine _enable_pkt_nio _enable_plan_cache_mem_diagnosis _enable_prefetch_limiting diff --git a/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/inner_table_overall.result b/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/inner_table_overall.result index 5d968a4388..ad939146c6 100644 --- a/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/inner_table_overall.result +++ b/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/inner_table_overall.result @@ -277,6 +277,7 @@ select 0xffffffffff & table_id, table_name, table_type, database_id, part_num fr 480 __all_import_table_task_history 0 201001 1 485 __all_clone_job 0 201001 1 486 __all_clone_job_history 0 201001 1 +493 __all_ncomp_dll 0 201001 1 494 __all_aux_stat 0 201001 1 495 __all_index_usage_info 0 201001 1 498 __all_transfer_partition_task 0 201001 1