About me:Oracle ACE pro,optimistic,passionate and harmonious. Focus on ORACLE,MySQL and other database programming,peformance tuning,db design, j2ee,Linux/AIX,Architecture tech,etc
全部博文(169)
分类: Oracle
2023-05-06 14:23:43
从Oracle 18.1数据库开始,自适应序列 (Scalable Sequences) 被引入。
为了改善以序列值作为键值的表的数据加载性能,自适应序列的特性被加入。这个特性为序列提供了添加 instance 和 session 偏移量的选项,当跨 RAC节 点加载数据或者单实例多个进程并发加载数据时,可以显著减少序列争用和索引块争用的可能性,以前可以应用自定义主键为类似scalable sequences来解决,经常用hash partition index解决,但是只能等值查询,也不能从根本上解决。
这个新特性的好处是,在以序列作为键值的表的数据加载时,它通过减少争用来进一步提升Oracle数据库加载数据的能力。在创建序列的时候,将 instance 和 session 的 id 添加到序列的值中,这样在生成序列值时产生的争用和 insert 键值时产生的索引块争用可以显著的减少。这表明Oracle数据库数据的数据加载能力可以进一步扩展,并且可以支撑更高速率的数据加载。
Scalable Sequences:
CREATE | ALTER SEQUENCE [ schema. ]sequence
[ { INCREMENT BY | START WITH } integer
| { MAXVALUE integer | NOMAXVALUE }
| { MINVALUE integer | NOMINVALUE }
| { CYCLE | NOCYCLE }
| { CACHE integer | NOCACHE }
| { ORDER | NOORDER }
| { SCALE {EXTEND | NOEXTEND} | NOSCALE}
]
SCALE/NOSCALE
When SCALE is specified, a numeric offset is affixed to the beginning of the sequence. This offset if of the form iii||sss||, where,
iii denotes a three digit instance offset given by (instance_id % 100) + 100,
sss denotes a three digits session offset given by (session_id % 1000), and
|| is the concatenation operator
EXTEND/NOEXTEND
为SCALE子句指定EXTEND选项时,SCALE序列值的长度为[X位+Y位],其中X是可缩放序列偏移量中的位数(默认为6位),Y是MAXVALUE子句中指定的位数。
例如,对于指定了MINVALUE为1、MAXVALUE为100(3位)和EXTEND选项的升序可扩展序列,可扩展序列值将为9位(6位可扩展序列偏移号+3位MAXVALUE),并且将采用以下形式:
iii||sss||001, iii||sss||002, …,iii||sss||100
6 digit scalable sequence offset number || 001 6 digit scalable sequence offset number || 002 6 digit scalable sequence offset number || 003 ... 6 digit scalable sequence offset number || 100
6 digit scalable sequence offset number || 1 6 digit scalable sequence offset number || 2 6 digit scalable sequence offset number || 3 ... 6 digit scalable sequence offset number || 9Note that the NEXTVAL operation on this scalable sequence after the sequence value of [6 digit scalable sequence offset number || 9] will report the following error message, because the next scalable sequence value is [6 digit scalable sequence offset number || 10], which contains 8 digits and is greater than MAXVALUE of 1000000 that contains 7 digits:
ORA-64603: NEXTVAL cannot be instantiated for SQ. Widen the sequence by 1 digits or alter sequence with SCALE EXTEND.