Oracle sequence caching

前端 未结 3 827
心在旅途
心在旅途 2021-02-15 18:22

I am trying to implement a sequence in an Oracle database to act as a surrogate key creator for a table. For performance reasons, I want this sequence to be cached. I have rea

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-15 18:47

    Turns out that this is not (or no longer true). Shut down and restart of instance does not lose cached values. Simple test with cache = 1000.

    SQL> select ordered.currval from dual;

    CURRVAL

        22
    

    SQL> select unordered.currval from dual

    CURRVAL

        24
    

    SQL> SHUTDOWN IMMEDIATE SQL> STARTUP

    NEXTVAL

        23
    

    SQL> select unordered.nextval from dual;

    NEXTVAL

        25
    

    Also, ALL_SEQUENCES.LAST_NUMBER does not hold the last last number provided by the sequence except on startup and before first NEXTVAL. After first NEXTVAL, it holds last number served plus CACHE_SIZE. This does not change until new cache is generated. However, on shutdown, it apparently gets reset to just the last number served.

提交回复
热议问题