fix last insert id when using batch
This commit is contained in:
parent
a5da343aec
commit
e30efac083
@ -235,6 +235,7 @@ int ObSyncPlanDriver::response_result(ObMySQLResultSet &result)
|
||||
ok_param.affected_rows_ = curr_affected_row;
|
||||
ok_param.is_partition_hit_ = session_.partition_hit().get_bool();
|
||||
ok_param.has_more_result_ = !result.is_cursor_end();
|
||||
ok_param.lii_ = result.get_last_insert_id_to_client();
|
||||
process_ok = true;
|
||||
if (OB_FAIL(sender_.send_ok_packet(session_, ok_param))) {
|
||||
LOG_WARN("send ok packet failed", K(ret), K(ok_param));
|
||||
|
@ -303,7 +303,12 @@ OB_INLINE int ObTableInsertOp::insert_row_to_das()
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
plan_ctx->record_last_insert_id_cur_stmt();
|
||||
bool is_ins_val_opt = ctx_.get_sql_ctx()->is_do_insert_batch_opt();
|
||||
if (MY_SPEC.ab_stmt_id_ != nullptr && !is_ins_val_opt) {
|
||||
plan_ctx->record_last_insert_id_cur_stmt_for_batch();
|
||||
} else {
|
||||
plan_ctx->record_last_insert_id_cur_stmt();
|
||||
}
|
||||
}
|
||||
NG_TRACE(insert_end);
|
||||
return ret;
|
||||
|
@ -785,6 +785,7 @@ int ObTableModifyOp::merge_implict_cursor(int64_t insert_rows,
|
||||
implicit_cursor.stmt_id_ = stmt_id;
|
||||
implicit_cursor.found_rows_ += found_rows;
|
||||
implicit_cursor.matched_rows_ += found_rows;
|
||||
implicit_cursor.last_insert_id_ = plan_ctx->get_autoinc_col_value();
|
||||
if (insert_rows > 0) {
|
||||
implicit_cursor.affected_rows_ += insert_rows;
|
||||
}
|
||||
|
@ -411,6 +411,7 @@ int ObPhysicalPlanCtx::switch_implicit_cursor()
|
||||
set_row_matched_count(cursor_info.matched_rows_);
|
||||
set_row_duplicated_count(cursor_info.duplicated_rows_);
|
||||
set_row_deleted_count(cursor_info.deleted_rows_);
|
||||
set_last_insert_id_to_client(cursor_info.last_insert_id_);
|
||||
++cur_stmt_id_;
|
||||
}
|
||||
return ret;
|
||||
|
@ -345,6 +345,12 @@ public:
|
||||
last_insert_id_cur_stmt_ = autoinc_id_tmp_;
|
||||
}
|
||||
}
|
||||
inline void record_last_insert_id_cur_stmt_for_batch()
|
||||
{
|
||||
if (autoinc_id_tmp_ > 0) {
|
||||
last_insert_id_cur_stmt_ = autoinc_id_tmp_;
|
||||
}
|
||||
}
|
||||
inline void set_last_insert_id_cur_stmt(const uint64_t last_insert_id)
|
||||
{
|
||||
last_insert_id_cur_stmt_ = last_insert_id;
|
||||
|
@ -1932,6 +1932,7 @@ int ObResultSet::switch_implicit_cursor(int64_t &affected_rows)
|
||||
}
|
||||
} else {
|
||||
affected_rows = plan_ctx->get_affected_rows();
|
||||
set_last_insert_id_to_client(plan_ctx->get_last_insert_id_to_client());
|
||||
memset(message_, 0, sizeof(message_));
|
||||
if (OB_FAIL(set_mysql_info())) {
|
||||
LOG_WARN("set mysql info failed", K(ret));
|
||||
|
@ -3698,7 +3698,8 @@ OB_SERIALIZE_MEMBER(ObImplicitCursorInfo,
|
||||
found_rows_,
|
||||
matched_rows_,
|
||||
duplicated_rows_,
|
||||
deleted_rows_);
|
||||
deleted_rows_,
|
||||
last_insert_id_);
|
||||
|
||||
int ObImplicitCursorInfo::merge_cursor(const ObImplicitCursorInfo &other)
|
||||
{
|
||||
@ -3715,6 +3716,7 @@ int ObImplicitCursorInfo::merge_cursor(const ObImplicitCursorInfo &other)
|
||||
matched_rows_ += other.matched_rows_;
|
||||
duplicated_rows_ += other.duplicated_rows_;
|
||||
deleted_rows_ += other.deleted_rows_;
|
||||
last_insert_id_ = other.last_insert_id_;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -1006,7 +1006,8 @@ public:
|
||||
found_rows_(0),
|
||||
matched_rows_(0),
|
||||
duplicated_rows_(0),
|
||||
deleted_rows_(0) {}
|
||||
deleted_rows_(0),
|
||||
last_insert_id_(0) {}
|
||||
|
||||
int merge_cursor(const ObImplicitCursorInfo &other);
|
||||
TO_STRING_KV(K_(stmt_id),
|
||||
@ -1014,7 +1015,8 @@ public:
|
||||
K_(found_rows),
|
||||
K_(matched_rows),
|
||||
K_(duplicated_rows),
|
||||
K_(deleted_rows));
|
||||
K_(deleted_rows),
|
||||
K_(last_insert_id));
|
||||
|
||||
int64_t stmt_id_;
|
||||
int64_t affected_rows_;
|
||||
@ -1022,6 +1024,7 @@ public:
|
||||
int64_t matched_rows_;
|
||||
int64_t duplicated_rows_;
|
||||
int64_t deleted_rows_;
|
||||
uint64_t last_insert_id_;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user