您的位置:首页 > 产品设计 > UI/UE

Overview of the Sequence Generator【每日一译】--20121207

2012-12-11 14:50 453 查看
The sequence generator provides a sequential series of numbers. The sequence

generator is especially useful in multiuser environments for generating unique

sequential numbers without the overhead of disk I/O or transaction locking. For

example, assume two users are simultaneously inserting new employee rows into the

employees table. By using a sequence to generate unique employee numbers for the

employee_id column, neither user has to wait for the other to enter the next

available employee number. The sequence automatically generates the correct values

for each user.

序列创建器提供了一个按顺序的数字的串行。序列创建器特别有用的在多用户环境下创建

唯一顺序数字没有额外的磁盘IO消耗或者事务锁。比如假定两个用户同时插入新的员工行到

EMPLOYEES表。通过使用一个序列去创建唯一的员工编号对于EMPLOYEE_ID列,两用户

都不用去等待输入下一个可用的员工号码。序列自动为每个用户创建正确的值。

Therefore, the sequence generator reduces serialization where the statements of two

transactions must generate sequential numbers at the same time. By avoiding the

serialization that results when multiple users wait for each other to generate and use a

sequence number, the sequence generator improves transaction throughput, and a

user’s wait is considerably shorter.

所以,序列创建器减少了串行化,两个语句事务必须创建顺序数字在同一时间。为了避免

串行的结果当多个用户等待其它每个去创建并且使用序列的数字,序列的创建器提高了事务

的吞吐量,并且用户的等待是相当短暂的。

Sequence numbers are Oracle integers of up to 38 digits defined in the database. A

sequence definition indicates general information, such as the following:

■ The name of the sequence

■ Whether the sequence ascends or descends

■ The interval between numbers

■ Whether Oracle should cache sets of generated sequence numbers in memory

序列的数字是ORACLE整数最大到38位的定义在数据库中。一个序列定义包含一般信息,如下:

#序列的名字

#序列是升序还是降序

#数字间的周期大小差

#ORACLE是否缓存创建序列的数字集在内存中

Oracle stores the definitions of all sequences for a particular database as rows in a

single data dictionary table in the SYSTEM tablespace. Therefore, all sequence

definitions are always available, because the SYSTEM tablespace is always online.

Sequence numbers are used by SQL statements that reference the sequence. You can

issue a statement to generate a new sequence number or use the current sequence

number. After a statement in a user’s session generates a sequence number, the

particular sequence number is available only to that session. Each user that references

a sequence has access to the current sequence number.

ORACLE存储所有序列的定义对于一个特定的数据库里,像行一样在一个单独的数据字典,它

位于SYSTEM表空间。所以,所有的序列定义一直是可用的,因为SYSTEM表空间是一直在线的。

序列的数字用于与序列相关的SQL语句中。你可以输入一个语句去创建一个新的序列数字或者使用

当前的序列号。在一个用户会话中在一个语句后创建了一个序列号,那个特定的序列号仅对当前这个

用户可用。每个关于序列的用户拥有访问当前序列号的权限。

Sequence numbers are generated independently of tables. Therefore, the same

sequence generator can be used for more than one table. Sequence number generation

is useful to generate unique primary keys for your data automatically and to

coordinate keys across multiple rows or tables. Individual sequence numbers can be

skipped if they were generated and used in a transaction that was ultimately rolled

back. Applications can make provisions to catch and reuse these sequence numbers, if

desired.

序列号独立创建于表。所以,同一个序列创建器可以被用于多个表。序列号的创建是非常有用的

去自动创建唯一的主键并且在多个行或者多个表中协调主键。个别的序列号可以被跳过如果它们被

创建并且在事务中的使用最终回退。应用可以设定规定去获取并且重用这些序列号,如果期望。

Caution: If your application can never lose sequence numbers,

then you cannot use Oracle sequences, and you may choose to store

sequence numbers in database tables. Be careful when

implementing sequence generators using database tables. Even in a

single instance configuration, for a high rate of sequence values

generation, a performance overhead is associated with the cost of

locking the row that stores the sequence value.

警告:如果你的应用不能丢失序列号,那么你不能使用ORACLE序列,你可以选择去存储序列号在数据库

表中。当使用数据库表去实现序列的创建时要小心。甚至在单实例的配置中,对于一个序列值创建高频率情况

一个性能的消耗有关于存储序列值的行的锁的成本。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: