patch 4.0
This commit is contained in:
@ -16,15 +16,16 @@
|
||||
#include "lib/container/ob_se_array_iterator.h"
|
||||
#include "lib/mysqlclient/ob_isql_client.h"
|
||||
#include "lib/mysqlclient/ob_mysql_proxy.h"
|
||||
#include "share/partition_table/ob_partition_info.h"
|
||||
#include "lib/hash/ob_hashmap.h"
|
||||
#include "common/object/ob_object.h"
|
||||
|
||||
namespace oceanbase {
|
||||
namespace share {
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
using namespace common;
|
||||
|
||||
const char* const ObDMLSqlSplicer::NULL_VALUE = NULL;
|
||||
const char *const ObDMLSqlSplicer::NULL_VALUE = NULL;
|
||||
|
||||
void ObDMLSqlSplicer::reset()
|
||||
{
|
||||
@ -34,68 +35,74 @@ void ObDMLSqlSplicer::reset()
|
||||
rows_end_pos_.reset();
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const uint64_t value, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_uint64_value(const uint64_t value, bool &is_null)
|
||||
{
|
||||
return append_value(static_cast<int64_t>(value), is_null);
|
||||
// is_null = false;
|
||||
// return values_.append_fmt("%lu", value);
|
||||
is_null = false;
|
||||
return values_.append_fmt("%lu", value);
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const int64_t value, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const uint64_t value, bool &is_null)
|
||||
{
|
||||
return append_value(static_cast<int64_t>(value), is_null);
|
||||
//is_null = false;
|
||||
//return values_.append_fmt("%lu", value);
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const int64_t value, bool &is_null)
|
||||
{
|
||||
is_null = false;
|
||||
return values_.append_fmt("%ld", value);
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const uint32_t value, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const uint32_t value, bool &is_null)
|
||||
{
|
||||
is_null = false;
|
||||
return values_.append_fmt("%u", value);
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const int32_t value, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const int32_t value, bool &is_null)
|
||||
{
|
||||
is_null = false;
|
||||
return values_.append_fmt("%d", value);
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const uint16_t value, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const uint16_t value, bool &is_null)
|
||||
{
|
||||
is_null = false;
|
||||
return values_.append_fmt("%u", value);
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const int16_t value, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const int16_t value, bool &is_null)
|
||||
{
|
||||
is_null = false;
|
||||
return values_.append_fmt("%d", value);
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const uint8_t value, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const uint8_t value, bool &is_null)
|
||||
{
|
||||
is_null = false;
|
||||
return values_.append_fmt("%u", value);
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const int8_t value, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const int8_t value, bool &is_null)
|
||||
{
|
||||
is_null = false;
|
||||
return values_.append_fmt("%d", value);
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const bool value, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const bool value, bool &is_null)
|
||||
{
|
||||
is_null = false;
|
||||
return values_.append_fmt("%d", value);
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const double value, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const double value, bool &is_null)
|
||||
{
|
||||
is_null = false;
|
||||
return values_.append_fmt("%lf", value);
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const char* str, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const char *str, bool &is_null)
|
||||
{
|
||||
is_null = (NULL == str);
|
||||
int ret = OB_SUCCESS;
|
||||
@ -107,7 +114,7 @@ int ObDMLSqlSplicer::append_value(const char* str, bool& is_null)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const common::number::ObNumber& nmb, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const common::number::ObNumber &nmb, bool &is_null)
|
||||
{
|
||||
is_null = false;
|
||||
int ret = OB_SUCCESS;
|
||||
@ -117,24 +124,25 @@ int ObDMLSqlSplicer::append_value(const common::number::ObNumber& nmb, bool& is_
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(char* str, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(char *str, bool &is_null)
|
||||
{
|
||||
return append_value(static_cast<const char*>(str), is_null);
|
||||
return append_value(static_cast<const char *>(str), is_null);
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const ObString& str, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const ObString &str, bool &is_null)
|
||||
{
|
||||
is_null = (NULL == str.ptr());
|
||||
int ret = OB_SUCCESS;
|
||||
if (!is_null) {
|
||||
if (OB_FAIL(values_.append_fmt(mode_ == NAKED_VALUE_MODE ? "%.*s" : "'%.*s'", str.length(), str.ptr()))) {
|
||||
if (OB_FAIL(values_.append_fmt(mode_ == NAKED_VALUE_MODE ? "%.*s" : "'%.*s'",
|
||||
str.length(), str.ptr()))) {
|
||||
LOG_WARN("append string to values failed", K(ret), K(str));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const ObHexEscapeSqlStr& escape_str, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const ObHexEscapeSqlStr &escape_str, bool &is_null)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NAKED_VALUE_MODE == mode_) {
|
||||
@ -153,16 +161,16 @@ int ObDMLSqlSplicer::append_value(const ObHexEscapeSqlStr& escape_str, bool& is_
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const ObRealUInt64& value, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const ObRealUInt64 &value, bool &is_null)
|
||||
{
|
||||
is_null = false;
|
||||
return values_.append_fmt("%lu", value.value());
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::append_value(const ObObj& obj, bool& is_null)
|
||||
int ObDMLSqlSplicer::append_value(const ObObj &obj, bool &is_null)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
switch (obj.get_type()) {
|
||||
switch(obj.get_type()) {
|
||||
case ObNullType:
|
||||
is_null = true;
|
||||
break;
|
||||
@ -237,7 +245,7 @@ int ObDMLSqlSplicer::append_value(const ObObj& obj, bool& is_null)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::add_pk_column(const bool is_null, const char* col_name)
|
||||
int ObDMLSqlSplicer::add_pk_column(const bool is_null, const char *col_name)
|
||||
{
|
||||
const bool is_pk = true;
|
||||
int ret = OB_SUCCESS;
|
||||
@ -250,7 +258,7 @@ int ObDMLSqlSplicer::add_pk_column(const bool is_null, const char* col_name)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::add_column(const bool is_null, const char* col_name)
|
||||
int ObDMLSqlSplicer::add_column(const bool is_null, const char *col_name)
|
||||
{
|
||||
const bool is_pk = false;
|
||||
int ret = OB_SUCCESS;
|
||||
@ -263,7 +271,8 @@ int ObDMLSqlSplicer::add_column(const bool is_null, const char* col_name)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::add_column(const bool is_primary_key, const bool is_null, const char* col_name)
|
||||
int ObDMLSqlSplicer::add_column(
|
||||
const bool is_primary_key, const bool is_null, const char *col_name)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(col_name)) {
|
||||
@ -285,7 +294,51 @@ int ObDMLSqlSplicer::add_column(const bool is_primary_key, const bool is_null, c
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::add_time_column(const char* col_name, const int64_t now)
|
||||
int ObDMLSqlSplicer::add_uint64_pk_column(const char *col_name, const uint64_t value)
|
||||
{
|
||||
const bool is_pk = true;
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(col_name)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid column name", K(ret), KP(col_name));
|
||||
} else if (OB_FAIL(add_uint64_column(is_pk, col_name, value))) {
|
||||
LOG_WARN("add column failed", K(ret), K(is_pk), K(value), K(col_name));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::add_uint64_column(const char *col_name, const uint64_t value)
|
||||
{
|
||||
const bool is_pk = false;
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(col_name)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid column name", K(ret), KP(col_name));
|
||||
} else if (OB_FAIL(add_uint64_column(is_pk, col_name, value))) {
|
||||
LOG_WARN("add column failed", K(ret), K(is_pk), K(value), K(col_name));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::add_uint64_column(
|
||||
const bool is_primary_key, const char *col_name, const uint64_t value)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_null = false;
|
||||
if (OB_ISNULL(col_name)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid column name", K(ret), KP(col_name));
|
||||
} else if (OB_FAIL(append_uint64_value(value, is_null))) {
|
||||
LOG_WARN("append value failed", K(ret), K(value));
|
||||
} else if (OB_FAIL(add_column(is_primary_key, is_null, col_name))) {
|
||||
LOG_WARN("add column failed", K(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::add_time_column(const char *col_name,
|
||||
const int64_t now,
|
||||
bool is_pk/*default false*/)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(col_name)) {
|
||||
@ -304,7 +357,7 @@ int ObDMLSqlSplicer::add_time_column(const char* col_name, const int64_t now)
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
const bool is_primary_key = false;
|
||||
const bool is_primary_key = is_pk;
|
||||
const bool is_null = false;
|
||||
if (OB_FAIL(add_column(is_primary_key, is_null, col_name))) {
|
||||
LOG_WARN("add column failed", K(ret), K(is_primary_key), K(is_null), K(col_name));
|
||||
@ -313,7 +366,7 @@ int ObDMLSqlSplicer::add_time_column(const char* col_name, const int64_t now)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::add_raw_time_column(const char* col_name, const int64_t now)
|
||||
int ObDMLSqlSplicer::add_raw_time_column(const char *col_name, const int64_t now)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const bool is_primary_key = false;
|
||||
@ -328,9 +381,11 @@ int ObDMLSqlSplicer::add_raw_time_column(const char* col_name, const int64_t now
|
||||
LOG_WARN("add column failed", K(ret), K(is_primary_key), K(is_null), K(col_name));
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_insert(const char* table_name, const char* head, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_insert(const char *table_name, const char *head,
|
||||
ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NULL == table_name || NULL == head) {
|
||||
@ -355,8 +410,8 @@ int ObDMLSqlSplicer::splice_insert(const char* table_name, const char* head, ObS
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_column(
|
||||
const char* sep, const ColSet::Type col_set, const ValSet::Type val_set, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_column(const char *sep,
|
||||
const ColSet::Type col_set, const ValSet::Type val_set, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool first = true;
|
||||
@ -369,9 +424,10 @@ int ObDMLSqlSplicer::splice_column(
|
||||
LOG_WARN("column_count is invalid", K(ret), "column_count", columns_.count());
|
||||
}
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < columns_.count(); ++i) {
|
||||
const Column& col = columns_.at(i);
|
||||
if (ColSet::ALL == col_set || (ColSet::ONLY_PK == col_set && col.primary_key_) ||
|
||||
(ColSet::FILTER_PK == col_set && !col.primary_key_)) {
|
||||
const Column &col = columns_.at(i);
|
||||
if (ColSet::ALL == col_set
|
||||
|| (ColSet::ONLY_PK == col_set && col.primary_key_)
|
||||
|| (ColSet::FILTER_PK == col_set && !col.primary_key_)) {
|
||||
if (!first) {
|
||||
if (OB_FAIL(sql.append(sep))) {
|
||||
LOG_WARN("append sql failed");
|
||||
@ -387,22 +443,22 @@ int ObDMLSqlSplicer::splice_column(
|
||||
if (col.is_null_) {
|
||||
ret = sql.append("NULL");
|
||||
} else {
|
||||
ret = sql.append(ObString(col.value_end_pos_ - start_pos, values_.ptr() + start_pos));
|
||||
ret = sql.append(ObString(
|
||||
col.value_end_pos_ - start_pos, values_.ptr() + start_pos));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ValSet::ALL: {
|
||||
case ValSet::ALL : {
|
||||
if (col.is_null_) {
|
||||
ret = sql.append_fmt("%s = NULL", col.name_);
|
||||
} else {
|
||||
ret = sql.append_fmt("%s = %.*s",
|
||||
col.name_,
|
||||
ret = sql.append_fmt("%s = %.*s", col.name_,
|
||||
static_cast<int32_t>(col.value_end_pos_ - start_pos),
|
||||
values_.ptr() + start_pos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
default : {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected value", K(ret), K(val_set));
|
||||
}
|
||||
@ -418,7 +474,7 @@ int ObDMLSqlSplicer::splice_column(
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_insert_sql_without_plancache(const char* table_name, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_insert_sql_without_plancache(const char *table_name, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NULL == table_name) {
|
||||
@ -433,7 +489,7 @@ int ObDMLSqlSplicer::splice_insert_sql_without_plancache(const char* table_name,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_insert_sql(const char* table_name, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_insert_sql(const char *table_name, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NULL == table_name) {
|
||||
@ -448,7 +504,7 @@ int ObDMLSqlSplicer::splice_insert_sql(const char* table_name, ObSqlString& sql)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_insert_ignore_sql(const char* table_name, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_insert_ignore_sql(const char *table_name, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NULL == table_name) {
|
||||
@ -463,7 +519,7 @@ int ObDMLSqlSplicer::splice_insert_ignore_sql(const char* table_name, ObSqlStrin
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_insert_update_sql(const char* table_name, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_insert_update_sql(const char *table_name, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NULL == table_name) {
|
||||
@ -482,7 +538,7 @@ int ObDMLSqlSplicer::splice_insert_update_sql(const char* table_name, ObSqlStrin
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_replace_sql(const char* table_name, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_replace_sql(const char *table_name, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NULL == table_name) {
|
||||
@ -497,7 +553,7 @@ int ObDMLSqlSplicer::splice_replace_sql(const char* table_name, ObSqlString& sql
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_delete_sql(const char* table_name, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_delete_sql(const char *table_name, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NULL == table_name) {
|
||||
@ -512,8 +568,8 @@ int ObDMLSqlSplicer::splice_delete_sql(const char* table_name, ObSqlString& sql)
|
||||
LOG_WARN("splice where condition failed", K(ret));
|
||||
} else {
|
||||
if (!extra_condition_.empty()) {
|
||||
if (OB_FAIL(
|
||||
sql.append_fmt(" AND %.*s", static_cast<int32_t>(extra_condition_.length()), extra_condition_.ptr()))) {
|
||||
if (OB_FAIL(sql.append_fmt(" AND %.*s",
|
||||
static_cast<int32_t>(extra_condition_.length()), extra_condition_.ptr()))) {
|
||||
LOG_WARN("add extra condition failed", K(ret), K_(extra_condition));
|
||||
}
|
||||
}
|
||||
@ -522,7 +578,7 @@ int ObDMLSqlSplicer::splice_delete_sql(const char* table_name, ObSqlString& sql)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_column_names(common::ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_column_names(common::ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (columns_.count() <= 0) {
|
||||
@ -534,7 +590,7 @@ int ObDMLSqlSplicer::splice_column_names(common::ObSqlString& sql) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_values(ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_values(ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (columns_.count() <= 0) {
|
||||
@ -546,7 +602,20 @@ int ObDMLSqlSplicer::splice_values(ObSqlString& sql) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_predicates(ObSqlString& sql) const
|
||||
// "pk1=v1, pk2=v2, c3=v3, c4=v4"
|
||||
int ObDMLSqlSplicer::splice_assignments(common::ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (columns_.count() <= 0) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid column count", K(ret), "column_count", columns_.count());
|
||||
} else if (OB_FAIL(splice_column(", ", ColSet::ALL, ValSet::ALL, sql))) {
|
||||
LOG_WARN("add values failed", K(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_predicates(ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (columns_.count() <= 0) {
|
||||
@ -558,7 +627,7 @@ int ObDMLSqlSplicer::splice_predicates(ObSqlString& sql) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_update_sql(const char* table_name, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_update_sql(const char *table_name, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NULL == table_name) {
|
||||
@ -577,8 +646,8 @@ int ObDMLSqlSplicer::splice_update_sql(const char* table_name, ObSqlString& sql)
|
||||
LOG_WARN("splice where condition failed", K(ret));
|
||||
} else {
|
||||
if (!extra_condition_.empty()) {
|
||||
if (OB_FAIL(
|
||||
sql.append_fmt(" AND %.*s", static_cast<int32_t>(extra_condition_.length()), extra_condition_.ptr()))) {
|
||||
if (OB_FAIL(sql.append_fmt(" AND %.*s",
|
||||
static_cast<int32_t>(extra_condition_.length()), extra_condition_.ptr()))) {
|
||||
LOG_WARN("add extra condition failed", K(ret), K_(extra_condition));
|
||||
}
|
||||
}
|
||||
@ -587,7 +656,9 @@ int ObDMLSqlSplicer::splice_update_sql(const char* table_name, ObSqlString& sql)
|
||||
}
|
||||
|
||||
int ObPTSqlSplicer::splice_batch_insert_update_replica_sql(
|
||||
const char* table_name, const bool with_role, ObSqlString& sql) const
|
||||
const char *table_name,
|
||||
const bool with_role,
|
||||
ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObArray<ObString> all_names;
|
||||
@ -602,14 +673,14 @@ int ObPTSqlSplicer::splice_batch_insert_update_replica_sql(
|
||||
LOG_WARN("splice insert sql failed", K(ret), K(table_name));
|
||||
} else if (OB_FAIL(sql.append(" ON DUPLICATE KEY UPDATE "))) {
|
||||
LOG_WARN("append sql failed", K(ret));
|
||||
} else if (OB_FAIL(
|
||||
splice_batch_insert_update_replica_column(with_role, ObString::make_string(","), all_names, sql))) {
|
||||
} else if (OB_FAIL(splice_batch_insert_update_replica_column(
|
||||
with_role, ObString::make_string(","), all_names, sql))) {
|
||||
LOG_WARN("failed to splice on dup", K(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPTSqlSplicer::splice_insert_update_replica_sql(const char* table_name, ObSqlString& sql) const
|
||||
int ObPTSqlSplicer::splice_insert_update_replica_sql(const char *table_name, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NULL == table_name) {
|
||||
@ -629,17 +700,25 @@ int ObPTSqlSplicer::splice_insert_update_replica_sql(const char* table_name, ObS
|
||||
}
|
||||
|
||||
int ObPTSqlSplicer::splice_batch_insert_update_replica_column(
|
||||
const bool with_role, const ObString& sep, const ObIArray<ObString>& names, ObSqlString& sql) const
|
||||
const bool with_role,
|
||||
const ObString &sep,
|
||||
const ObIArray<ObString> &names,
|
||||
ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t N = names.count();
|
||||
bool first = true;
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < N; ++i) {
|
||||
const ObString& name = names.at(i);
|
||||
if (0 == name.case_compare("tenant_id") || 0 == name.case_compare("table_id") ||
|
||||
0 == name.case_compare("partition_id") || 0 == name.case_compare("svr_ip") ||
|
||||
0 == name.case_compare("svr_port") || 0 == name.case_compare("unit_id") ||
|
||||
(0 == name.case_compare("role") && !with_role) || 0 == name.case_compare("is_previous_leader")) {
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < N; ++i)
|
||||
{
|
||||
const ObString &name = names.at(i);
|
||||
if (0 == name.case_compare("tenant_id")
|
||||
|| 0 == name.case_compare("table_id")
|
||||
|| 0 == name.case_compare("partition_id")
|
||||
|| 0 == name.case_compare("svr_ip")
|
||||
|| 0 == name.case_compare("svr_port")
|
||||
|| 0 == name.case_compare("unit_id")
|
||||
|| (0 == name.case_compare("role") && !with_role)
|
||||
|| 0 == name.case_compare("is_previous_leader")) {
|
||||
// Skip primary_key, unit_id, is_previous_leader, and keep it consistent with the original batch report logic
|
||||
} else {
|
||||
if (!first && OB_FAIL(sql.append(sep))) {
|
||||
@ -649,11 +728,11 @@ int ObPTSqlSplicer::splice_batch_insert_update_replica_column(
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
} // end for
|
||||
} // end for
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPTSqlSplicer::splice_insert_update_replica_column(const char* sep, ObSqlString& sql) const
|
||||
int ObPTSqlSplicer::splice_insert_update_replica_column(const char *sep, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool first = true;
|
||||
@ -666,10 +745,11 @@ int ObPTSqlSplicer::splice_insert_update_replica_column(const char* sep, ObSqlSt
|
||||
LOG_WARN("column_count is invalid", K(ret), "column_count", columns_.count());
|
||||
}
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < columns_.count(); ++i) {
|
||||
const Column& col = columns_.at(i);
|
||||
if (col.primary_key_ || 0 == strncmp(col.name_, "unit_id", strlen("unit_id")) ||
|
||||
const Column &col = columns_.at(i);
|
||||
if (col.primary_key_ ||
|
||||
0 == strncmp(col.name_, "unit_id", strlen("unit_id")) ||
|
||||
0 == strncmp(col.name_, "is_previous_leader", strlen("is_previous_leader"))) {
|
||||
// do nothing
|
||||
//do nothing
|
||||
} else {
|
||||
if (!first) {
|
||||
if (OB_FAIL(sql.append(sep))) {
|
||||
@ -680,8 +760,9 @@ int ObPTSqlSplicer::splice_insert_update_replica_column(const char* sep, ObSqlSt
|
||||
if (col.is_null_) {
|
||||
ret = sql.append_fmt("%s = NULL", col.name_);
|
||||
} else {
|
||||
ret = sql.append_fmt(
|
||||
"%s = %.*s", col.name_, static_cast<int32_t>(col.value_end_pos_ - start_pos), values_.ptr() + start_pos);
|
||||
ret = sql.append_fmt("%s = %.*s", col.name_,
|
||||
static_cast<int32_t>(col.value_end_pos_ - start_pos),
|
||||
values_.ptr() + start_pos);
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
LOG_WARN("append column failed", K(ret));
|
||||
@ -694,71 +775,7 @@ int ObPTSqlSplicer::splice_insert_update_replica_column(const char* sep, ObSqlSt
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPTSqlSplicer::splice_update_leader_replica_sql(
|
||||
const ObPartitionReplica& replica, const char* table_name, ObSqlString& sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
char ip[OB_MAX_SERVER_ADDR_SIZE] = "";
|
||||
int64_t start_pos = 0;
|
||||
int32_t port = 0;
|
||||
if (OB_ISNULL(table_name) || !replica.is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(table_name), K(replica));
|
||||
} else if (columns_.count() <= 0) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("column_count is invalid", K(ret), "column_count", columns_.count());
|
||||
} else if (false == replica.server_.ip_to_string(ip, sizeof(ip))) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("convert server ip to string failed", K(ret), "server", replica.server_);
|
||||
} else if (OB_FAIL(sql.assign_fmt("UPDATE %s SET ", table_name))) {
|
||||
LOG_WARN("assign sql failed", K(ret));
|
||||
} else {
|
||||
bool first = true;
|
||||
port = replica.server_.get_port();
|
||||
for (int64_t i = 0; i < columns_.count() && OB_SUCC(ret); i++) {
|
||||
const Column& col = columns_.at(i);
|
||||
if (!col.primary_key_) {
|
||||
if (!first) {
|
||||
if (OB_FAIL(sql.append(", "))) {
|
||||
LOG_WARN("append sql failed", K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
if (col.is_null_) {
|
||||
ret = sql.append_fmt(
|
||||
"%s = case when (svr_ip='%s' and svr_port=%d) then NULL else %s end", col.name_, ip, port, col.name_);
|
||||
} else {
|
||||
ret = sql.append_fmt("%s = case when (svr_ip='%s' and svr_port=%d) then %.*s else %s end",
|
||||
col.name_,
|
||||
ip,
|
||||
port,
|
||||
static_cast<int32_t>(col.value_end_pos_ - start_pos),
|
||||
values_.ptr() + start_pos,
|
||||
col.name_);
|
||||
}
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
start_pos = col.value_end_pos_;
|
||||
} // end for
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_FAIL(sql.append_fmt(", role = case when (svr_ip='%s' and svr_port=%d) then %d else %d end",
|
||||
ip,
|
||||
port,
|
||||
replica.role_,
|
||||
FOLLOWER))) {
|
||||
LOG_WARN("fail to appen sql", K(ret));
|
||||
} else if (OB_FAIL(sql.append(" where "))) {
|
||||
LOG_WARN("fail to append value", K(ret));
|
||||
} else if (OB_FAIL(splice_column(" AND ", ColSet::ONLY_PK, ValSet::ALL, sql))) {
|
||||
LOG_WARN("splice where condition failed", K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_select_1_sql(const char* table_name, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_select_1_sql(const char *table_name, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NULL == table_name) {
|
||||
@ -775,8 +792,8 @@ int ObDMLSqlSplicer::splice_select_1_sql(const char* table_name, ObSqlString& sq
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_core_cells(
|
||||
ObCoreTableProxy& kv_proxy, common::ObIArray<ObCoreTableProxy::UpdateCell>& cells)
|
||||
int ObDMLSqlSplicer::splice_core_cells(ObCoreTableProxy &kv_proxy,
|
||||
common::ObIArray<ObCoreTableProxy::UpdateCell> &cells)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
cells.reuse();
|
||||
@ -788,14 +805,14 @@ int ObDMLSqlSplicer::splice_core_cells(
|
||||
LOG_WARN("invalid column count", K(ret), "column_count", columns_.count());
|
||||
}
|
||||
|
||||
FOREACH_X(col, columns_, OB_SUCCESS == ret)
|
||||
{
|
||||
FOREACH_X(col, columns_, OB_SUCCESS == ret) {
|
||||
ucell.is_filter_cell_ = col->primary_key_;
|
||||
cell.name_ = ObString::make_string(col->name_);
|
||||
if (col->is_null_) {
|
||||
cell.value_.reset();
|
||||
} else {
|
||||
cell.value_ = ObString(0, static_cast<int32_t>(col->value_end_pos_ - start_pos), values_.ptr() + start_pos);
|
||||
cell.value_ = ObString(0, static_cast<int32_t>(col->value_end_pos_ - start_pos),
|
||||
values_.ptr() + start_pos);
|
||||
}
|
||||
cell.is_hex_value_ = col->is_hex_value_;
|
||||
if (OB_FAIL(kv_proxy.store_cell(cell, ucell.cell_))) {
|
||||
@ -821,7 +838,7 @@ int ObDMLSqlSplicer::finish_row()
|
||||
LOG_WARN("failed to push back", K(ret), K(last_pos));
|
||||
}
|
||||
} else {
|
||||
int64_t last_row_end_pos = rows_end_pos_.at(N - 1);
|
||||
int64_t last_row_end_pos = rows_end_pos_.at(N-1);
|
||||
if (last_pos <= last_row_end_pos) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("no cells in the row", K(ret), K(last_pos), K(last_row_end_pos));
|
||||
@ -833,7 +850,7 @@ int ObDMLSqlSplicer::finish_row()
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::build_rows_matrix(ObIArray<ObString>& all_names, ObIArray<int64_t>& rows_matrix) const
|
||||
int ObDMLSqlSplicer::build_rows_matrix(ObIArray<ObString> &all_names, ObIArray<int64_t> &rows_matrix) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
hash::ObHashMap<ObString, int64_t> name_idx_map;
|
||||
@ -845,8 +862,9 @@ int ObDMLSqlSplicer::build_rows_matrix(ObIArray<ObString>& all_names, ObIArray<i
|
||||
|
||||
ObArray<int64_t> name_idx_array;
|
||||
int64_t cell_count = columns_.count();
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < cell_count; ++i) {
|
||||
const Column& col = columns_.at(i);
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < cell_count; ++i)
|
||||
{
|
||||
const Column &col = columns_.at(i);
|
||||
ObString cname = ObString::make_string(col.name_);
|
||||
int64_t name_idx = 0;
|
||||
if (OB_FAIL(name_idx_map.get_refactored(cname, name_idx))) {
|
||||
@ -855,10 +873,10 @@ int ObDMLSqlSplicer::build_rows_matrix(ObIArray<ObString>& all_names, ObIArray<i
|
||||
// found a new column name
|
||||
if (OB_FAIL(all_names.push_back(cname))) {
|
||||
LOG_WARN("failed to push back", K(ret));
|
||||
} else if (OB_FAIL(name_idx_map.set_refactored(cname, all_names.count() - 1))) {
|
||||
} else if (OB_FAIL(name_idx_map.set_refactored(cname, all_names.count()-1))) {
|
||||
LOG_WARN("failed to set hashmap", K(ret));
|
||||
} else {
|
||||
name_idx = all_names.count() - 1;
|
||||
name_idx = all_names.count()-1;
|
||||
}
|
||||
} else {
|
||||
LOG_WARN("failed to get name from map", K(ret));
|
||||
@ -871,7 +889,7 @@ int ObDMLSqlSplicer::build_rows_matrix(ObIArray<ObString>& all_names, ObIArray<i
|
||||
LOG_WARN("failed to push back name idx", K(ret));
|
||||
}
|
||||
}
|
||||
} // end for
|
||||
} // end for
|
||||
// invert index
|
||||
hash::ObHashMap<int64_t, int64_t> name_idx_to_pos;
|
||||
if (OB_SUCC(ret)) {
|
||||
@ -881,7 +899,7 @@ int ObDMLSqlSplicer::build_rows_matrix(ObIArray<ObString>& all_names, ObIArray<i
|
||||
}
|
||||
int64_t last_pos = 0;
|
||||
int64_t row_count = rows_end_pos_.count();
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < row_count; ++i) // for each row
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < row_count; ++i) // for each row
|
||||
{
|
||||
int64_t row_end_pos = rows_end_pos_.at(i);
|
||||
if (row_end_pos >= columns_.count()) {
|
||||
@ -899,7 +917,8 @@ int ObDMLSqlSplicer::build_rows_matrix(ObIArray<ObString>& all_names, ObIArray<i
|
||||
// build row
|
||||
int64_t column_count = all_names.count();
|
||||
int64_t pos = -1;
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < column_count; ++i) {
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < column_count; ++i)
|
||||
{
|
||||
if (OB_FAIL(name_idx_to_pos.get_refactored(i, pos))) {
|
||||
if (OB_HASH_NOT_EXIST == ret) {
|
||||
ret = OB_SUCCESS;
|
||||
@ -915,8 +934,8 @@ int ObDMLSqlSplicer::build_rows_matrix(ObIArray<ObString>& all_names, ObIArray<i
|
||||
LOG_WARN("failed to push back to rows matrix", K(ret));
|
||||
}
|
||||
}
|
||||
} // end for
|
||||
} // end for
|
||||
} // end for
|
||||
} // end for
|
||||
#ifndef NDEBUG
|
||||
// sanity check
|
||||
if (OB_SUCC(ret)) {
|
||||
@ -927,9 +946,11 @@ int ObDMLSqlSplicer::build_rows_matrix(ObIArray<ObString>& all_names, ObIArray<i
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("wrong matrix size", K(matrix_size), K(column_count), K(row_count));
|
||||
} else {
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < row_count; ++i) {
|
||||
for (int64_t j = 0; OB_SUCCESS == ret && j < column_count; ++j) {
|
||||
int64_t cell_pos = rows_matrix.at(j + i * column_count);
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < row_count; ++i)
|
||||
{
|
||||
for (int64_t j = 0; OB_SUCCESS == ret && j < column_count; ++j)
|
||||
{
|
||||
int64_t cell_pos = rows_matrix.at(j+i*column_count);
|
||||
if (-1 != cell_pos) {
|
||||
if (cell_pos >= columns_.count()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
@ -939,19 +960,20 @@ int ObDMLSqlSplicer::build_rows_matrix(ObIArray<ObString>& all_names, ObIArray<i
|
||||
LOG_ERROR("cell name not match", K(i), K(j), K(cell_pos));
|
||||
}
|
||||
}
|
||||
} // end for
|
||||
} // end for
|
||||
} // end for
|
||||
} // end for
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int join_strings(const ObString& sep, const ObIArray<ObString>& names, ObSqlString& sql)
|
||||
static int join_strings(const ObString &sep, const ObIArray<ObString> &names, ObSqlString &sql)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t N = names.count();
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < N; ++i) {
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < N; ++i)
|
||||
{
|
||||
if (0 != i) {
|
||||
if (OB_FAIL(sql.append(sep))) {
|
||||
LOG_WARN("failed to append sep", K(ret));
|
||||
@ -962,13 +984,12 @@ static int join_strings(const ObString& sep, const ObIArray<ObString>& names, Ob
|
||||
LOG_WARN("failed to append str", K(ret));
|
||||
}
|
||||
}
|
||||
} // end for
|
||||
} // end for
|
||||
return ret;
|
||||
}
|
||||
|
||||
// (1,2,3), (4,5,6)
|
||||
int ObDMLSqlSplicer::splice_rows_matrix(
|
||||
const ObArray<ObString>& all_names, const ObArray<int64_t>& rows_matrix, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_rows_matrix(const ObArray<ObString> &all_names, const ObArray<int64_t> &rows_matrix, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const int64_t column_count = all_names.count();
|
||||
@ -978,7 +999,8 @@ int ObDMLSqlSplicer::splice_rows_matrix(
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("wrong matrix size", K(matrix_size), K(column_count), K(row_count));
|
||||
} else {
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < row_count; ++i) {
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < row_count; ++i)
|
||||
{
|
||||
if (0 != i) {
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_FAIL(sql.append(", "))) {
|
||||
@ -992,13 +1014,14 @@ int ObDMLSqlSplicer::splice_rows_matrix(
|
||||
LOG_WARN("append sql failed", K(ret));
|
||||
}
|
||||
}
|
||||
for (int64_t j = 0; OB_SUCCESS == ret && j < column_count; ++j) {
|
||||
for (int64_t j = 0; OB_SUCCESS == ret && j < column_count; ++j)
|
||||
{
|
||||
if (0 != j) {
|
||||
if (OB_FAIL(sql.append(","))) {
|
||||
LOG_WARN("append sql failed", K(ret));
|
||||
}
|
||||
}
|
||||
int64_t cell_pos = rows_matrix.at(j + i * column_count);
|
||||
int64_t cell_pos = rows_matrix.at(j+i*column_count);
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (-1 != cell_pos) {
|
||||
if (cell_pos >= columns_.count()) {
|
||||
@ -1008,10 +1031,10 @@ int ObDMLSqlSplicer::splice_rows_matrix(
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("cell name not match", K(i), K(j), K(cell_pos));
|
||||
} else {
|
||||
const Column& col = columns_.at(cell_pos);
|
||||
const Column &col = columns_.at(cell_pos);
|
||||
int64_t start_pos = 0;
|
||||
if (cell_pos >= 1) {
|
||||
start_pos = columns_.at(cell_pos - 1).value_end_pos_;
|
||||
start_pos = columns_.at(cell_pos-1).value_end_pos_;
|
||||
}
|
||||
if (col.is_null_) {
|
||||
ret = sql.append("NULL");
|
||||
@ -1022,21 +1045,21 @@ int ObDMLSqlSplicer::splice_rows_matrix(
|
||||
} else {
|
||||
ret = sql.append("NULL");
|
||||
}
|
||||
} // end for
|
||||
} // end for
|
||||
if (OB_SUCC(ret)) {
|
||||
// end of row
|
||||
if (OB_FAIL(sql.append(")"))) {
|
||||
LOG_WARN("append sql failed", K(ret));
|
||||
}
|
||||
}
|
||||
} // end for
|
||||
} // end for
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_batch_insert(const char* table_name, const char* head, ObSqlString& sql,
|
||||
ObArray<ObString>& all_names, ObArray<int64_t>& rows_matrix) const
|
||||
int ObDMLSqlSplicer::splice_batch_insert(const char *table_name, const char *head, ObSqlString &sql,
|
||||
ObArray<ObString> &all_names, ObArray<int64_t> &rows_matrix) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NULL == table_name || NULL == head) {
|
||||
@ -1061,7 +1084,7 @@ int ObDMLSqlSplicer::splice_batch_insert(const char* table_name, const char* hea
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_batch_insert_sql(const char* table_name, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_batch_insert_sql(const char *table_name, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObArray<ObString> all_names;
|
||||
@ -1078,7 +1101,7 @@ int ObDMLSqlSplicer::splice_batch_insert_sql(const char* table_name, ObSqlString
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_batch_replace_sql_without_plancache(const char* table_name, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_batch_replace_sql_without_plancache(const char *table_name, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObArray<ObString> all_names;
|
||||
@ -1089,14 +1112,13 @@ int ObDMLSqlSplicer::splice_batch_replace_sql_without_plancache(const char* tabl
|
||||
} else if (columns_.count() <= 0) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("column_count is invalid", K(ret), "column_count", columns_.count());
|
||||
} else if (OB_FAIL(
|
||||
splice_batch_insert(table_name, "REPLACE /*+use_plan_cache(none)*/", sql, all_names, rows_matrix))) {
|
||||
} else if (OB_FAIL(splice_batch_insert(table_name, "REPLACE /*+use_plan_cache(none)*/", sql, all_names, rows_matrix))) {
|
||||
LOG_WARN("splice insert failed", K(ret), K(table_name));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_batch_replace_sql(const char* table_name, ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_batch_replace_sql(const char *table_name, ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObArray<ObString> all_names;
|
||||
@ -1114,27 +1136,28 @@ int ObDMLSqlSplicer::splice_batch_replace_sql(const char* table_name, ObSqlStrin
|
||||
}
|
||||
|
||||
// @todo optimize, we could only have non-primary columns here
|
||||
static int splice_on_duplicate_key_update(const ObString& sep, const ObIArray<ObString>& names, ObSqlString& sql)
|
||||
static int splice_on_duplicate_key_update(const ObString &sep, const ObIArray<ObString> &names, ObSqlString &sql)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t N = names.count();
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < N; ++i) {
|
||||
for (int64_t i = 0; OB_SUCCESS == ret && i < N; ++i)
|
||||
{
|
||||
if (0 != i) {
|
||||
if (OB_FAIL(sql.append(sep))) {
|
||||
LOG_WARN("failed to append sep", K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
const ObString& name = names.at(i);
|
||||
const ObString &name = names.at(i);
|
||||
if (OB_FAIL(sql.append_fmt("%.*s=VALUES(%.*s)", name.length(), name.ptr(), name.length(), name.ptr()))) {
|
||||
LOG_WARN("failed to append str", K(ret));
|
||||
}
|
||||
}
|
||||
} // end for
|
||||
} // end for
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_batch_insert_update_sql(const char* table_name, common::ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_batch_insert_update_sql(const char *table_name, common::ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObArray<ObString> all_names;
|
||||
@ -1156,8 +1179,7 @@ int ObDMLSqlSplicer::splice_batch_insert_update_sql(const char* table_name, comm
|
||||
}
|
||||
|
||||
// (c1, c2, c3) IN ((1, 2, 3), (4, 5, 6))
|
||||
int ObDMLSqlSplicer::splice_batch_predicates(
|
||||
const ObArray<ObString>& all_names, const ObArray<int64_t>& rows_matrix, common::ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_batch_predicates(const ObArray<ObString> &all_names, const ObArray<int64_t> &rows_matrix, common::ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t column_count = all_names.count();
|
||||
@ -1174,7 +1196,7 @@ int ObDMLSqlSplicer::splice_batch_predicates(
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
const ObString& name = all_names.at(i);
|
||||
const ObString &name = all_names.at(i);
|
||||
if (OB_FAIL(sql.append_fmt("%.*s", name.length(), name.ptr()))) {
|
||||
LOG_WARN("append sql failed", K(ret));
|
||||
}
|
||||
@ -1194,7 +1216,7 @@ int ObDMLSqlSplicer::splice_batch_predicates(
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_batch_delete_sql(const char* table_name, common::ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_batch_delete_sql(const char *table_name, common::ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObArray<ObString> all_names;
|
||||
@ -1212,14 +1234,15 @@ int ObDMLSqlSplicer::splice_batch_delete_sql(const char* table_name, common::ObS
|
||||
} else if (OB_FAIL(splice_batch_predicates(all_names, rows_matrix, sql))) {
|
||||
LOG_WARN("failed to splice batch predicates", K(ret));
|
||||
} else if (!extra_condition_.empty()) {
|
||||
if (OB_FAIL(sql.append_fmt(" AND %.*s", static_cast<int32_t>(extra_condition_.length()), extra_condition_.ptr()))) {
|
||||
if (OB_FAIL(sql.append_fmt(" AND %.*s",
|
||||
static_cast<int32_t>(extra_condition_.length()), extra_condition_.ptr()))) {
|
||||
LOG_WARN("add extra condition failed", K(ret), K_(extra_condition));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLSqlSplicer::splice_batch_predicates_sql(common::ObSqlString& sql) const
|
||||
int ObDMLSqlSplicer::splice_batch_predicates_sql(common::ObSqlString &sql) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObArray<ObString> all_names;
|
||||
@ -1236,20 +1259,21 @@ int ObDMLSqlSplicer::splice_batch_predicates_sql(common::ObSqlString& sql) const
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
#define DEF_DML_EXECUTE(dml) \
|
||||
int ObDMLExecHelper::exec_##dml(const char* table_name, const ObDMLSqlSplicer& splicer, int64_t& affected_rows) \
|
||||
{ \
|
||||
int ret = OB_SUCCESS; \
|
||||
ObSqlString sql; \
|
||||
if (NULL == table_name) { \
|
||||
ret = OB_INVALID_ARGUMENT; \
|
||||
LOG_WARN("invalid argument", K(ret), KP(table_name)); \
|
||||
} else if (OB_FAIL(splicer.splice_##dml##_sql(table_name, sql))) { \
|
||||
LOG_WARN("splice sql failed", K(ret)); \
|
||||
} else if (OB_FAIL(sql_client_.write(tenant_id_, sql.ptr(), affected_rows))) { \
|
||||
LOG_WARN("execute sql failed", K(ret), K(sql)); \
|
||||
} \
|
||||
return ret; \
|
||||
#define DEF_DML_EXECUTE(dml) \
|
||||
int ObDMLExecHelper::exec_##dml(const char *table_name, \
|
||||
const ObDMLSqlSplicer &splicer, int64_t &affected_rows) \
|
||||
{ \
|
||||
int ret = OB_SUCCESS; \
|
||||
ObSqlString sql; \
|
||||
if (NULL == table_name) { \
|
||||
ret = OB_INVALID_ARGUMENT; \
|
||||
LOG_WARN("invalid argument", K(ret), KP(table_name)); \
|
||||
} else if (OB_FAIL(splicer.splice_##dml##_sql(table_name, sql))) { \
|
||||
LOG_WARN("splice sql failed", K(ret)); \
|
||||
} else if (OB_FAIL(sql_client_.write(tenant_id_, sql.ptr(), affected_rows))) { \
|
||||
LOG_WARN("execute sql failed", K(ret), K(sql)); \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
DEF_DML_EXECUTE(insert);
|
||||
@ -1260,7 +1284,8 @@ DEF_DML_EXECUTE(insert_update);
|
||||
|
||||
#undef DEF_DML_EXECUTE
|
||||
|
||||
int ObDMLExecHelper::exec_insert_ignore(const char* table_name, const ObDMLSqlSplicer& splicer, int64_t& affected_rows)
|
||||
int ObDMLExecHelper::exec_insert_ignore(const char *table_name,
|
||||
const ObDMLSqlSplicer &splicer, int64_t &affected_rows)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool exist = false;
|
||||
@ -1285,7 +1310,8 @@ int ObDMLExecHelper::exec_insert_ignore(const char* table_name, const ObDMLSqlSp
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLExecHelper::check_row_exist(const char* table_name, const ObDMLSqlSplicer& splicer, bool& exist)
|
||||
int ObDMLExecHelper::check_row_exist(const char *table_name,
|
||||
const ObDMLSqlSplicer &splicer, bool &exist)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
exist = false;
|
||||
@ -1296,8 +1322,7 @@ int ObDMLExecHelper::check_row_exist(const char* table_name, const ObDMLSqlSplic
|
||||
} else if (OB_FAIL(splicer.splice_select_1_sql(table_name, sql))) {
|
||||
LOG_WARN("splice select sql failed", K(ret));
|
||||
} else {
|
||||
SMART_VAR(ObMySQLProxy::MySQLResult, res)
|
||||
{
|
||||
SMART_VAR(ObMySQLProxy::MySQLResult, res) {
|
||||
if (OB_FAIL(sql_client_.read(res, tenant_id_, sql.ptr()))) {
|
||||
LOG_WARN("execute query failed", K(ret), K(sql));
|
||||
} else {
|
||||
@ -1318,5 +1343,5 @@ int ObDMLExecHelper::check_row_exist(const char* table_name, const ObDMLSqlSplic
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // end namespace share
|
||||
} // end namespace oceanbase
|
||||
} // end namespace share
|
||||
} // end namespace oceanbase
|
||||
|
||||
Reference in New Issue
Block a user