diff --git a/deps/oblib/src/common/object/ob_object.cpp b/deps/oblib/src/common/object/ob_object.cpp index 41f59f6edc5deb8ba02fe2dc8d1f40d3a40093f6..3ea4e4fa9ad794d75f6881671e00cf3506c87e49 100644 --- a/deps/oblib/src/common/object/ob_object.cpp +++ b/deps/oblib/src/common/object/ob_object.cpp @@ -570,7 +570,30 @@ int ObObj::deep_copy(const ObObj& src, char* buf, const int64_t size, int64_t& p return ret; } -bool ObObj::can_compare(const ObObj& other) const +void* ObObj::get_deep_copy_obj_ptr() +{ + void * ptr = NULL; + if (ob_is_string_type(this->get_type())) { + // val_len_ == 0 is empty string, and it may point to unexpected address + // Therefore, reset it to NULL + if (val_len_ != 0) { + ptr = (void *)v_.string_; + } + } else if (ob_is_raw(this->get_type())) { + ptr = (void *)v_.string_; + } else if (ob_is_number_tc(this->get_type())) { + ptr = (void *)v_.nmb_digits_; + } else if (ob_is_rowid_tc(this->get_type())) { + ptr = (void *)v_.string_; + } else if (ob_is_lob_locator(this->get_type())) { + ptr = (void *)&v_.lob_locator_; + } else { + // do nothing + } + return ptr; +} + +bool ObObj::can_compare(const ObObj &other) const { obj_cmp_func cmp_func = NULL; return (is_min_value() || is_max_value() || other.is_min_value() || other.is_max_value() || diff --git a/deps/oblib/src/common/object/ob_object.h b/deps/oblib/src/common/object/ob_object.h index 374059d61b2f63f1059d25e519e1ecf023fa7cf3..e6505a266087b8ac85e0c643829a9b91e54ad00f 100644 --- a/deps/oblib/src/common/object/ob_object.h +++ b/deps/oblib/src/common/object/ob_object.h @@ -2084,10 +2084,11 @@ public: //@{ deep copy bool need_deep_copy() const; OB_INLINE int64_t get_deep_copy_size() const; - int deep_copy(const ObObj& src, char* buf, const int64_t size, int64_t& pos); - void set_data_ptr(void* data_ptr); - const void* get_data_ptr() const; - // return byte length + int deep_copy(const ObObj &src, char *buf, const int64_t size, int64_t &pos); + void* get_deep_copy_obj_ptr(); + void set_data_ptr(void *data_ptr); + const void *get_data_ptr() const; + //return byte length int64_t get_data_length() const; template diff --git a/deps/oblib/src/lib/ob_define.h b/deps/oblib/src/lib/ob_define.h index 664fde7f88d13b9db5098f5d22730e0947ace3d6..9e6984c05f0693c123a02369b069737830b897c7 100644 --- a/deps/oblib/src/lib/ob_define.h +++ b/deps/oblib/src/lib/ob_define.h @@ -818,6 +818,9 @@ const uint64_t OB_ORA_SYS_DATABASE_ID = 6; const uint64_t OB_ORA_LBACSYS_DATABASE_ID = 7; const uint64_t OB_ORA_AUDITOR_DATABASE_ID = 8; const char* const OB_ORA_PUBLIC_SCHEMA_NAME = "PUBLIC"; +// not actual database, only for using and creating outlines without specified database +const uint64_t OB_OUTLINE_DEFAULT_DATABASE_ID = 9; +const char* const OB_OUTLINE_DEFAULT_DATABASE_NAME = "__outline_default_db"; // sys unit associated const const uint64_t OB_SYS_UNIT_CONFIG_ID = 1; diff --git a/src/observer/mysql/ob_mysql_request_manager.h b/src/observer/mysql/ob_mysql_request_manager.h index a8b4a8355bff30c7ecc06d9726a1b1804838e796..29a88d7ddd7c7beeb6c8d1a0cea3f327635c3571 100644 --- a/src/observer/mysql/ob_mysql_request_manager.h +++ b/src/observer/mysql/ob_mysql_request_manager.h @@ -71,7 +71,7 @@ public: static const int32_t BATCH_RELEASE_COUNT = 50000; static const int32_t MAX_RELEASE_TIME = 5 * 1000; // 5ms static const int64_t US_PER_HOUR = 3600000000; - static const int64_t MAX_QUEUE_SIZE = 1000000; // 100w + static const int64_t MAX_QUEUE_SIZE = 10000000; // 10m static const int64_t MINI_MODE_MAX_QUEUE_SIZE = 100000; // 10w // start to eliminate when sql_audit more than 9 millions records static const int64_t HIGH_LEVEL_EVICT_SIZE = 9000000; // 900w diff --git a/src/observer/ob_inner_sql_connection.cpp b/src/observer/ob_inner_sql_connection.cpp index 5b507f790c06bb01992553ffdb70965883fecbea..a078ebea77ed99e154a268cf5fc032ca07e2c0ac 100644 --- a/src/observer/ob_inner_sql_connection.cpp +++ b/src/observer/ob_inner_sql_connection.cpp @@ -473,6 +473,10 @@ int ObInnerSQLConnection::process_retry( if (need_retry) { LOG_WARN("need retry, set ret to OB_SUCCESS", K(ret), K(last_ret), K(retry_cnt)); retry_info.set_last_query_retry_err(last_ret); + if (OB_ISNULL(extern_session_)) { + } else { + extern_session_->get_retry_info_for_update().set_last_query_retry_err(last_ret); + } ret = OB_SUCCESS; } return ret; diff --git a/src/observer/virtual_table/ob_tenant_virtual_outline.cpp b/src/observer/virtual_table/ob_tenant_virtual_outline.cpp index 89b6e34298a5084d193e9ab00fd5f390fe6a2ff0..c131a1b57b1f80a72d3754f17888192364149ed2 100644 --- a/src/observer/virtual_table/ob_tenant_virtual_outline.cpp +++ b/src/observer/virtual_table/ob_tenant_virtual_outline.cpp @@ -156,7 +156,10 @@ int ObTenantVirtualOutline::fill_cells(const ObOutlineInfo* outline_info) } case DATABASE_NAME: { DBInfo db_info; - if (OB_FAIL(database_infos_.get_refactored(outline_info->get_database_id(), db_info))) { + if (outline_info->get_database_id()==OB_OUTLINE_DEFAULT_DATABASE_ID) { + cells[cell_idx].set_varchar(OB_OUTLINE_DEFAULT_DATABASE_NAME); + cells[cell_idx].set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset())); + } else if (OB_FAIL(database_infos_.get_refactored(outline_info->get_database_id(), db_info))) { LOG_WARN("fail to ge value from database_infos", K(ret), K(outline_info->get_database_id())); } else { cells[cell_idx].set_varchar(db_info.db_name_); @@ -224,6 +227,10 @@ int ObTenantVirtualOutline::is_output_outline(const ObOutlineInfo* outline_info, LOG_WARN("parameter is NULL", K(ret), K(outline_info), K(schema_guard_)); } else if (outline_info->get_outline_content_str().empty()) { is_output = false; + } else if (outline_info->get_database_id() == OB_OUTLINE_DEFAULT_DATABASE_ID) { + // __outline_default_db is a logical table and has no physical schema. + // Therefore, always output this. + is_output = true; } else if (OB_FAIL(is_database_recycle(outline_info->get_database_id(), is_recycle))) { LOG_WARN("fail to judge database recycle", K(ret), KPC(outline_info)); } else { diff --git a/src/rootserver/ob_ddl_service.cpp b/src/rootserver/ob_ddl_service.cpp index e0bd292912d449409da3e6e380ac8d8433dab162..fcb992fca90c55d6beee5e332b7580c351169ff5 100644 --- a/src/rootserver/ob_ddl_service.cpp +++ b/src/rootserver/ob_ddl_service.cpp @@ -18807,13 +18807,15 @@ int ObDDLService::drop_outline(const obrpc::ObDropOutlineArg& arg) uint64_t database_id = OB_INVALID_ID; if (OB_SUCC(ret)) { bool database_exist = false; - if (OB_FAIL(schema_service_->check_database_exist(tenant_id, database_name, database_id, database_exist))) { - LOG_WARN("failed to check database exist!", - K(tenant_id), - K(database_name), - K(database_id), - K(database_exist), - K(ret)); + if (database_name == OB_OUTLINE_DEFAULT_DATABASE_NAME) { + database_id = OB_OUTLINE_DEFAULT_DATABASE_ID; + database_exist = true; + } else if (OB_FAIL(schema_service_->check_database_exist(tenant_id, + database_name, + database_id, + database_exist))) { + LOG_WARN("failed to check database exist!", K(tenant_id), K(database_name), + K(database_id), K(database_exist), K(ret)); } else if (!database_exist) { ret = OB_ERR_BAD_DATABASE; LOG_USER_ERROR(OB_ERR_BAD_DATABASE, database_name.length(), database_name.ptr()); diff --git a/src/rootserver/ob_root_service.cpp b/src/rootserver/ob_root_service.cpp index fcb4fd50c7edd50856367d181bf344a6ee73218d..7108678d242d79128709a940b1b38f97478f0a3a 100644 --- a/src/rootserver/ob_root_service.cpp +++ b/src/rootserver/ob_root_service.cpp @@ -6357,6 +6357,9 @@ int ObRootService::create_outline(const ObCreateOutlineArg& arg) const ObDatabaseSchema* db_schema = NULL; if (OB_FAIL(ddl_service_.get_tenant_schema_guard_with_version_in_inner_table(tenant_id, schema_guard))) { LOG_WARN("get schema guard in inner table failed", K(ret)); + } else if (database_name == OB_OUTLINE_DEFAULT_DATABASE_NAME) { + // if not specify database, set default database name and database id; + outline_info.set_database_id(OB_OUTLINE_DEFAULT_DATABASE_ID); } else if (OB_FAIL(schema_guard.get_database_schema(tenant_id, database_name, db_schema))) { LOG_WARN("get database schema failed", K(ret)); } else if (NULL == db_schema) { diff --git a/src/sql/engine/ob_physical_plan.h b/src/sql/engine/ob_physical_plan.h index 3b51d461819f31be6921a311b2392aaee873716f..fa82d47ce9211c59c12c30f64c382c320ff258ef 100644 --- a/src/sql/engine/ob_physical_plan.h +++ b/src/sql/engine/ob_physical_plan.h @@ -90,18 +90,8 @@ public: virtual void destroy(); virtual void reset(); - void set_is_last_open_succ(bool val) - { - stat_.is_last_open_succ_ = val; - } - bool is_last_open_succ() const - { - return stat_.is_last_open_succ_; - } - bool from_plan_baseline() const - { - return common::OB_INVALID_ID != stat_.bl_info_.plan_baseline_id_; - } + void set_is_last_exec_succ(bool val) { stat_.is_last_exec_succ_ = val; } + bool is_last_exec_succ() const { return stat_.is_last_exec_succ_; } const ObString& get_constructed_sql() const { return stat_.bl_info_.key_.constructed_sql_; diff --git a/src/sql/ob_result_set.cpp b/src/sql/ob_result_set.cpp index 1786b42795ed865bac5f1d27882f941c4487a263..9b5af87d9418ce7a5a2d2fd2a8fd5129fb10c2e0 100644 --- a/src/sql/ob_result_set.cpp +++ b/src/sql/ob_result_set.cpp @@ -128,12 +128,6 @@ OB_INLINE int ObResultSet::open_plan() } } } - - if (OB_FAIL(ret)) { - physical_plan_->set_is_last_open_succ(false); - } else { - physical_plan_->set_is_last_open_succ(true); - } } return ret; } @@ -143,6 +137,19 @@ int ObResultSet::sync_open() int ret = OB_SUCCESS; OZ(execute()); OZ(open()); + + if (OB_NOT_NULL(cmd_)) { + // cmd not set + } else if (ret == OB_NOT_INIT) { + // phy plan not init, do nothing + } else if (OB_ISNULL(physical_plan_)) { + LOG_WARN("empty physical plan"); + } else if (OB_FAIL(ret)) { + physical_plan_->set_is_last_exec_succ(false); + } else { + physical_plan_->set_is_last_exec_succ(true); + } + return ret; } @@ -478,12 +485,15 @@ OB_INLINE int ObResultSet::end_participant(const bool is_rollback) int ObResultSet::get_next_row(const common::ObNewRow*& row) { int& ret = errcode_; - if (OB_LIKELY(NULL != physical_plan_)) { // take this branch more frequently + // last_exec_succ default values is true + if (OB_LIKELY(NULL != physical_plan_)) { // take this branch more frequently if (OB_ISNULL(exec_result_)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("exec result is null", K(ret)); } else if (OB_FAIL(exec_result_->get_next_row(get_exec_context(), row))) { if (OB_ITER_END != ret) { + // marked last execute status + physical_plan_->set_is_last_exec_succ(false); LOG_WARN("get next row from exec result failed", K(ret)); } } else { diff --git a/src/sql/ob_sql.cpp b/src/sql/ob_sql.cpp index 8479a302c344668dd4bfa30ec2cf596ca6849f2e..b831c1988dfc279f23670cca39e5c8917555b9e9 100644 --- a/src/sql/ob_sql.cpp +++ b/src/sql/ob_sql.cpp @@ -1154,13 +1154,20 @@ inline int ObSql::handle_text_query(const ObString& stmt, ObSqlCtx& context, ObR } else { context.cur_sql_ = trimed_stmt; pc_ctx = new (pc_ctx) ObPlanCacheCtx(trimed_stmt, - false, /*is_ps_mode*/ - allocator, - context, - ectx, - tenant_id); - if (OB_FAIL(session.get_database_id(pc_ctx->bl_key_.db_id_))) { + false, /*is_ps_mode*/ + allocator, + context, + ectx, + tenant_id); + uint64_t database_id = OB_INVALID_ID; + + if (OB_FAIL(session.get_database_id(database_id))) { LOG_WARN("Failed to get database id", K(ret)); + } else if (FALSE_IT(pc_ctx->bl_key_.db_id_ = + (database_id == OB_INVALID_ID) ? + OB_OUTLINE_DEFAULT_DATABASE_ID: + database_id)) { + // do nothing } else if (!use_plan_cache) { if (context.multi_stmt_item_.is_batched_multi_stmt()) { ret = OB_BATCHED_MULTI_STMT_ROLLBACK; diff --git a/src/sql/plan_cache/ob_plan_cache.cpp b/src/sql/plan_cache/ob_plan_cache.cpp index f52de4a8abeacda3bf0505437c472430b69cada5..9141653825336603f531fc9e966ac6afad0c0eee 100644 --- a/src/sql/plan_cache/ob_plan_cache.cpp +++ b/src/sql/plan_cache/ob_plan_cache.cpp @@ -1606,8 +1606,13 @@ int ObPlanCache::construct_plan_cache_key(ObPlanCacheCtx& plan_ctx, ObjNameSpace int ObPlanCache::construct_plan_cache_key(ObSQLSessionInfo& session, ObjNameSpace ns, ObPlanCacheKey& pc_key) { int ret = OB_SUCCESS; - if (OB_FAIL(session.get_database_id(pc_key.db_id_))) { + uint64_t database_id = OB_INVALID_ID; + if (OB_FAIL(session.get_database_id(database_id))) { LOG_WARN("get database id failed", K(ret)); + } else if (FALSE_IT(pc_key.db_id_ = (database_id == OB_INVALID_ID) ? + OB_OUTLINE_DEFAULT_DATABASE_ID + : database_id)) { + // do nothing } else { pc_key.namespace_ = ns; pc_key.sys_vars_str_ = session.get_sys_var_in_pc_str(); diff --git a/src/sql/plan_cache/ob_plan_cache.h b/src/sql/plan_cache/ob_plan_cache.h index 733bdf9692b9e2b64875625340d2958274438d95..4e88c427463b3a2543c2ea8bc1f22f05f7b15c4f 100644 --- a/src/sql/plan_cache/ob_plan_cache.h +++ b/src/sql/plan_cache/ob_plan_cache.h @@ -294,11 +294,11 @@ public: int dump_all_objs() const; template int dump_deleted_objs(common::ObIArray& deleted_objs, const int64_t safe_timestamp) const; - static common::ObMemAttr get_mem_attr() + common::ObMemAttr get_mem_attr() { common::ObMemAttr attr; attr.label_ = ObNewModIds::OB_SQL_PLAN_CACHE; - attr.tenant_id_ = OB_INVALID_ID; + attr.tenant_id_ = tenant_id_; attr.ctx_id_ = ObCtxIds::PLAN_CACHE_CTX_ID; return attr; } diff --git a/src/sql/plan_cache/ob_plan_cache_util.h b/src/sql/plan_cache/ob_plan_cache_util.h index d73461827b04bdb7249934eb78eceee3f3f9b4f3..510b2d13943fdfde00257266a5cfc1f8723e4637 100644 --- a/src/sql/plan_cache/ob_plan_cache_util.h +++ b/src/sql/plan_cache/ob_plan_cache_util.h @@ -698,7 +698,7 @@ struct ObPlanStat { int64_t expected_worker_count_; int64_t outline_version_; int64_t outline_id_; - bool is_last_open_succ_; + bool is_last_exec_succ_; common::ObString sp_info_str_; common::ObString param_infos_; common::ObString sys_vars_str_; @@ -782,7 +782,7 @@ struct ObPlanStat { expected_worker_count_(-1), outline_version_(common::OB_INVALID_VERSION), outline_id_(common::OB_INVALID_ID), - is_last_open_succ_(true), + is_last_exec_succ_(true), is_evolution_(false), asyn_baseline_stat_(ASYN_NOTHING), is_bind_sensitive_(false), @@ -847,7 +847,7 @@ struct ObPlanStat { expected_worker_count_(rhs.expected_worker_count_), outline_version_(rhs.outline_version_), outline_id_(rhs.outline_id_), - is_last_open_succ_(rhs.is_last_open_succ_), + is_last_exec_succ_(rhs.is_last_exec_succ_), is_evolution_(rhs.is_evolution_), asyn_baseline_stat_(rhs.asyn_baseline_stat_), bl_info_(rhs.bl_info_), @@ -996,7 +996,7 @@ struct ObPlanStat { K_(execute_times), K_(disk_reads), K_(direct_writes), K_(buffer_gets), K_(application_wait_time), K_(concurrency_wait_time), K_(user_io_wait_time), K_(rows_processed), K_(elapsed_time), K_(cpu_time), K_(large_querys), K_(delayed_large_querys), K_(outline_version), K_(outline_id), K_(is_evolution), - K_(is_last_open_succ), K_(is_bind_sensitive), K_(is_bind_aware), K_(is_last_open_succ), K_(timeout_count), + K_(is_last_exec_succ), K_(is_bind_sensitive), K_(is_bind_aware), K_(is_last_exec_succ), K_(timeout_count), K_(bl_info)); }; diff --git a/src/sql/plan_cache/ob_plan_cache_value.cpp b/src/sql/plan_cache/ob_plan_cache_value.cpp index c340e7c9598e614742fca20c361dd8103f79908f..3635d4729eaef4bbd9d5a8487bb1d41d584f3ecc 100644 --- a/src/sql/plan_cache/ob_plan_cache_value.cpp +++ b/src/sql/plan_cache/ob_plan_cache_value.cpp @@ -151,10 +151,12 @@ ObPlanCacheValue::ObPlanCacheValue() int ObPlanCacheValue::init(ObPCVSet* pcv_set, const ObCacheObject* cache_obj, ObPlanCacheCtx& pc_ctx) { int ret = OB_SUCCESS; - ObMemAttr mem_attr = ObPlanCache::get_mem_attr(); - if (OB_ISNULL(pcv_set) || OB_ISNULL(cache_obj)) { + ObMemAttr mem_attr; + if (OB_ISNULL(pcv_set) || OB_ISNULL(cache_obj) || OB_ISNULL(pcv_set->get_plan_cache())) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid argument", K(pcv_set), K(cache_obj)); + } else if (FALSE_IT(mem_attr = pcv_set->get_plan_cache()->get_mem_attr())) { + // do nothing } else if (OB_ISNULL(pc_alloc_ = pcv_set->get_pc_allocator())) { LOG_WARN("invalid argument", K(pcv_set->get_pc_allocator())); } else if (OB_FAIL(outline_params_wrapper_.set_allocator(pc_alloc_, mem_attr))) { @@ -840,6 +842,20 @@ void ObPlanCacheValue::reset() not_param_info_.at(i).raw_text_.reset(); } } + + for (int64_t i = 0; i < not_param_var_.count(); i++) { + // deep-copy destory + // free v + ObObjParam param = not_param_var_.at(i).ps_param_; + void * ptr = param.get_deep_copy_obj_ptr(); + if (NULL == ptr){ + // do nothing + } else { + pc_alloc_->free(ptr); + not_param_var_.at(i).ps_param_.reset(); + } + } + if (NULL != outline_signature_.ptr()) { pc_alloc_->free(outline_signature_.ptr()); outline_signature_.reset(); @@ -851,6 +867,7 @@ void ObPlanCacheValue::reset() } not_param_info_.reset(); not_param_index_.reset(); + not_param_var_.reset(); neg_param_index_.reset(); param_charset_type_.reset(); sql_traits_.reset(); diff --git a/src/sql/plan_cache/ob_plan_set.cpp b/src/sql/plan_cache/ob_plan_set.cpp index b99d46bcc72f1d19358f36fbbcc7c09b33d21f0d..61d26473aee709af15209019034049db4e65cf4a 100644 --- a/src/sql/plan_cache/ob_plan_set.cpp +++ b/src/sql/plan_cache/ob_plan_set.cpp @@ -1195,8 +1195,9 @@ int ObSqlPlanSet::get_local_plan_direct(ObPlanCacheCtx& pc_ctx, bool& is_direct_ plan = local_plan_; } if (OB_SUCC(ret) && plan != NULL) { - int last_retry_err = pc_ctx.sql_ctx_.session_info_->get_retry_info().get_last_query_retry_err(); - if (plan->is_last_open_succ()) { + int last_retry_err = pc_ctx.sql_ctx_.session_info_ + ->get_retry_info().get_last_query_retry_err(); + if (plan->is_last_exec_succ()) { is_direct_local_plan = true; } else if (pc_ctx.sql_ctx_.session_info_->get_is_in_retry() && is_local_plan_opt_allowed(last_retry_err)) { is_direct_local_plan = true; diff --git a/src/sql/resolver/ddl/ob_outline_resolver.cpp b/src/sql/resolver/ddl/ob_outline_resolver.cpp index 421003de6fe9cfa421e2f3ed9b6a902066a8cd23..1f972f6c46175e20d0c3bf63ed80ea4f63a5a5a9 100644 --- a/src/sql/resolver/ddl/ob_outline_resolver.cpp +++ b/src/sql/resolver/ddl/ob_outline_resolver.cpp @@ -60,8 +60,7 @@ int ObOutlineResolver::resolve_outline_name(const ParseNode* node, ObString& db_ bool perserve_lettercase = share::is_oracle_mode() ? true : (mode != OB_LOWERCASE_AND_INSENSITIVE); if (NULL == db_name_node) { if (session_info_->get_database_name().empty()) { - ret = OB_ERR_NO_DB_SELECTED; - LOG_WARN("no database selected"); + db_name = OB_OUTLINE_DEFAULT_DATABASE_NAME; } else { db_name = session_info_->get_database_name(); }