加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-12 15:53:45 所属栏目:百科 来源:网络整理
导读:如果为亿级别的表建主键会非常慢,原因是用建主键的语句是不能用到并行的,需要索引和约束分开建才能快。做一个实验: drop table test purge; create table test as select * from dba_objects where object_id is not null; -- 按普通的方式建索引,可以看

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

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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读