序列如何在oracle中保持并发 [英] how sequence maintain concurrency in oracle

查看:714
本文介绍了序列如何在oracle中保持并发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果多个用户同时访问了序列(甚至是毫秒),会发生什么情况.无论是死锁还是Oracle都有某种机制?

what happened, if sequence has been access at the same time (even in milliseconds) by multiple users. Whether it will be dead lock or Oracle have some mechanism ?

我的意思是,如果A和B用户同时从squence1请求nextval,那么他们将获得相同的价值,或者将被吊死.

I mean, If A and B users has requested for nextval from squence1 at same time, then they will get same value or they will hanged.

根据此博客,它说

对序列的NextVal的并发访问将始终返回单独 值给每个调用者. (除非已将序列设置为循环 值-在这种情况下,可能会有重复的值.

Concurrent access of NextVal on a sequence will always return separate values to each caller. (Unless the sequence has been setup to cycle values - in which case duplicate values are possible).

推荐答案

乔纳森·刘易斯(Jonathan Lewis)在他的《 Oracle核心》(第222-225页)一书中对此进行了介绍.我不会重述所有内容,您应该购买该书(在此处查找).重要的是,他不仅解释了会发生什么,而且还向我们展示了如何(通过使用SQL跟踪)看到正在发生的事情.

Jonathan Lewis covers this in his book Oracle Core (pp.222-225). I'm not going to recapitulate everything, you should buy the book (find it here). The important thing is that he not only explains what happens, he shows us how we can see what's happening (by using SQL trace).

基本上,每个序列只是核心表seq$中的一行.第一次调用nextval会发布该序列条目的更新.这会将序列的高水位线增加到起始值+缓存值.数据库跟踪SGA中的当前值(起始值+呼叫nextval的次数).当该数字达到最高水位标记时,数据库将再次更新seq$.

Basically, each sequence is just a row in the core table seq$. The first call to nextval issues an update to that sequence's entry. This increments the sequence's highwater mark to starting value + cache value. The database tracks the current value (starting value + number of calls to nextval) in the SGA; when that number reaches highwater mark the database updates seq$ again.

要注意的重要一点是,所有这些都在SGA中管理,而不是在单个会话中管理.单个会话跟踪的唯一内容是最近一次调用nextval的结果,因此它可以满足后续对currval的调用.

The important thing to note is that all this managed in the SGA and not the individual session. The only thing the individual session tracks is the result of the most recent call to nextval so it can satisfy subsequent calls to currval.

这篇关于序列如何在oracle中保持并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆