From b54eb60074142aca3560dad9f5d198cb64295b20 Mon Sep 17 00:00:00 2001 From: YangEfei Date: Sat, 11 May 2024 04:15:46 +0000 Subject: [PATCH] [TABLELOCK] fix mysqltest about mysql lock function --- deps/oblib/src/lib/container/ob_mask_set2.h | 12 +-- .../code_generator/ob_static_engine_cg.cpp | 5 +- src/sql/optimizer/ob_join_order.cpp | 1 + src/sql/optimizer/ob_log_plan.cpp | 79 +++++++++++++++++++ src/sql/optimizer/ob_log_plan.h | 4 + src/sql/optimizer/ob_log_set.cpp | 15 +--- src/sql/optimizer/ob_log_table_scan.cpp | 19 +---- src/sql/optimizer/ob_log_table_scan.h | 4 +- src/sql/optimizer/ob_logical_operator.cpp | 17 ---- src/sql/optimizer/ob_optimizer_util.cpp | 12 ++- src/sql/optimizer/ob_optimizer_util.h | 2 +- src/sql/optimizer/ob_select_log_plan.cpp | 3 + 12 files changed, 108 insertions(+), 65 deletions(-) diff --git a/deps/oblib/src/lib/container/ob_mask_set2.h b/deps/oblib/src/lib/container/ob_mask_set2.h index 518bfcb103..e45d6ba55d 100644 --- a/deps/oblib/src/lib/container/ob_mask_set2.h +++ b/deps/oblib/src/lib/container/ob_mask_set2.h @@ -67,9 +67,9 @@ public: } if (OB_SUCCESS == ret) { if (!hit) { - ret = OB_MASK_SET_NO_NODE; - } - } + ret = OB_MASK_SET_NO_NODE; + } + } } return ret; } @@ -99,9 +99,9 @@ public: int mask(const T &key, bool &is_new_mask) { int ret = OB_SUCCESS; - bool tmp_new_mask = false; - if (!is_inited_) { - ret = OB_NOT_INIT; + bool tmp_new_mask = false; + if (!is_inited_) { + ret = OB_NOT_INIT; } else { bool hit = false; for (int64_t i = 0 ; OB_SUCCESS == ret && i < array_->count(); i++) { diff --git a/src/sql/code_generator/ob_static_engine_cg.cpp b/src/sql/code_generator/ob_static_engine_cg.cpp index 0d8aead827..e540492404 100644 --- a/src/sql/code_generator/ob_static_engine_cg.cpp +++ b/src/sql/code_generator/ob_static_engine_cg.cpp @@ -1811,7 +1811,10 @@ int ObStaticEngineCG::generate_recursive_union_all_spec(ObLogSet &op, ObRecursiv bool bulk_search = (min_cluster_version >= CLUSTER_VERSION_4_2_2_0 && min_cluster_version < CLUSTER_VERSION_4_3_0_0) || (min_cluster_version >= CLUSTER_VERSION_4_3_1_0); - bool add_extra_column = bulk_search && lib::is_oracle_mode() && op.is_breadth_search(); + bool add_extra_column = (NULL != op.get_identify_seq_expr()); + if (lib::is_oracle_mode() && op.is_breadth_search()) { + bulk_search &= add_extra_column; + } if (OB_UNLIKELY(spec.get_child_cnt() != 2) || OB_ISNULL(left = spec.get_child(0)) || OB_ISNULL(right = spec.get_child(1)) diff --git a/src/sql/optimizer/ob_join_order.cpp b/src/sql/optimizer/ob_join_order.cpp index 2edd4a2eb0..ee3a258dd3 100644 --- a/src/sql/optimizer/ob_join_order.cpp +++ b/src/sql/optimizer/ob_join_order.cpp @@ -8513,6 +8513,7 @@ int ObJoinOrder::generate_subquery_paths(PathHelper &helper) LOG_WARN("failed to add pushdown filters", K(ret)); } else { log_plan->set_is_subplan_scan(true); + log_plan->set_nonrecursive_plan_for_fake_cte(get_plan()->get_nonrecursive_plan_for_fake_cte()); if (parent_stmt->is_insert_stmt()) { log_plan->set_insert_stmt(static_cast(parent_stmt)); } diff --git a/src/sql/optimizer/ob_log_plan.cpp b/src/sql/optimizer/ob_log_plan.cpp index 93a7cd3acd..3be190f29e 100644 --- a/src/sql/optimizer/ob_log_plan.cpp +++ b/src/sql/optimizer/ob_log_plan.cpp @@ -4017,6 +4017,8 @@ int ObLogPlan::generate_subplan_for_query_ref(ObQueryRefRawExpr *query_ref, } else if (OB_ISNULL(logical_plan = opt_ctx.get_log_plan_factory().create(opt_ctx, *subquery))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("failed to create plan", K(ret), K(opt_ctx.get_query_ctx()->get_sql_stmt())); + } else if (FALSE_IT(logical_plan->set_nonrecursive_plan_for_fake_cte(get_nonrecursive_plan_for_fake_cte()))) { + // never reach } else if (OB_FAIL(SMART_CALL(static_cast(logical_plan)->generate_raw_plan()))) { LOG_WARN("failed to optimize sub-select", K(ret)); } else { @@ -12172,11 +12174,16 @@ int ObLogPlan::do_post_plan_processing() { int ret = OB_SUCCESS; ObLogicalOperator *root = NULL; + uint64_t min_cluster_version = GET_MIN_CLUSTER_VERSION(); if (OB_ISNULL(root = get_plan_root())) { ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected null", K(ret)); } else if (OB_FAIL(adjust_final_plan_info(root))) { LOG_WARN("failed to adjust parent-child relationship", K(ret)); + } else if ((((min_cluster_version >= CLUSTER_VERSION_4_2_2_0 && min_cluster_version < CLUSTER_VERSION_4_3_0_0) + || (min_cluster_version >= CLUSTER_VERSION_4_3_1_0)) && is_oracle_mode()) && + OB_FAIL(set_identify_seq_expr_for_recursive_union_all(root))) { + LOG_WARN("failed to set identify seq expr", K(ret)); } else if (OB_FAIL(update_re_est_cost(root))) { LOG_WARN("failed to re est cost", K(ret)); } else if (OB_FAIL(choose_duplicate_table_replica(root, @@ -12364,6 +12371,78 @@ int ObLogPlan::adjust_final_plan_info(ObLogicalOperator *&op) return ret; } +int ObLogPlan::set_identify_seq_expr_for_recursive_union_all(ObLogicalOperator *op) +{ + int ret = OB_SUCCESS; + if (OB_ISNULL(op)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected null", K(ret)); + } else if (LOG_SET == op->get_type() && static_cast(op)->is_recursive_union() && + static_cast(op)->is_breadth_search()) { + ObRawExpr *identify_seq_expr = NULL; + bool is_valid = true; + if (OB_FAIL(ObOptimizerUtil::allocate_identify_seq_expr(get_optimizer_context(), identify_seq_expr))) { + LOG_WARN("allocate identify seq expr failed", K(ret)); + } + for (int64_t i = 0; OB_SUCC(ret) && i < op->get_num_of_child(); i++) { + if (OB_FAIL(SMART_CALL(set_identify_seq_expr_for_fake_cte(op->get_child(i), + identify_seq_expr, + is_valid)))) { + LOG_WARN("failed to set identify seq expr", K(ret)); + } + } + if (OB_SUCC(ret) && is_valid) { + static_cast(op)->set_identify_seq_expr(identify_seq_expr); + } + } + for (int64_t i = 0; OB_SUCC(ret) && i < op->get_num_of_child(); i++) { + if (OB_FAIL(SMART_CALL(set_identify_seq_expr_for_recursive_union_all(op->get_child(i))))) { + LOG_WARN("failed to set identify seq expr", K(ret)); + } + } + return ret; +} + +int ObLogPlan::set_identify_seq_expr_for_fake_cte(ObLogicalOperator *op, + ObRawExpr *identify_seq_expr, + bool &is_valid) +{ + int ret = OB_SUCCESS; + if (OB_ISNULL(op) || OB_ISNULL(identify_seq_expr) || OB_ISNULL(op->get_parent())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected null", K(ret)); + } else if (op->get_contains_fake_cte()) { + if (op->is_plan_root()) { + // check whether the identify seq expr can be set to the output exprs of the plan root + if (LOG_SET == op->get_parent()->get_type() && + static_cast(op->get_parent())->is_recursive_union()) { + // do nothing + } else { + // fake cte is in an inline view, not supported + is_valid = false; + } + } + for (int64_t i = 0; OB_SUCC(ret) && i < op->get_num_of_child(); i++) { + if (OB_FAIL(SMART_CALL(set_identify_seq_expr_for_fake_cte(op->get_child(i), + identify_seq_expr, + is_valid)))) { + LOG_WARN("failed to set identify seq expr", K(ret)); + } + } + if (OB_SUCC(ret) && is_valid) { + if (LOG_TABLE_SCAN == op->get_type()) { + static_cast(op)->set_identify_seq_expr(identify_seq_expr); + } + if (op->is_plan_root()) { + if (OB_FAIL(op->get_output_exprs().push_back(identify_seq_expr))) { + LOG_WARN("failed to push back", K(ret)); + } + } + } + } + return ret; +} + /* * re-estimate cost for limit/join filter/parallel */ diff --git a/src/sql/optimizer/ob_log_plan.h b/src/sql/optimizer/ob_log_plan.h index 7a2c51add3..92fac8a4c4 100644 --- a/src/sql/optimizer/ob_log_plan.h +++ b/src/sql/optimizer/ob_log_plan.h @@ -252,6 +252,10 @@ public: int adjust_final_plan_info(ObLogicalOperator *&op); + int set_identify_seq_expr_for_recursive_union_all(ObLogicalOperator *op); + + int set_identify_seq_expr_for_fake_cte(ObLogicalOperator *op, ObRawExpr *expr, bool &is_valid); + int update_re_est_cost(ObLogicalOperator *op); int collect_table_location(ObLogicalOperator *op); diff --git a/src/sql/optimizer/ob_log_set.cpp b/src/sql/optimizer/ob_log_set.cpp index a83967a156..dc6c583209 100644 --- a/src/sql/optimizer/ob_log_set.cpp +++ b/src/sql/optimizer/ob_log_set.cpp @@ -565,20 +565,9 @@ int ObLogSet::get_op_exprs(ObIArray &all_exprs) LOG_WARN("failed to get exprs", K(ret)); } else if (is_recursive_union_ && get_stmt()->is_select_stmt()) { const ObSelectStmt *select_stmt = static_cast(get_stmt()); - uint64_t min_cluster_version = GET_MIN_CLUSTER_VERSION(); // 伪列的产生,search/cycle的伪列都要求在recursive union算子产生 - if (lib::is_oracle_mode() && is_breadth_search_ - && ((min_cluster_version >= CLUSTER_VERSION_4_2_2_0 - && min_cluster_version < CLUSTER_VERSION_4_3_0_0) - || (min_cluster_version >= CLUSTER_VERSION_4_3_1_0))) { - if (OB_ISNULL(identify_seq_expr_)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("identify seq exor is null", K(ret)); - } else if (OB_FAIL(all_exprs.push_back(identify_seq_expr_))) { - LOG_WARN("failed to push back expr", K(ret)); - } - } - if (OB_FAIL(ret)) { + if (NULL != identify_seq_expr_ && OB_FAIL(all_exprs.push_back(identify_seq_expr_))) { + LOG_WARN("failed to push back expr", K(ret)); } else if (OB_FAIL(append(all_exprs, select_stmt->get_cte_exprs()))) { LOG_WARN("fail to add cte exprs", K(ret)); } else { /*do nothing*/ } diff --git a/src/sql/optimizer/ob_log_table_scan.cpp b/src/sql/optimizer/ob_log_table_scan.cpp index 4e2c5b092a..d3bc84f93a 100644 --- a/src/sql/optimizer/ob_log_table_scan.cpp +++ b/src/sql/optimizer/ob_log_table_scan.cpp @@ -457,23 +457,8 @@ int ObLogTableScan::generate_access_exprs() LOG_WARN("failed to append exprs", K(ret)); } else { /*do nothing*/ } - uint64_t min_cluster_version = GET_MIN_CLUSTER_VERSION(); - if (OB_SUCC(ret) && lib::is_oracle_mode() && get_contains_fake_cte() - && ((min_cluster_version >= CLUSTER_VERSION_4_2_2_0 - && min_cluster_version < CLUSTER_VERSION_4_3_0_0) - || (min_cluster_version >= CLUSTER_VERSION_4_3_1_0))) { - ObLogSet *rcte_op = nullptr; - if (OB_FAIL(find_nearest_rcte_op(rcte_op))) { - LOG_WARN("fail to find recursive cte op", K(ret)); - } else if (OB_ISNULL(rcte_op_ = rcte_op)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("recursive cte op is NULL", K(ret)); - } else if (!rcte_op_->is_breadth_search()) { - //search depth do nothing - } else if (OB_ISNULL(identify_seq_expr_ = rcte_op->get_identify_seq_expr())) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("identify seq expr is NULL", K(ret)); - } else if (OB_FAIL(access_exprs_.push_back(identify_seq_expr_))) { + if (OB_SUCC(ret) && NULL != identify_seq_expr_) { + if (OB_FAIL(access_exprs_.push_back(identify_seq_expr_))) { LOG_WARN("fail to add identify seq expr", K(ret)); } } diff --git a/src/sql/optimizer/ob_log_table_scan.h b/src/sql/optimizer/ob_log_table_scan.h index c61a841c0d..4740db1eb7 100644 --- a/src/sql/optimizer/ob_log_table_scan.h +++ b/src/sql/optimizer/ob_log_table_scan.h @@ -125,7 +125,6 @@ public: tablet_id_type_(0), calc_part_id_expr_(NULL), trans_info_expr_(NULL), - rcte_op_(nullptr), identify_seq_expr_(nullptr), global_index_back_table_partition_info_(NULL), has_index_scan_filter_(false), @@ -554,8 +553,8 @@ public: inline void set_doc_id_index_table_id(const uint64_t doc_id_index_table_id) { doc_id_table_id_ = doc_id_index_table_id; } inline uint64_t get_doc_id_index_table_id() const { return doc_id_table_id_; } virtual int get_card_without_filter(double &card) override; - inline ObLogSet *get_rcte_op() { return rcte_op_; } inline ObRawExpr *get_identify_seq_expr() { return identify_seq_expr_; } + void set_identify_seq_expr(ObRawExpr *expr) { identify_seq_expr_ = expr; } private: // member functions //called when index_back_ set @@ -678,7 +677,6 @@ protected: // memeber variables ObRawExpr *trans_info_expr_; //for batch search recursive cte - ObLogSet *rcte_op_; ObRawExpr *identify_seq_expr_; // begin for global index lookup diff --git a/src/sql/optimizer/ob_logical_operator.cpp b/src/sql/optimizer/ob_logical_operator.cpp index 934086d8e2..d3061d35dd 100644 --- a/src/sql/optimizer/ob_logical_operator.cpp +++ b/src/sql/optimizer/ob_logical_operator.cpp @@ -3697,23 +3697,6 @@ int ObLogicalOperator::set_plan_root_output_exprs() uint64_t min_cluster_version = GET_MIN_CLUSTER_VERSION(); if (!sel_stmt->has_select_into() && OB_FAIL(sel_stmt->get_select_exprs(output_exprs_, is_unpivot))) { LOG_WARN("failed to get select exprs", K(ret)); - } else if (((min_cluster_version >= CLUSTER_VERSION_4_2_2_0 - && min_cluster_version < CLUSTER_VERSION_4_3_0_0) - || (min_cluster_version >= CLUSTER_VERSION_4_3_1_0)) - && is_oracle_mode() && OB_NOT_NULL(this->parent_) - && LOG_SET == this->parent_->type_) { - ObLogSet *set_op = static_cast(this->parent_); - if (this == this->parent_->child_[1] && - set_op->is_recursive_union() && set_op->is_breadth_search()) { - ObRawExpr *identify_seq_expr = nullptr; - if (OB_FAIL(ObOptimizerUtil::allocate_identify_seq_expr(get_plan(), identify_seq_expr))) { - LOG_WARN("allocate identify seq expr failed", K(ret)); - } else if (OB_FAIL(output_exprs_.push_back(identify_seq_expr))) { - LOG_WARN("failed to push identify seq expr into output", K(ret)); - } else { - set_op->set_identify_seq_expr(identify_seq_expr); - } - } } else { /*do nothing*/ } } else if (stmt->is_returning()) { const ObDelUpdStmt *del_upd_stmt = static_cast(stmt); diff --git a/src/sql/optimizer/ob_optimizer_util.cpp b/src/sql/optimizer/ob_optimizer_util.cpp index ad251dcd07..f571537ae2 100644 --- a/src/sql/optimizer/ob_optimizer_util.cpp +++ b/src/sql/optimizer/ob_optimizer_util.cpp @@ -8440,21 +8440,19 @@ int ObOptimizerUtil::allocate_group_id_expr(ObLogPlan *log_plan, ObRawExpr *&gro return ret; } -int ObOptimizerUtil::allocate_identify_seq_expr(ObLogPlan *log_plan, ObRawExpr *&identify_seq_expr) +int ObOptimizerUtil::allocate_identify_seq_expr(ObOptimizerContext &opt_ctx, ObRawExpr *&identify_seq_expr) { int ret = OB_SUCCESS; - ObOptimizerContext *opt_ctx = NULL; ObOpPseudoColumnRawExpr *tmp_identify_seq_expr = NULL; identify_seq_expr = NULL; - if (OB_ISNULL(log_plan) || OB_ISNULL(opt_ctx = &log_plan->get_optimizer_context()) - || OB_ISNULL(opt_ctx->get_session_info())) { + if (OB_ISNULL(opt_ctx.get_session_info())) { ret = OB_ERR_UNEXPECTED; - LOG_WARN("Get unexpected null", K(ret), K(log_plan), K(opt_ctx)); + LOG_WARN("Get unexpected null", K(ret), K(opt_ctx.get_session_info())); } else { ObExprResType res_type; res_type.set_type(ObUInt64Type); res_type.set_accuracy(ObAccuracy::MAX_ACCURACY[ObUInt64Type]); - if (OB_FAIL(ObRawExprUtils::build_op_pseudo_column_expr(opt_ctx->get_expr_factory(), + if (OB_FAIL(ObRawExprUtils::build_op_pseudo_column_expr(opt_ctx.get_expr_factory(), T_PSEUDO_IDENTIFY_SEQ, "IDENTIFY_SEQ", res_type, @@ -8462,7 +8460,7 @@ int ObOptimizerUtil::allocate_identify_seq_expr(ObLogPlan *log_plan, ObRawExpr * } else if (OB_ISNULL(tmp_identify_seq_expr)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("identify seq expr is null", K(ret)); - } else if (OB_FAIL(tmp_identify_seq_expr->formalize(opt_ctx->get_session_info()))) { + } else if (OB_FAIL(tmp_identify_seq_expr->formalize(opt_ctx.get_session_info()))) { LOG_WARN("identify seq expr formalize failed", K(ret)); } else { identify_seq_expr = tmp_identify_seq_expr; diff --git a/src/sql/optimizer/ob_optimizer_util.h b/src/sql/optimizer/ob_optimizer_util.h index c76fb056b3..820222c702 100644 --- a/src/sql/optimizer/ob_optimizer_util.h +++ b/src/sql/optimizer/ob_optimizer_util.h @@ -1395,7 +1395,7 @@ public: static int allocate_group_id_expr(ObLogPlan *log_plan, ObRawExpr *&group_id_expr); - static int allocate_identify_seq_expr(ObLogPlan *log_plan, ObRawExpr *&identify_seq_expr); + static int allocate_identify_seq_expr(ObOptimizerContext &opt_ctx, ObRawExpr *&identify_seq_expr); static int check_contribute_query_range(ObLogicalOperator *tsc, const ObIArray ¶ms, diff --git a/src/sql/optimizer/ob_select_log_plan.cpp b/src/sql/optimizer/ob_select_log_plan.cpp index 1f7cced460..ed6fa20b84 100644 --- a/src/sql/optimizer/ob_select_log_plan.cpp +++ b/src/sql/optimizer/ob_select_log_plan.cpp @@ -1775,6 +1775,9 @@ int ObSelectLogPlan::generate_raw_plan_for_set() const ObSelectStmt *child_stmt = NULL; ObSelectLogPlan *child_plan = NULL; ObSelectLogPlan *nonrecursive_plan = NULL; + if (!select_stmt->is_recursive_union()) { + nonrecursive_plan = get_nonrecursive_plan_for_fake_cte(); + } for (int64 i = 0; OB_SUCC(ret) && i < child_size; ++i) { child_input_filters.reuse(); child_rename_filters.reuse();