oracle创建主键开并行,对Oracle 并行的误解3--其实建主键没有用到并行

如果为亿级别的表建主键会非常慢,原因是用建主键的语句是不能用到并行的,需要索引和约束分开建才能快。做一个实验:

drop table test purge;

create table test as select * from dba_objects where object_id is not null;

--按普通的方式建索引,可以看到并行度为1

alter table test add constraint pk_t_object_id primary key (object_id) Nologging parallel 16;

select degree from user_indexes s where s.index_name=upper('pk_t_object_id');

1

--按下列的方式两步走,先建唯一性索引,然后加约束

alter table TEST drop constraint PK_T_OBJECT_ID cascade;

create unique index ind_t_object_id on test(object_id) Nologging parallel 16;

alter table test add constraint pk_t_object_id primary key (object_id);

select degree from user_indexes s where s.index_name=upper('ind_t_object_id');

16

--最后一定要记住,把索引并行度打回来,不然后果很严重

alter index ind_t_object_id noparallel;

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值