add for replace and insert_up with batch_optimization
This commit is contained in:
committed by
ob-robot
parent
671aeb2cea
commit
f001af9558
@ -697,6 +697,7 @@ int ObParser::check_is_insert(common::ObIArray<common::ObString> &queries, bool
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
is_ins = false;
|
||||
bool is_replace = false;
|
||||
if (queries.count() < 1) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("queries is unexpected", K(ret));
|
||||
@ -705,6 +706,8 @@ int ObParser::check_is_insert(common::ObIArray<common::ObString> &queries, bool
|
||||
} else {
|
||||
ObString &sql_str = queries.at(0);
|
||||
is_ins = (sql_str.length() > 6 && 0 == STRNCASECMP(sql_str.ptr(), "insert", 6));
|
||||
is_replace = (sql_str.length() > 7 && 0 == STRNCASECMP(sql_str.ptr(), "replace", 7));
|
||||
is_ins = is_ins | is_replace;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -731,7 +734,9 @@ int ObParser::reconstruct_insert_sql(const common::ObString &stmt,
|
||||
allocator_ = &allocator;
|
||||
if (OB_FAIL(parse(stmt, parse_result, parse_mode, false, true))) {
|
||||
// if parser SQL failed,then we won't rewrite it and keep it as it is
|
||||
LOG_WARN("failed to parser insert sql", K(ret));
|
||||
LOG_WARN("failed to parser insert sql", K(ret),
|
||||
K(parse_result.ins_multi_value_res_->on_duplicate_pos_),
|
||||
K(parse_result.ins_multi_value_res_->values_count_));
|
||||
} else if (parse_result.ins_multi_value_res_->values_count_ == 1) {
|
||||
// only one set of values,not need rewrite
|
||||
} else if (OB_ISNULL(bak_allocator)) {
|
||||
@ -740,6 +745,13 @@ int ObParser::reconstruct_insert_sql(const common::ObString &stmt,
|
||||
} else {
|
||||
// restore the allocator
|
||||
allocator_ = bak_allocator;
|
||||
LOG_DEBUG("after do reconstruct sql, result is",
|
||||
K(parse_result.ins_multi_value_res_->on_duplicate_pos_),
|
||||
K(parse_result.ins_multi_value_res_->values_col_),
|
||||
K(parse_result.ins_multi_value_res_->values_count_),
|
||||
K(stmt));
|
||||
bool is_on_duplicate = (parse_result.ins_multi_value_res_->on_duplicate_pos_ > 0);
|
||||
int64_t on_duplicate_length = stmt.length() - parse_result.ins_multi_value_res_->on_duplicate_pos_;
|
||||
for (ParenthesesOffset *current_obj = parse_result.ins_multi_value_res_->ref_parentheses_;
|
||||
OB_SUCC(ret) && NULL != current_obj;
|
||||
current_obj = current_obj->next_) {
|
||||
@ -753,7 +765,11 @@ int ObParser::reconstruct_insert_sql(const common::ObString &stmt,
|
||||
// right_parentheses_ - left_parentheses_,not contain the length of the left parenthesis, so the length + 1
|
||||
const int64_t values_length = current_obj->right_parentheses_ - current_obj->left_parentheses_ + 1;
|
||||
// The reason for here + 1 is to add a delimiter;
|
||||
const int64_t final_length = shared_length + values_length + 1; // 这个+1的原因是
|
||||
int64_t final_length = shared_length + values_length + 1; // 这个+1的原因是 为了后边的';'
|
||||
if (is_on_duplicate) {
|
||||
// for the on_duplicate_key clause of insert_up
|
||||
final_length = final_length + on_duplicate_length;
|
||||
}
|
||||
if (OB_ISNULL(new_sql_buf = static_cast<char*>(allocator_->alloc(final_length)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("fail to alloc memory", K(ret), K(final_length));
|
||||
@ -761,11 +777,19 @@ int ObParser::reconstruct_insert_sql(const common::ObString &stmt,
|
||||
LOG_WARN("failed to deep copy new sql", K(ret), K(final_length), K(shared_length), K(pos), K(stmt));
|
||||
} else if (OB_FAIL(databuff_memcpy(new_sql_buf, final_length, pos, values_length, (stmt.ptr() + (current_obj->left_parentheses_ - 1))))) {
|
||||
LOG_WARN("failed to deep copy member list buf", K(ret), K(final_length), K(pos), K(stmt), K(values_length));
|
||||
} else if (is_on_duplicate && OB_FAIL(databuff_memcpy(new_sql_buf,
|
||||
final_length,
|
||||
pos,
|
||||
on_duplicate_length,
|
||||
stmt.ptr() + parse_result.ins_multi_value_res_->on_duplicate_pos_))) {
|
||||
|
||||
} else {
|
||||
new_sql_buf[final_length - 1] = ';';
|
||||
ObString part(final_length, new_sql_buf);
|
||||
if (OB_FAIL(ins_queries.push_back(part))) {
|
||||
LOG_WARN("fail to push back query str", K(ret), K(part));
|
||||
} else {
|
||||
LOG_DEBUG("after rebuild multi_query sql is", K(part));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user