OceanBase系列---【如何把一个表改造成分区表?】

1.先备份原表数据(为了不影响原表使用,如果暂时没人用,可以省略此步骤)

create table source_tmp as select * from source;

2.改造原表ddl,创建分区表source_partition

具体参考:https://www.cnblogs.com/hujunwei/p/19178124

3.把备份表的数据导入到新建的分区表

-- 数据量小的话可以直接insert into select,大的话可以加日期范围筛选,这里实测:同步100多万数据需要20s左右。
insert into source_partition select * from source_tmp where ...;

4.数据完整性校验

select count(1) from source;
select count(1) from source_partition;

5.修改表名

RENAME source TO source_back;
RENAME source_partition TO source;

posted on 2025-10-30 21:33  少年攻城狮  阅读(2)  评论(0)    收藏  举报

导航