[CP] generate delete+insert plan when update primary key in a pdml plan

This commit is contained in:
sdc
2024-02-06 04:16:29 +00:00
committed by ob-robot
parent 6627f9ef2e
commit 95b577395b
5 changed files with 46 additions and 1 deletions

View File

@ -2278,6 +2278,40 @@ int ObDelUpdLogPlan::check_update_part_key(const ObTableSchema* index_schema,
}
return ret;
}
int ObDelUpdLogPlan::check_update_primary_key(const ObTableSchema* index_schema,
IndexDMLInfo*& index_dml_info) const
{
int ret = OB_SUCCESS;
const ObDelUpdStmt *stmt = get_stmt();
ObSEArray<uint64_t, 8> pk_ids;
if (OB_ISNULL(stmt) || OB_ISNULL(index_schema) || OB_ISNULL(index_dml_info)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(stmt), K(index_schema), K(index_dml_info));
} else if (!index_dml_info->is_primary_index_) {
// do nothing
} else if (OB_FAIL(index_schema->get_rowkey_info().get_column_ids(pk_ids))) {
LOG_WARN("failed to get rowkey column ids", K(ret));
} else {
for (int64_t i = 0; i < index_dml_info->assignments_.count(); ++i) {
ObColumnRefRawExpr *column_expr = index_dml_info->assignments_.at(i).column_expr_;
ColumnItem *column_item = nullptr;
if (OB_ISNULL(column_expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null column expr", K(ret));
} else if (OB_ISNULL(column_item = stmt->get_column_item_by_id(column_expr->get_table_id(),
column_expr->get_column_id()))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null column item", K(ret), KPC(column_expr));
} else if (has_exist_in_array(pk_ids, column_item->base_cid_)) {
index_dml_info->is_update_primary_key_ = true;
break;
}
}
}
return ret;
}
int ObDelUpdLogPlan::allocate_link_dml_as_top(ObLogicalOperator *&old_top)
{
int ret = OB_SUCCESS;

View File

@ -233,6 +233,8 @@ public:
IndexDMLInfo*& index_dml_info) const;
int check_update_part_key(const ObTableSchema* index_schema,
IndexDMLInfo*& index_dml_info) const;
int check_update_primary_key(const ObTableSchema* index_schema,
IndexDMLInfo*& index_dml_info) const;
int allocate_link_dml_as_top(ObLogicalOperator *&old_top);
bool use_pdml() const { return use_pdml_; }
int compute_dml_parallel();

View File

@ -41,6 +41,7 @@ int IndexDMLInfo::deep_copy(ObIRawExprCopier &expr_copier, const IndexDMLInfo &o
is_primary_index_ = other.is_primary_index_;
is_update_unique_key_ = other.is_update_unique_key_;
is_update_part_key_ = other.is_update_part_key_;
is_update_primary_key_ = other.is_update_primary_key_;
assignments_.reset();
if (OB_FAIL(expr_copier.copy(other.column_exprs_, column_exprs_))) {
LOG_WARN("failed to assign column exprs", K(ret));
@ -83,6 +84,7 @@ int IndexDMLInfo::assign_basic(const IndexDMLInfo &other)
is_primary_index_ = other.is_primary_index_;
is_update_unique_key_ = other.is_update_unique_key_;
is_update_part_key_ = other.is_update_part_key_;
is_update_primary_key_ = other.is_update_primary_key_;
trans_info_expr_ = other.trans_info_expr_;
if (OB_FAIL(column_exprs_.assign(other.column_exprs_))) {
LOG_WARN("failed to assign column exprs", K(ret));

View File

@ -36,6 +36,7 @@ public:
part_ids_(),
is_update_unique_key_(false),
is_update_part_key_(false),
is_update_primary_key_(false),
distinct_algo_(T_DISTINCT_NONE),
lookup_part_id_expr_(NULL),
old_part_id_expr_(NULL),
@ -65,6 +66,7 @@ public:
part_ids_.reset();
is_update_unique_key_ = false;
is_update_part_key_ = false;
is_update_primary_key_ = false;
distinct_algo_ = T_DISTINCT_NONE;
lookup_part_id_expr_ = NULL;
old_part_id_expr_ = NULL;
@ -156,6 +158,7 @@ public:
common::ObSEArray<ObObjectID, 1, common::ModulePageAllocator, true> part_ids_;
bool is_update_unique_key_;
bool is_update_part_key_;
bool is_update_primary_key_;
DistinctType distinct_algo_;
ObRawExpr *lookup_part_id_expr_; // for replace and insert_up conflict scene
ObRawExpr *old_part_id_expr_;
@ -188,6 +191,7 @@ public:
K_(ck_cst_exprs),
K_(is_update_unique_key),
K_(is_update_part_key),
K_(is_update_primary_key),
K_(distinct_algo),
K_(related_index_ids));
};

View File

@ -407,7 +407,8 @@ int ObUpdateLogPlan::candi_allocate_pdml_update()
ret = OB_ERR_UNEXPECTED;
LOG_WARN("index dml info is null", K(ret));
} else if (index_dml_info->is_update_part_key_ ||
index_dml_info->is_update_unique_key_) {
index_dml_info->is_update_unique_key_ ||
index_dml_info->is_update_primary_key_) {
IndexDMLInfo *index_delete_info = nullptr;
IndexDMLInfo *index_insert_info = nullptr;
// 更新了当前索引的分区键,需要做 row-movement
@ -622,6 +623,8 @@ int ObUpdateLogPlan::prepare_table_dml_info_special(const ObDmlTableInfo& table_
} else if (OB_ISNULL(index_schema)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to get table schema", K(table_info), K(ret));
} else if (OB_FAIL(check_update_primary_key(index_schema, table_dml_info))) {
LOG_WARN("failed to check update unique key", K(ret));
} else if (!table_info.is_link_table_ &&
OB_FAIL(check_update_part_key(index_schema, table_dml_info))) {
LOG_WARN("failed to check update part key", K(ret));