issue in Number generation in Sequence using Cache

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 06:21:25

问题


I have a sequence created with nocycle, noorder, cache 100 and increment by 1. I am using the below SQL to generate sequence:

select myseq.nextVal from dual;

With this sequence I got values between 206764957 and 206765478 on one day. After few days when I used this process again it gave me values between 206765361 and 206793474.

So in my first run the highest number was 206765478 and in my second run the lowest number was 206765361. I was expecting all of the numbers to in the second run to be higher than ll of the numbers from the first run, not to have them overlapping.

Could you please help in finding the issue with this sequence?


回答1:


From the documentation:

ORDER
Specify ORDER to guarantee that sequence numbers are generated in order of request. This clause is useful if you are using the sequence numbers as timestamps. Guaranteeing order is usually not important for sequences used to generate primary keys.

ORDER is necessary only to guarantee ordered generation if you are using Oracle Real Application Clusters. If you are using exclusive mode, then sequence numbers are always generated in order.

NOORDER
Specify NOORDER if you do not want to guarantee sequence numbers are generated in order of request. This is the default.

You have specified noorder so sequences numbers are not guaranteed to be generated in the order of the request. From the behaviour you are seeing, and assuming your assertion that the sequence hasn't been modified is true, you seem to be using RAC and are seeing the effect of the way caching is implemented across RAC nodes.

And from the Real Application Clusters Administration and Deployment Guide:

If you use sequence numbers, then always use CACHE with the NOORDER option for optimal performance in sequence number generation. With the CACHE option, however, you may have gaps in the sequence numbers. If your environment cannot tolerate sequence number gaps, then use the NOCACHE option or consider pre-generating the sequence numbers. If your application requires sequence number ordering but can tolerate gaps, then use CACHE and ORDER to cache and order sequence numbers in Oracle RAC. If your application requires ordered sequence numbers without gaps, then use NOCACHE and ORDER. The NOCACHE and ORDER combination has the most negative effect on performance compared to other caching and ordering combinations.

If you are trying to use the sequence to show the order that rows were created then you could use order but that will slow things down. It might be more reliable to use a timestamp column, though that is limited by the precision supported by your operating system, and might not be unique.



来源:https://stackoverflow.com/questions/39832607/issue-in-number-generation-in-sequence-using-cache

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!