适用版本
OceanBase 数据库 V4.0 ~ V4.2.1 版本。
问题现象
对一个包含 300+ 分区的表执行 Truncate Table 操作耗时 3.2s。
问题原因
3.2s 的耗时组成:
- 增删 300+ tablet:1s
- schema 刷新:0.8s
- schema 刷新需要读取
__all_table_history/__all_part_history/__all_sub_part_history,刷新时间与历史表中的记录数正相关。
- schema 刷新需要读取
- 加表锁:0.2s
- 等 DDL 锁差:0.2s
- RPC 通知其他 Server 执行 schema 更新:1s
- V4.2 版本不支持 schema 异步刷新通知,需要同步等待。
解决方法
在以上耗时组成中,可以干预的是 schema 刷新中读取 shema 历史表的时间。通过调小以下参数来控制 schema 历史信息的回收。
- schema_history_expire_time
- schema_history_recycle_interval