概念描述
在 Oceanbase 上,truncate/drop partition 会导致全局索引失效,即使分区是空分区,全局索引也会失效,在 Oracle 数据库上执行相同的测试,truncate/drop partition 空分区,全局索引不会失效。
测试验证
1. truncate partition 空分区,全局索引会失效
-- 创建测试表
drop table dbmt.tablea;
create table dbmt.tablea(id number,c varchar2(100)) partition by range(id) (partition p1 values less than(100), partition p2 values less than(200));
-- 创建全局索引
create index dbmt.idx_tablea on dbmt.tablea(id);
-- 执行 truncate partition
alter table dbmt.tablea truncate partition p1;
-- 查看全局索引状态
obclient [SYS]> select owner, table_name, index_name, status from dba_indexes where index_name = 'IDX_TABLEA';
+-------+------------+------------+----------+
| OWNER | TABLE_NAME | INDEX_NAME | STATUS |
+-------+------------+------------+----------+
| DBMT | TABLEA | IDX_TABLEA | UNUSABLE |
+-------+------------+------------+----------+
1 row in set (0.003 sec)
复制
2. drop partition 空分区,全局索引会失效
-- 创建测试表
drop table dbmt.tablea;
create table dbmt.tablea(id number,c varchar2(100)) partition by range(id) (partition p1 values less than(100), partition p2 values less than(200));
-- 创建全局索引
create index dbmt.idx_tablea on dbmt.tablea(id);
-- 执行 truncate partition
alter table dbmt.tablea drop partition p1;
-- 查看全局索引状态
obclient [SYS]> select owner, table_name, index_name, status from dba_indexes where index_name = 'IDX_TABLEA';
+-------+------------+------------+----------+
| OWNER | TABLE_NAME | INDEX_NAME | STATUS |
+-------+------------+------------+----------+
| DBMT | TABLEA | IDX_TABLEA | UNUSABLE |
+-------+------------+------------+----------+
1 row in set (0.003 sec)
复制
处理失效的全局索引
- Oceanbase 不支持 rebuild index,出现索引失效,只能删除重建
obclient [SYS]> alter index DBMT.IDX_TABLEA rebuild;
ORA-00900: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'rebuild' at line 1
obclient [SYS]> drop index DBMT.IDX_TABLEA;
Query OK, 0 rows affected (0.065 sec)
obclient [SYS]> create index dbmt.idx_tablea on dbmt.tablea(id);
Query OK, 0 rows affected (0.964 sec)
obclient [SYS]> select owner, table_name, index_name, status from dba_indexes where index_name = 'IDX_TABLEA';
Empty set (0.001 sec)
复制
- truncate/drop partition 加上 update global indexes 使其自动维护全局索引
alter table dbmt.tablea truncate partition p1 update global indexes;
alter table dbmt.tablea drop partition p1 update global indexes;
复制
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
文章被以下合辑收录
评论
相关阅读
2025年4月中国数据库流行度排行榜:OB高分复登顶,崖山稳驭撼十强
墨天轮编辑部
2053次阅读
2025-04-09 15:33:27
2025年3月国产数据库大事记
墨天轮编辑部
913次阅读
2025-04-03 15:21:16
AI关键场景得到全面支持!OceanBase入选Forrester报告三大领域代表厂商
OceanBase数据库
247次阅读
2025-04-19 22:27:54
数据库管理-第313期 分布式挑战单机,OceanBase单机版试玩(20250411)
胖头鱼的鱼缸
221次阅读
2025-04-10 22:41:56
OceanBase CEO杨冰:2025年分布式数据库将迎来本地部署和国产升级的全面爆发
通讯员
203次阅读
2025-04-03 09:35:26
OceanBase单机版产品解读
多明戈教你玩狼人杀
184次阅读
2025-04-11 15:28:33
2024年中国联通软研院OceanBase扩容单一来源采购公示
通讯员
162次阅读
2025-04-21 15:55:59
OceanBase单机版保姆级安装
薛晓刚
144次阅读
2025-04-10 17:30:42
定档!2025 OceanBase开发者大会,5月17日广州见!
OceanBase数据库
134次阅读
2025-04-09 16:48:47
Oceanbase单机版上手示例
潇湘秦
128次阅读
2025-04-18 13:40:24
TA的专栏
目录