fix check_db_and_table_is_exist func when table name with special symbol
This commit is contained in:
4
deps/oblib/src/common/object/ob_object.cpp
vendored
4
deps/oblib/src/common/object/ob_object.cpp
vendored
@ -2221,7 +2221,7 @@ DEF_TO_STRING(ObHexEscapeSqlStr)
|
|||||||
int64_t buf_pos = 0;
|
int64_t buf_pos = 0;
|
||||||
if (buf != NULL && buf_len > 0 && !str_.empty()) {
|
if (buf != NULL && buf_len > 0 && !str_.empty()) {
|
||||||
const char *end = str_.ptr() + str_.length();
|
const char *end = str_.ptr() + str_.length();
|
||||||
if (lib::is_oracle_mode()) {
|
if (do_oracle_mode_escape_) {
|
||||||
for (const char *cur = str_.ptr(); cur < end && buf_pos < buf_len; ++cur) {
|
for (const char *cur = str_.ptr(); cur < end && buf_pos < buf_len; ++cur) {
|
||||||
if ('\'' == *cur) {
|
if ('\'' == *cur) {
|
||||||
//在oracle模式中,只处理单引号转义
|
//在oracle模式中,只处理单引号转义
|
||||||
@ -2301,7 +2301,7 @@ int64_t ObHexEscapeSqlStr::get_extra_length() const
|
|||||||
int64_t ret_length = 0;
|
int64_t ret_length = 0;
|
||||||
if (!str_.empty()) {
|
if (!str_.empty()) {
|
||||||
const char *end = str_.ptr() + str_.length();
|
const char *end = str_.ptr() + str_.length();
|
||||||
if (lib::is_oracle_mode()) {
|
if (do_oracle_mode_escape_) {
|
||||||
for (const char *cur = str_.ptr(); cur < end; ++cur) {
|
for (const char *cur = str_.ptr(); cur < end; ++cur) {
|
||||||
if ('\'' == *cur) {
|
if ('\'' == *cur) {
|
||||||
++ret_length;
|
++ret_length;
|
||||||
|
|||||||
11
deps/oblib/src/common/object/ob_object.h
vendored
11
deps/oblib/src/common/object/ob_object.h
vendored
@ -4073,15 +4073,22 @@ class ObHexEscapeSqlStr
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ObHexEscapeSqlStr(const common::ObString &str) : str_(str),
|
ObHexEscapeSqlStr(const common::ObString &str) : str_(str),
|
||||||
skip_escape_(false) { }
|
skip_escape_(false),
|
||||||
|
do_oracle_mode_escape_(lib::is_oracle_mode()) { }
|
||||||
ObHexEscapeSqlStr(const common::ObString &str, const bool skip_escape) : str_(str),
|
ObHexEscapeSqlStr(const common::ObString &str, const bool skip_escape) : str_(str),
|
||||||
skip_escape_(skip_escape){ }
|
skip_escape_(skip_escape),
|
||||||
|
do_oracle_mode_escape_(lib::is_oracle_mode()){ }
|
||||||
|
ObHexEscapeSqlStr(const common::ObString &str,
|
||||||
|
const bool skip_escape,
|
||||||
|
const bool do_oracle_mode_escape)
|
||||||
|
: str_(str), skip_escape_(skip_escape), do_oracle_mode_escape_(do_oracle_mode_escape){ }
|
||||||
ObString str() const { return str_; }
|
ObString str() const { return str_; }
|
||||||
int64_t get_extra_length() const;
|
int64_t get_extra_length() const;
|
||||||
DECLARE_TO_STRING;
|
DECLARE_TO_STRING;
|
||||||
private:
|
private:
|
||||||
ObString str_;
|
ObString str_;
|
||||||
bool skip_escape_;
|
bool skip_escape_;
|
||||||
|
bool do_oracle_mode_escape_;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Ob2DArray<ObObjParam, OB_MALLOC_BIG_BLOCK_SIZE,
|
typedef Ob2DArray<ObObjParam, OB_MALLOC_BIG_BLOCK_SIZE,
|
||||||
|
|||||||
@ -16212,15 +16212,26 @@ int ObDDLService::check_db_and_table_is_exist(const obrpc::ObTruncateTableArg &a
|
|||||||
? true : false;
|
? true : false;
|
||||||
SMART_VAR(ObMySQLProxy::MySQLResult, res) {
|
SMART_VAR(ObMySQLProxy::MySQLResult, res) {
|
||||||
common::sqlclient::ObMySQLResult *result = NULL;
|
common::sqlclient::ObMySQLResult *result = NULL;
|
||||||
if (OB_FAIL(sql.assign_fmt("SELECT session_id, a.database_id, table_id, database_name, table_name "
|
bool skip_escape = false;
|
||||||
|
// Before checking the table name, we should use mysql mode to escape the table name anyway,
|
||||||
|
// otherwise we may not find the table name in select sql
|
||||||
|
bool do_oracle_mode_escape = false;
|
||||||
|
const char *tmp_table_name = to_cstring(ObHexEscapeSqlStr(table_name, skip_escape, do_oracle_mode_escape));
|
||||||
|
const char *tmp_database_name = to_cstring(ObHexEscapeSqlStr(database_name, skip_escape, do_oracle_mode_escape));
|
||||||
|
if (OB_ISNULL(tmp_table_name)) {
|
||||||
|
ret = OB_ERR_UNEXPECTED;
|
||||||
|
LOG_WARN("table name is NULL", KR(ret), K(tenant_id));
|
||||||
|
} else if (OB_ISNULL(tmp_database_name)) {
|
||||||
|
ret = OB_ERR_UNEXPECTED;
|
||||||
|
LOG_WARN("database name is NULL", KR(ret), K(tenant_id));
|
||||||
|
} else if (OB_FAIL(sql.assign_fmt("SELECT session_id, a.database_id, table_id, database_name, table_name "
|
||||||
"FROM %s a JOIN (SELECT session_id, database_id, table_id, table_name FROM %s "
|
"FROM %s a JOIN (SELECT session_id, database_id, table_id, table_name FROM %s "
|
||||||
"UNION ALL SELECT session_id, database_id, table_id, table_name FROM %s WHERE tenant_id = %ld) c "
|
"UNION ALL SELECT session_id, database_id, table_id, table_name FROM %s WHERE tenant_id = %ld) c "
|
||||||
"ON a.database_id = c.database_id WHERE a.database_name = '%.*s' AND table_name = '%.*s' "
|
"ON a.database_id = c.database_id WHERE a.database_name = '%s' AND table_name = '%s' "
|
||||||
"AND (session_id = 0 or session_id = %lu) order by session_id desc",
|
"AND (session_id = 0 or session_id = %lu) order by session_id desc",
|
||||||
OB_ALL_DATABASE_TNAME, OB_ALL_TABLE_TNAME,
|
OB_ALL_DATABASE_TNAME, OB_ALL_TABLE_TNAME,
|
||||||
OB_ALL_VIRTUAL_CORE_ALL_TABLE_TNAME, tenant_id,
|
OB_ALL_VIRTUAL_CORE_ALL_TABLE_TNAME, tenant_id,
|
||||||
database_name.length(), database_name.ptr(),
|
tmp_database_name, tmp_table_name, session_id))) {
|
||||||
table_name.length(), table_name.ptr(), session_id))) {
|
|
||||||
LOG_WARN("failed assing sql", KR(ret), K(table_name), K(database_name), K(session_id));
|
LOG_WARN("failed assing sql", KR(ret), K(table_name), K(database_name), K(session_id));
|
||||||
} else if (OB_FAIL(trans.read(res, tenant_id, sql.ptr()))) {
|
} else if (OB_FAIL(trans.read(res, tenant_id, sql.ptr()))) {
|
||||||
LOG_WARN("failed to execute sql", KR(ret), K(tenant_id), K(table_name), K(database_name), K(session_id), K(sql));
|
LOG_WARN("failed to execute sql", KR(ret), K(tenant_id), K(table_name), K(database_name), K(session_id), K(sql));
|
||||||
|
|||||||
@ -2041,6 +2041,35 @@ ObTruncateTableExecutor::~ObTruncateTableExecutor()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ObTruncateTableExecutor::check_use_parallel_truncate(const obrpc::ObTruncateTableArg &arg, bool &use_parallel_truncate)
|
||||||
|
{
|
||||||
|
int ret = OB_SUCCESS;
|
||||||
|
uint64_t compat_version = 0;
|
||||||
|
use_parallel_truncate = false;
|
||||||
|
const ObTableSchema *table_schema = NULL;
|
||||||
|
const uint64_t tenant_id = arg.tenant_id_;
|
||||||
|
const ObString table_name = arg.table_name_;
|
||||||
|
const ObString database_name = arg.database_name_;
|
||||||
|
share::schema::ObSchemaGetterGuard schema_guard;
|
||||||
|
if (OB_FAIL(GET_MIN_DATA_VERSION(tenant_id, compat_version))) {
|
||||||
|
LOG_WARN("get min data_version failed", K(ret), K(tenant_id));
|
||||||
|
} else if (OB_ISNULL(GCTX.schema_service_)) {
|
||||||
|
ret = OB_NOT_INIT;
|
||||||
|
LOG_WARN("GCTX schema_service not init", K(ret));
|
||||||
|
} else if (OB_FAIL(GCTX.schema_service_->get_tenant_schema_guard(tenant_id, schema_guard))) {
|
||||||
|
LOG_WARN("fail to get tenant schema guard", K(ret), K(tenant_id));
|
||||||
|
} else if (FALSE_IT(schema_guard.set_session_id(arg.session_id_))) {
|
||||||
|
} else if (OB_FAIL(schema_guard.get_table_schema(tenant_id, database_name, table_name, false, table_schema))) {
|
||||||
|
LOG_WARN("fail to get table schema", K(ret), K(database_name), K(table_name));
|
||||||
|
} else if (OB_ISNULL(table_schema)) {
|
||||||
|
ret = OB_TABLE_NOT_EXIST;
|
||||||
|
LOG_WARN("table is not exist", K(ret), K(database_name), K(table_name));
|
||||||
|
} else {
|
||||||
|
use_parallel_truncate = table_schema->get_autoinc_column_id() == 0 && compat_version >= DATA_VERSION_4_1_0_0;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int ObTruncateTableExecutor::execute(ObExecContext &ctx, ObTruncateTableStmt &stmt)
|
int ObTruncateTableExecutor::execute(ObExecContext &ctx, ObTruncateTableStmt &stmt)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
@ -2073,33 +2102,16 @@ int ObTruncateTableExecutor::execute(ObExecContext &ctx, ObTruncateTableStmt &st
|
|||||||
//impossible
|
//impossible
|
||||||
} else if (!stmt.is_truncate_oracle_temp_table()) {
|
} else if (!stmt.is_truncate_oracle_temp_table()) {
|
||||||
int64_t foreign_key_checks = 0;
|
int64_t foreign_key_checks = 0;
|
||||||
share::schema::ObSchemaGetterGuard schema_guard;
|
|
||||||
my_session->get_foreign_key_checks(foreign_key_checks);
|
my_session->get_foreign_key_checks(foreign_key_checks);
|
||||||
tmp_arg.foreign_key_checks_ = is_oracle_mode() || (is_mysql_mode() && foreign_key_checks);
|
tmp_arg.foreign_key_checks_ = is_oracle_mode() || (is_mysql_mode() && foreign_key_checks);
|
||||||
tmp_arg.compat_mode_ = ORACLE_MODE == my_session->get_compatibility_mode()
|
tmp_arg.compat_mode_ = ORACLE_MODE == my_session->get_compatibility_mode()
|
||||||
? lib::Worker::CompatMode::ORACLE : lib::Worker::CompatMode::MYSQL;
|
? lib::Worker::CompatMode::ORACLE : lib::Worker::CompatMode::MYSQL;
|
||||||
int64_t affected_rows = 0;
|
int64_t affected_rows = 0;
|
||||||
uint64_t compat_version = 0;
|
bool use_parallel_truncate = false;
|
||||||
const ObTableSchema *table_schema = NULL;
|
|
||||||
const uint64_t tenant_id = truncate_table_arg.tenant_id_;
|
const uint64_t tenant_id = truncate_table_arg.tenant_id_;
|
||||||
const ObString table_name = truncate_table_arg.table_name_;
|
if (OB_FAIL(check_use_parallel_truncate(truncate_table_arg, use_parallel_truncate))) {
|
||||||
const ObString database_name = truncate_table_arg.database_name_;
|
LOG_WARN("fail to check use parallel trunate", KR(ret), K(truncate_table_arg));
|
||||||
if (OB_FAIL(GET_MIN_DATA_VERSION(tenant_id, compat_version))) {
|
} else if (!use_parallel_truncate) {
|
||||||
LOG_WARN("get min data_version failed", K(ret), K(tenant_id));
|
|
||||||
} else if (OB_ISNULL(GCTX.schema_service_)) {
|
|
||||||
ret = OB_NOT_INIT;
|
|
||||||
LOG_WARN("GCTX schema_service not init", K(ret));
|
|
||||||
} else if (OB_FAIL(GCTX.schema_service_->get_tenant_schema_guard(tenant_id, schema_guard))) {
|
|
||||||
LOG_WARN("fail to get tenant schema guard", K(ret), K(tenant_id));
|
|
||||||
} else if (FALSE_IT(schema_guard.set_session_id(truncate_table_arg.session_id_))) {
|
|
||||||
} else if (OB_FAIL(schema_guard.get_table_schema(tenant_id, database_name, table_name, false, table_schema))) {
|
|
||||||
LOG_WARN("fail to get table schema", K(ret), K(database_name), K(table_name));
|
|
||||||
} else if (OB_ISNULL(table_schema)) {
|
|
||||||
ret = OB_TABLE_NOT_EXIST;
|
|
||||||
LOG_WARN("table is not exist", K(ret), K(database_name), K(table_name));
|
|
||||||
// Avoiding the impact of new_truncate_table on mysql auotinc, then we need to execute the old logic
|
|
||||||
} else if (compat_version < DATA_VERSION_4_1_0_0
|
|
||||||
|| table_schema->get_autoinc_column_id() != 0) {
|
|
||||||
if (OB_FAIL(common_rpc_proxy->truncate_table(truncate_table_arg, res))) {
|
if (OB_FAIL(common_rpc_proxy->truncate_table(truncate_table_arg, res))) {
|
||||||
LOG_WARN("rpc proxy alter table failed", K(ret));
|
LOG_WARN("rpc proxy alter table failed", K(ret));
|
||||||
} else if (res.is_valid()
|
} else if (res.is_valid()
|
||||||
@ -2162,7 +2174,6 @@ int ObTruncateTableExecutor::execute(ObExecContext &ctx, ObTruncateTableStmt &st
|
|||||||
K(res));
|
K(res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ObSqlString sql;
|
ObSqlString sql;
|
||||||
int64_t affect_rows = 0;
|
int64_t affect_rows = 0;
|
||||||
|
|||||||
@ -221,6 +221,7 @@ public:
|
|||||||
virtual ~ObTruncateTableExecutor();
|
virtual ~ObTruncateTableExecutor();
|
||||||
int execute(ObExecContext &ctx, ObTruncateTableStmt &stmt);
|
int execute(ObExecContext &ctx, ObTruncateTableStmt &stmt);
|
||||||
private:
|
private:
|
||||||
|
int check_use_parallel_truncate(const obrpc::ObTruncateTableArg &arg, bool &use_parallel_truncate);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user