From ad0dbbb47c53275904b3960662bbf21d6874f612 Mon Sep 17 00:00:00 2001 From: obdev Date: Mon, 8 Apr 2024 06:50:50 +0000 Subject: [PATCH] remove location constraint of insert table if insert plan is local with multi-part-insert --- src/sql/optimizer/ob_logical_operator.cpp | 24 +++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/sql/optimizer/ob_logical_operator.cpp b/src/sql/optimizer/ob_logical_operator.cpp index 6559b1ad4..7815382c8 100644 --- a/src/sql/optimizer/ob_logical_operator.cpp +++ b/src/sql/optimizer/ob_logical_operator.cpp @@ -2614,9 +2614,9 @@ int ObLogicalOperator::gen_location_constraint(void *ctx) bool is_union_all_set_pw = false; bool is_setop_ext_pw = false; bool is_join_ext_pw = false; - if (OB_ISNULL(ctx) || OB_ISNULL(get_stmt())) { + if (OB_ISNULL(ctx) || OB_ISNULL(get_stmt()) || OB_ISNULL(get_plan())) { ret = OB_ERR_UNEXPECTED; - LOG_WARN("ctx is unexpected null", K(ret)); + LOG_WARN("ctx is unexpected null", K(ret), K(ctx), K(get_stmt()), K(get_plan())); } else { ObLocationConstraintContext *loc_cons_ctx = reinterpret_cast(ctx); @@ -2709,8 +2709,24 @@ int ObLogicalOperator::gen_location_constraint(void *ctx) } else { ++add_count; } - } else if (OB_FAIL(loc_cons_ctx->base_table_constraints_.push_back(loc_cons))) { - LOG_WARN("failed to push back location constraint", K(ret)); + } else { + bool find = false; + ObIArray & partition_infos = + get_plan()->get_optimizer_context().get_table_partition_info(); + for (int64_t i = 0; !find && i < partition_infos.count(); ++i) { + const ObTablePartitionInfo *cur_info = partition_infos.at(i); + if (OB_NOT_NULL(cur_info) && + cur_info->get_table_id() == loc_cons.key_.table_id_ && + cur_info->get_ref_table_id() == loc_cons.key_.ref_table_id_) { + find = true; + } + } + if (!find) { + // local multi part insert, remove location constraint of insert table because + // we didn't add it's table location. + } else if (OB_FAIL(loc_cons_ctx->base_table_constraints_.push_back(loc_cons))) { + LOG_WARN("failed to push back location constraint", K(ret)); + } } }