Oracle Sequence Nocache

默认情况下,创建Sequence时,缓冲(cache)是20.意即:20次.nextval才会触发一次对sys.seq$的更新(update)操作。这样就能提高SQL执行性能。
当用户指定nocache时,如:
create sequence test_seq nocache;

每一次test_seq.nextval都会触发一次sys.seq$更新(update)。
我们可以比较下cache 20 和nocache的性能:
create sequence test_seq1 nocache;
create sequence test_seq2 cache 20;

create table tt1 (id number);
create table tt2 (id number);

declare
  v_start_time number :=dbms_utility.get_cpu_time;
  v_time1 number;
begin
  insert into tt1 select test_seq1.nextval from dual connect by level <= 100000;
  v_time1 := dbms_utility.get_cpu_time;
  dbms_output.put_line('Nocache sequence: ' || (v_time1 - v_start_time) / 100 || ' seconds');
  insert into tt2 select test_seq2.nextval from dual connect by level <= 100000;
  dbms_output.put_line('Caceh 20 sequence: ' || (dbms_utility.get_cpu_time - v_time1) / 100 || ' seconds');
end;

anonymous block completed
Nocache sequence: 28.37 seconds
Caceh 20 sequence: 1.83 seconds

性能差异还是相当明显的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值