Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
oceanbase
oceanbase
提交
04a4317f
O
oceanbase
项目概览
oceanbase
/
oceanbase
2 年多 前同步成功
通知
263
Star
6084
Fork
1301
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
oceanbase
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
04a4317f
编写于
11月 12, 2025
作者:
O
obdev
提交者:
ob-robot
11月 12, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix create index report 5019.
上级
66d983f9
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
94 addition
and
27 deletion
+94
-27
src/rootserver/ob_create_index_on_empty_table_helper.cpp
src/rootserver/ob_create_index_on_empty_table_helper.cpp
+6
-2
src/rootserver/ob_create_index_on_empty_table_helper.h
src/rootserver/ob_create_index_on_empty_table_helper.h
+1
-0
src/rootserver/ob_ddl_service.cpp
src/rootserver/ob_ddl_service.cpp
+18
-4
src/rootserver/ob_ddl_service.h
src/rootserver/ob_ddl_service.h
+2
-1
src/rootserver/ob_index_builder.cpp
src/rootserver/ob_index_builder.cpp
+14
-0
src/rootserver/parallel_ddl/ob_create_index_helper.cpp
src/rootserver/parallel_ddl/ob_create_index_helper.cpp
+7
-0
src/share/ob_ddl_common.cpp
src/share/ob_ddl_common.cpp
+29
-20
src/share/ob_ddl_common.h
src/share/ob_ddl_common.h
+1
-0
src/share/schema/ob_latest_schema_guard.cpp
src/share/schema/ob_latest_schema_guard.cpp
+14
-0
src/share/schema/ob_latest_schema_guard.h
src/share/schema/ob_latest_schema_guard.h
+2
-0
未找到文件。
src/rootserver/ob_create_index_on_empty_table_helper.cpp
浏览文件 @
04a4317f
...
...
@@ -26,6 +26,7 @@ namespace rootserver
int
ObCreateIndexOnEmptyTableHelper
::
check_create_index_on_empty_table_opt
(
rootserver
::
ObDDLService
&
ddl_service
,
ObMySQLTransaction
&
trans
,
const
share
::
schema
::
ObSysVariableSchema
&
sys_var_schema
,
const
ObString
&
database_name
,
const
share
::
schema
::
ObTableSchema
&
table_schema
,
ObIndexType
index_type
,
...
...
@@ -36,7 +37,7 @@ int ObCreateIndexOnEmptyTableHelper::check_create_index_on_empty_table_opt(
is_create_index_on_empty_table_opt
=
false
;
if
(
DATA_VERSION_SUPPORT_EMPTY_TABLE_CREATE_INDEX_OPT
(
executor_data_version
))
{
if
(
!
share
::
schema
::
is_index_support_empty_table_opt
(
index_type
)
&&
index_type
!=
ObIndexType
::
INDEX_TYPE_IS_NOT
)
{
}
else
if
(
OB_FAIL
(
ObDDLUtil
::
check_table_empty
(
database_name
,
}
else
if
(
OB_FAIL
(
ObDDLUtil
::
check_table_empty
(
sys_var_schema
,
database_name
,
table_schema
,
sql_mode
,
is_create_index_on_empty_table_opt
)))
{
...
...
@@ -49,13 +50,16 @@ int ObCreateIndexOnEmptyTableHelper::check_create_index_on_empty_table_opt(
}
else
{
LOG_WARN
(
"failed to lock table"
,
KR
(
ret
),
K
(
table_schema
));
}
}
else
if
(
OB_FAIL
(
ObDDLUtil
::
check_table_empty
(
database_name
,
}
else
if
(
OB_FAIL
(
ObDDLUtil
::
check_table_empty
(
sys_var_schema
,
database_name
,
table_schema
,
sql_mode
,
is_create_index_on_empty_table_opt
)))
{
LOG_WARN
(
"failed to check table empty"
,
KR
(
ret
),
K
(
database_name
),
K
(
table_schema
));
}
}
LOG_TRACE
(
"check_create_index_on_empty_table_opt"
,
K
(
ret
),
K
(
is_create_index_on_empty_table_opt
),
"name_case_mode"
,
sys_var_schema
.
get_name_case_mode
(),
K
(
database_name
),
"table_name"
,
table_schema
.
get_table_name_str
());
return
ret
;
}
...
...
src/rootserver/ob_create_index_on_empty_table_helper.h
浏览文件 @
04a4317f
...
...
@@ -29,6 +29,7 @@ public:
static
int
check_create_index_on_empty_table_opt
(
rootserver
::
ObDDLService
&
ddl_service
,
ObMySQLTransaction
&
trans
,
const
share
::
schema
::
ObSysVariableSchema
&
sys_var_schema
,
const
ObString
&
database_name
,
const
share
::
schema
::
ObTableSchema
&
table_schema
,
ObIndexType
index_type
,
...
...
src/rootserver/ob_ddl_service.cpp
浏览文件 @
04a4317f
...
...
@@ -15382,7 +15382,7 @@ int ObDDLService::check_need_add_progressive_round(
return ret;
}
int ObDDLService::check_is_only_add_index_on_empty_table(ObMySQLTransaction &trans,
int ObDDLService::check_is_only_add_index_on_empty_table(Ob
SchemaGetterGuard &schema_guard, Ob
MySQLTransaction &trans,
const ObString &database_name,
const share::schema::ObTableSchema &table_schema,
const obrpc::ObAlterTableArg &alter_table_arg,
...
...
@@ -15405,8 +15405,16 @@ int ObDDLService::check_is_only_add_index_on_empty_table(ObMySQLTransaction &tra
}
}
if (OB_SUCC(ret) && is_only_creata_index_on_empty_table) {
if (OB_FAIL(ObCreateIndexOnEmptyTableHelper::check_create_index_on_empty_table_opt(*this,
const ObSysVariableSchema *sys_var_schema = nullptr;
const uint64_t tenant_id = table_schema.get_tenant_id();
if (OB_FAIL(schema_guard.get_sys_variable_schema(tenant_id, sys_var_schema))) {
LOG_WARN("fail to get sysvar schema", KR(ret), K(tenant_id));
} else if (OB_ISNULL(sys_var_schema)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("sys_var_schema is null", KR(ret));
} else if (OB_FAIL(ObCreateIndexOnEmptyTableHelper::check_create_index_on_empty_table_opt(*this,
trans,
*sys_var_schema,
database_name,
table_schema,
ObIndexType::INDEX_TYPE_IS_NOT,
...
...
@@ -15628,7 +15636,7 @@ int ObDDLService::alter_table_in_trans(obrpc::ObAlterTableArg &alter_table_arg,
orig_table_schema->get_table_id(),
ddl_operator, *schema_service_))) {
LOG_WARN("failed to modify obj status", K(ret));
} else if (OB_FAIL(check_is_only_add_index_on_empty_table(trans,
} else if (OB_FAIL(check_is_only_add_index_on_empty_table(
schema_guard,
trans,
alter_table_schema.get_origin_database_name(),
new_table_schema,
alter_table_arg,
...
...
@@ -17561,14 +17569,20 @@ int ObDDLService::add_not_null_column_default_null_to_table_schema(
bool is_table_empty = false;
bool is_oracle_mode = false;
const uint64_t tenant_id = origin_table_schema.get_tenant_id();
const ObSysVariableSchema *sys_var_schema = nullptr;
if (OB_FAIL(origin_table_schema.check_if_oracle_compat_mode(is_oracle_mode))) {
LOG_WARN("fail to check is oracle mode", K(ret), K(origin_table_schema));
} else if (OB_FAIL(schema_guard.get_sys_variable_schema(tenant_id, sys_var_schema))) {
LOG_WARN("fail to get sysvar schema", KR(ret), K(tenant_id));
} else if (OB_ISNULL(sys_var_schema)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("sys_var_schema is null", KR(ret));
} else if (OB_UNLIKELY(!is_oracle_mode)) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("add column not null in mysql mode is online ddl, not offline ddl", K(ret), K(is_oracle_mode));
} else if (OB_FAIL(lock_table(trans, origin_table_schema))) {
LOG_WARN("failed to lock ddl lock", K(ret));
} else if (OB_FAIL(ObDDLUtil::check_table_empty(alter_table_arg.alter_table_schema_.get_origin_database_name(),
} else if (OB_FAIL(ObDDLUtil::check_table_empty(
*sys_var_schema,
alter_table_arg.alter_table_schema_.get_origin_database_name(),
origin_table_schema,
alter_table_arg.sql_mode_,
is_table_empty))) {
src/rootserver/ob_ddl_service.h
浏览文件 @
04a4317f
...
...
@@ -1366,7 +1366,8 @@ int check_will_be_having_domain_index_operation(
common
::
ObMySQLTransaction
&
trans
,
const
share
::
schema
::
ObSchemaOperationType
operation_type
,
const
common
::
ObString
&
ddl_stmt_str
);
int
check_is_only_add_index_on_empty_table
(
ObMySQLTransaction
&
trans
,
int
check_is_only_add_index_on_empty_table
(
ObSchemaGetterGuard
&
schema_guard
,
ObMySQLTransaction
&
trans
,
const
ObString
&
database_name
,
const
share
::
schema
::
ObTableSchema
&
table_schema
,
const
obrpc
::
ObAlterTableArg
&
alter_table_arg
,
...
...
src/rootserver/ob_index_builder.cpp
浏览文件 @
04a4317f
...
...
@@ -605,6 +605,7 @@ int ObIndexBuilder::do_create_global_index(
const
uint64_t
tenant_id
=
table_schema
.
get_tenant_id
();
bool
create_index_on_empty_table_opt
=
false
;
const
ObString
&
database_name
=
arg
.
database_name_
;
const
ObSysVariableSchema
*
sys_var_schema
=
nullptr
;
if
(
database_name
.
empty
())
{
ret
=
OB_INVALID_ARGUMENT
;
LOG_WARN
(
"database name is empty"
,
K
(
ret
),
K
(
database_name
));
...
...
@@ -622,8 +623,14 @@ int ObIndexBuilder::do_create_global_index(
}
else
if
(
!
new_arg
.
is_valid
())
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"fail to copy create index arg"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
schema_guard
.
get_sys_variable_schema
(
tenant_id
,
sys_var_schema
)))
{
LOG_WARN
(
"fail to get sysvar schema"
,
KR
(
ret
),
K
(
tenant_id
));
}
else
if
(
OB_ISNULL
(
sys_var_schema
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"sys_var_schema is null"
,
KR
(
ret
));
}
else
if
(
OB_FAIL
(
ObCreateIndexOnEmptyTableHelper
::
check_create_index_on_empty_table_opt
(
ddl_service_
,
trans
,
*
sys_var_schema
,
database_name
,
table_schema
,
new_arg
.
index_type_
,
...
...
@@ -1415,6 +1422,7 @@ int ObIndexBuilder::do_create_local_index(
ObDocIDType
type
=
ObDocIDType
::
INVALID
;
bool
create_index_on_empty_table_opt
=
false
;
const
ObString
&
database_name
=
create_index_arg
.
database_name_
;
const
ObSysVariableSchema
*
sys_var_schema
=
nullptr
;
if
(
database_name
.
empty
())
{
ret
=
OB_INVALID_ARGUMENT
;
LOG_WARN
(
"database name is empty"
,
K
(
ret
),
K
(
database_name
));
...
...
@@ -1440,8 +1448,14 @@ int ObIndexBuilder::do_create_local_index(
}
else
if
(
!
my_arg
.
is_valid
())
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"fail to copy create index arg"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
schema_guard
.
get_sys_variable_schema
(
tenant_id
,
sys_var_schema
)))
{
LOG_WARN
(
"fail to get sysvar schema"
,
KR
(
ret
),
K
(
tenant_id
));
}
else
if
(
OB_ISNULL
(
sys_var_schema
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"sys_var_schema is null"
,
KR
(
ret
));
}
else
if
(
OB_FAIL
(
ObCreateIndexOnEmptyTableHelper
::
check_create_index_on_empty_table_opt
(
ddl_service_
,
trans
,
*
sys_var_schema
,
database_name
,
table_schema
,
my_arg
.
index_type_
,
...
...
src/rootserver/parallel_ddl/ob_create_index_helper.cpp
浏览文件 @
04a4317f
...
...
@@ -65,6 +65,7 @@ int ObCreateIndexHelper::lock_objects_()
{
int
ret
=
OB_SUCCESS
;
const
ObDatabaseSchema
*
database_schema
=
NULL
;
const
ObSysVariableSchema
*
sysvar_schema
=
nullptr
;
DEBUG_SYNC
(
BEFORE_PARALLEL_DDL_LOCK
);
if
(
OB_FAIL
(
check_inner_stat_
()))
{
LOG_WARN
(
"fail to check inner stat"
,
KR
(
ret
));
...
...
@@ -94,8 +95,14 @@ int ObCreateIndexHelper::lock_objects_()
ret
=
OB_ERR_PARALLEL_DDL_CONFLICT
;
LOG_WARN
(
"database_schema's database name not equal to arg"
,
KR
(
ret
),
K
(
database_schema
->
get_database_name_str
()),
K_
(
arg_
.
database_name
));
}
else
if
(
OB_FAIL
(
latest_schema_guard_
.
get_sys_variable_schema
(
sysvar_schema
)))
{
LOG_WARN
(
"fail to get sysvar schema"
,
KR
(
ret
),
K_
(
tenant_id
));
}
else
if
(
OB_ISNULL
(
sysvar_schema
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"sysvar_schema is null"
,
KR
(
ret
));
}
else
if
(
OB_FAIL
(
ObCreateIndexOnEmptyTableHelper
::
check_create_index_on_empty_table_opt
(
*
ddl_service_
,
get_trans_
(),
*
sysvar_schema
,
arg_
.
database_name_
,
*
orig_data_table_schema_
,
arg_
.
index_type_
,
...
...
src/share/ob_ddl_common.cpp
浏览文件 @
04a4317f
...
...
@@ -5013,12 +5013,14 @@ int ObDDLUtil::check_tablet_checksum_error(
}
int
ObDDLUtil
::
check_table_empty
(
const
share
::
schema
::
ObSysVariableSchema
&
sys_var_schema
,
const
ObString
&
database_name
,
const
share
::
schema
::
ObTableSchema
&
table_schema
,
const
ObSQLMode
sql_mode
,
bool
&
is_table_empty
)
{
int
ret
=
OB_SUCCESS
;
UNUSED
(
sql_mode
);
is_table_empty
=
false
;
bool
is_oracle_mode
=
false
;
uint64_t
table_id
=
OB_INVALID_ID
;
...
...
@@ -5032,34 +5034,46 @@ int ObDDLUtil::check_table_empty(
}
else
if
(
OB_FAIL
(
table_schema
.
check_if_oracle_compat_mode
(
is_oracle_mode
)))
{
LOG_WARN
(
"fail to check is oracle mode"
,
K
(
ret
),
K
(
table_schema
));
}
else
{
const
ObString
&
check_expr_str
=
"1 != 1"
;
const
ObString
&
table_name
=
table_schema
.
get_table_name_str
();
ObSqlString
sql_string
;
ObSessionParam
session_param
;
int64_t
new_sql_mode
=
static_cast
<
int64_t
>
(
sql_mode
);
session_param
.
sql_mode_
=
&
new_sql_mode
;
session_param
.
tz_info_wrap_
=
nullptr
;
session_param
.
ddl_info_
.
set_is_ddl
(
true
);
session_param
.
ddl_info_
.
set_retryable_ddl
(
true
);
session_param
.
ddl_info_
.
set_source_table_hidden
(
table_schema
.
is_user_hidden_table
());
session_param
.
ddl_info_
.
set_dest_table_hidden
(
false
);
ObTimeoutCtx
timeout_ctx
;
ObCommonSqlProxy
*
sql_proxy
=
nullptr
;
const
char
*
format_str
=
nullptr
;
const
uint64_t
tenant_id
=
table_schema
.
get_tenant_id
();
ObOracleSqlProxy
oracle_sql_proxy
(
*
GCTX
.
sql_proxy_
);
ObSingleConnectionProxy
single_conn_proxy
;
sqlclient
::
ObISQLConnection
*
connection
=
nullptr
;
const
ObSysVarSchema
*
var_schema
=
nullptr
;
if
(
is_oracle_mode
)
{
format_str
=
"SELECT /*+ %.*s */ 1 FROM
\"
%.*s
\"
.
\"
%.*s
\"
WHERE NOT 1 != 1 AND ROWNUM = 1"
;
sql_proxy
=
GCTX
.
ddl_oracle_sql_proxy_
;
if
(
OB_FAIL
(
single_conn_proxy
.
connect
(
tenant_id
,
0
/*group_id*/
,
&
oracle_sql_proxy
)))
{
LOG_WARN
(
"failed to get mysql connect"
,
KR
(
ret
),
K
(
tenant_id
));
}
}
else
{
format_str
=
"SELECT /*+ %.*s */ 1 FROM `%.*s`.`%.*s` WHERE NOT 1 != 1 LIMIT 1"
;
sql_proxy
=
GCTX
.
ddl_sql_proxy_
;
if
(
OB_FAIL
(
single_conn_proxy
.
connect
(
tenant_id
,
0
/*group_id*/
,
GCTX
.
sql_proxy_
)))
{
LOG_WARN
(
"failed to get mysql connect"
,
KR
(
ret
),
K
(
tenant_id
));
}
}
SMART_VAR
(
ObMySQLProxy
::
MySQLResult
,
res
)
{
common
::
sqlclient
::
ObMySQLResult
*
result
=
nullptr
;
ObSqlString
ddl_schema_hint_str
;
ObArenaAllocator
allocator
(
"ObDDLTmp"
);
ObString
new_table_name
;
ObString
new_database_name
;
if
(
OB_FAIL
(
sql
::
ObSQLUtils
::
generate_new_name_with_escape_character
(
if
(
OB_FAIL
(
ret
))
{
}
else
if
(
OB_FAIL
(
sys_var_schema
.
get_sysvar_schema
(
SYS_VAR_LOWER_CASE_TABLE_NAMES
,
var_schema
)))
{
LOG_WARN
(
"failed to get lower_case_table_names"
,
KR
(
ret
));
}
else
if
(
OB_ISNULL
(
var_schema
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"var_schema is null"
,
KR
(
ret
));
}
else
if
(
OB_ISNULL
(
connection
=
single_conn_proxy
.
get_connection
()))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"unexpected null conn"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
connection
->
set_session_variable
(
share
::
OB_SV_LOWER_CASE_TABLE_NAMES
,
var_schema
->
get_value
())))
{
LOG_WARN
(
"update lower_case_table_names for ddl inner sql failed"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
sql
::
ObSQLUtils
::
generate_new_name_with_escape_character
(
allocator
,
database_name
,
new_database_name
,
...
...
@@ -5083,16 +5097,11 @@ int ObDDLUtil::check_table_empty(
static_cast
<
int
>
(
new_database_name
.
length
()),
new_database_name
.
ptr
(),
static_cast
<
int
>
(
new_table_name
.
length
()),
new_table_name
.
ptr
())))
{
LOG_WARN
(
"fail to assign format"
,
K
(
ret
));
}
if
(
OB_FAIL
(
ret
))
{
}
else
if
(
OB_ISNULL
(
sql_proxy
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"sql proxy is null"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
sql_proxy
->
read
(
res
,
table_schema
.
get_tenant_id
(),
sql_string
.
ptr
(),
&
session_param
)))
{
}
else
if
(
OB_FAIL
(
single_conn_proxy
.
read
(
res
,
tenant_id
,
sql_string
.
ptr
())))
{
LOG_WARN
(
"execute sql failed"
,
K
(
ret
),
K
(
sql_string
.
ptr
()));
}
else
if
(
OB_ISNULL
(
result
=
res
.
get_result
()))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"execute sql failed"
,
K
(
ret
),
K
(
t
able_schema
.
get_tenant_id
()
),
K
(
sql_string
));
LOG_WARN
(
"execute sql failed"
,
K
(
ret
),
K
(
t
enant_id
),
K
(
sql_string
));
}
else
if
(
OB_FAIL
(
result
->
next
()))
{
if
(
OB_ITER_END
==
ret
)
{
ret
=
OB_SUCCESS
;
...
...
src/share/ob_ddl_common.h
浏览文件 @
04a4317f
...
...
@@ -1417,6 +1417,7 @@ public:
const
bool
calc_memtable
,
int64_t
&
physical_row_count
/*OUT*/
);
static
int
check_table_empty
(
const
share
::
schema
::
ObSysVariableSchema
&
sys_var_schema
,
const
ObString
&
database_name
,
const
share
::
schema
::
ObTableSchema
&
table_schema
,
const
ObSQLMode
sql_mode
,
...
...
src/share/schema/ob_latest_schema_guard.cpp
浏览文件 @
04a4317f
...
...
@@ -1074,3 +1074,17 @@ int ObLatestSchemaGuard::get_table_id_and_table_name_in_tablegroup(
}
return
ret
;
}
int
ObLatestSchemaGuard
::
get_sys_variable_schema
(
const
ObSysVariableSchema
*&
sys_variable_schema
)
{
int
ret
=
OB_SUCCESS
;
sys_variable_schema
=
NULL
;
if
(
OB_FAIL
(
check_inner_stat_
()))
{
LOG_WARN
(
"fail to check inner stat"
,
KR
(
ret
));
}
else
if
(
OB_FAIL
(
get_schema_
(
SYS_VARIABLE_SCHEMA
,
tenant_id_
,
tenant_id_
/*schema_id*/
,
sys_variable_schema
)))
{
LOG_WARN
(
"fail to get tenant system variable"
,
KR
(
ret
),
K_
(
tenant_id
),
KPC
(
sys_variable_schema
));
}
else
if
(
OB_ISNULL
(
sys_variable_schema
))
{
LOG_INFO
(
"sys_variable_schema is null"
,
KR
(
ret
),
K_
(
tenant_id
));
}
return
ret
;
}
src/share/schema/ob_latest_schema_guard.h
浏览文件 @
04a4317f
...
...
@@ -438,6 +438,8 @@ int get_table_id_and_table_name_in_tablegroup(
int
get_sequence_schema
(
const
uint64_t
sequence_id
,
const
ObSequenceSchema
*&
sequence_schema
);
int
get_sys_variable_schema
(
const
ObSysVariableSchema
*&
sys_variable_schema
);
/* -------------- interfaces with cache end ---------------*/
private:
int
check_inner_stat_
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录