Skip to Main Content
  • Questions
  • any performance hit using sequence with nocache in OLTP

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Baqir.

Asked: November 08, 2002 - 1:09 pm UTC

Last updated: June 29, 2012 - 9:53 am UTC

Version: 9.2.0.1

Viewed 10K+ times! This question is

You Asked

I would appreciate if you please let us know -- if there is any performace hit in OLTP using sequence with option "nocache"??
Thanks

and Tom said...

Huge -- yes. You will be doing a recursive SQL update to seq$ with every "nextval" call

Why anyone would ever go with nocache is totally beyond me. If you think it is giving you "gap free sequences" -- think again. The only thing is it doing is setting "slow=true".

A cache of hundreds or even thousands would be preferable and much more scalable.

Rating

  (21 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

sequences with nocache option

Baqir Hussain, November 08, 2002 - 6:00 pm UTC

Thanks for the prompt reply. We have over 300 sequences in our schema. We have created sequece with 500 cache size. These sequences will be used frequently and will be aged out of the library cache generating a gap about 420 to 450. Missing sequence is not a problem but with a gap of 400 or plus is not accepttable. How can we avoid this gap for these sequences?
Can we use dbms_shared_pool.keep to pin all sequences in the shared pool and HOW?
Is there any any performance hit putting these sequence in the shared_pool all together?
How can we keep these sequence in the shared_pool before and after the database shutdown?
Triggers can be used to accomplish this task. Please show me some examples of these triggers.
Thanks in advance

Tom Kyte
November 08, 2002 - 9:14 pm UTC

So?  Even if they are aged out (no likely if you a) size right b) use bind variables) so???

Why is a gap of 5 ok but 400 bad?  You do know that if you lost 400 a second -- it would take:

ops$tkyte@ORA920.US.ORACLE.COM> select (rpad('9',27,'9')/400) seconds,
  2         (rpad('9',27,'9')/400)/60 minutes,
  3         (rpad('9',27,'9')/400)/60/60 hours,
  4         (rpad('9',27,'9')/400)/60/60/24 days,
  5         (rpad('9',27,'9')/400)/60/60/24/365.25 years
  6    from dual;

   SECONDS    MINUTES      HOURS       DAYS      YEARS
---------- ---------- ---------- ---------- ----------
2.5000E+24 4.1667E+22 6.9444E+20 2.8935E+19 7.9220E+16

ops$tkyte@ORA920.US.ORACLE.COM>


7.9e16 YEARS to exhaust that sequence....

Yes you can ping

Yes that would most like be a waste of good code on a system that was sized and coded properly

Yes it would not matter in the long run.

search for

pinning sequence

on this site to see how to pin them and

connor "missing sequence number"

(and look for connor's comment in there) to see how to "unload" them.

But -- its a waste of really good coding time IMO
 

Could this be expanded a bit?

Bob Maggio, November 09, 2002 - 8:18 am UTC

So, if I have a system with many sequences, all created with nocahce, would recreating the sequences with cache=1000 possibly improve performance? It seems to say so but we haven't really noticed any issues on this system. But there are 100s of sequences that are this way. Any other negative implications of setting the sequence cache high?

Tom Kyte
November 09, 2002 - 11:00 am UTC

Tell you what -- I'll present the numbers and you can make the choice, refer to 
http://asktom.oracle.com/~tkyte/runstats.html
for details on this test harness I'm using:

ops$tkyte@ORA920.US.ORACLE.COM> create sequence cached cache 1000;
Sequence created.

ops$tkyte@ORA920.US.ORACLE.COM> create sequence not_cached nocache;
Sequence created.

ops$tkyte@ORA920.US.ORACLE.COM> declare
  2      l_start number;
  3      l_run1  number;
  4      l_run2  number;
  5
  6      l_num   number;
  7  begin
  8      insert into run_stats select 'before', stats.* from stats;
  9
 10      l_start := dbms_utility.get_time;
 11      for i in 1 .. 100000
 12      loop
 13          select cached.nextval into l_num from dual;
 14      end loop;
 15      l_run1 := (dbms_utility.get_time-l_start);
 16      dbms_output.put_line( l_run1 || ' hsecs' );
 17
 18      insert into run_stats select 'after 1', stats.* from stats;
 19      l_start := dbms_utility.get_time;
 20      for i in 1 .. 100000
 21      loop
 22          select NOT_cached.nextval into l_num from dual;
 23      end loop;
 24      l_run2 := (dbms_utility.get_time-l_start);
 25      dbms_output.put_line( l_run2 || ' hsecs' );
 26      dbms_output.put_line
 27      ( 'run 1 ran in ' || round(l_run1/l_run2*100,2) || '% of the time' );
 28
 29      insert into run_stats select 'after 2', stats.* from stats;
 30  end;
 31  /
2497 hsecs
14753 hsecs
run 1 ran in 16.93% of the time

PL/SQL procedure successfully completed.

<b>Hmm, elapsed time is quite HUGELY different.... the cached sequence is obviously "wall clock faster" but even more importantly:</b>



ops$tkyte@ORA920.US.ORACLE.COM> select a.name, b.value-a.value run1, c.value-b.value run2,
  2         ( (c.value-b.value)-(b.value-a.value)) diff
  3    from run_stats a, run_stats b, run_stats c
  4   where a.name = b.name
  5     and b.name = c.name
  6     and a.runid = 'before'
  7     and b.runid = 'after 1'
  8     and c.runid = 'after 2'
  9     and (c.value-a.value) > 0
 10     and (c.value-b.value) <> (b.value-a.value)
 11   order by abs( (c.value-b.value)-(b.value-a.value))
 12  /

NAME                                 RUN1       RUN2       DIFF
------------------------------ ---------- ---------- ----------
...
STAT...consistent gets - exami        174     100005      99831
nation

STAT...consistent gets             300268     400125      99857
STAT...index fetch by key             129     100001      99872
STAT...commit cleanouts               100     100001      99901
STAT...commit cleanouts succes        100     100001      99901
sfully completed

STAT...calls to kcmgas                100     100009      99909
STAT...execute count               100120     200032      99912
STAT...parse count (total)            119     100033      99914
STAT...opened cursors cumulati        113     100033      99920
ve

STAT...deferred (CURRENT) bloc         99     100024      99925
k cleanout applications

LATCH.sequence cache               300200     200000    -100200
STAT...enqueue requests               303     200079     199776
STAT...enqueue releases               302     200079     199777
STAT...redo entries                   221     200113     199892
LATCH.row cache enqueue latch         312     200600     200288
LATCH.dml lock allocation             391     200956     200565
LATCH.redo allocation                 362     201615     201253
STAT...calls to get snapshot s     300329     600089     299760
cn: kcmgss

LATCH.undo global data                483     301121     300638
STAT...db block gets                  348     303296     302948
STAT...db block changes               429     400152     399723
LATCH.library cache pin alloca        703     401043     400340
tion

LATCH.enqueue hash chains             912     401842     400930
STAT...session logical reads       300616     703421     402805
LATCH.shared pool                  201067     701434     500367
LATCH.row cache objects               716     600609     599893
LATCH.library cache pin            401212    1201376     800164
LATCH.library cache                501960    1602596    1100636
LATCH.cache buffers chains         603008    1920502    1317494
STAT...recursive calls             101649    1500253    1398604
STAT...redo size                    99800   72413704   72313904

99 rows selected.

ops$tkyte@ORA920.US.ORACLE.COM>


<b>Remember -- LATCHES are locks, locks imply serialization, serialization implies less scalable -- longer waits.

Also -- look at the STATS as well -- only 72m more redo for "nocache"


Nocache looks like a lose lose proposition to me, how about you?</b>
 

NOCACHE

Oleksandr Alesinslyy, November 09, 2002 - 12:22 pm UTC

>Why anyone would ever go with nocache is totally beyond me.

NOCACHE may be useful if somebody need to know exact order of events (e.g. inserts into table). Any time-based solution may be inadequete of the finite resolution of any timer. Exect ordering may be achieved only by means of serialization and NOCACHE provide just it. Definitely, your payment is performance and scalability, but in some cirqumtints it may be acceptable.

Yours sincerely,
Oleksandr

Tom Kyte
November 09, 2002 - 3:00 pm UTC

And just exactly how would nocache help you achieve:

"...if somebody need to know exact order of events (e.g.
inserts into table..."

any better (or worse) the CACHE 1000??

The results would be EXACTLY the same, 100% exactly the same. The values returned to nextval just come back SLOWER with nocache -- but the values are the same (slower -- same results -- bummer)

Now what?

NOCACHE and event orders

Oleksandr Alesinskyy, November 10, 2002 - 8:19 am UTC

Yes, you are righ, ss test result show. I have erroneously assumed that values are cached at session level, but it seems that in reality they are cached system-wide.

BTW,just for curiosity, wss it this waz from the moment of sequences introduction. I have some vague recollection that long ago I have tested this on Oracle 7.0.16 and test have shown session-level cache (i.e. when I have tried to access cached sequence from one session and receive "i", then range of values from "i" till "i+cache-1" was reserved for this session and next access from another session had returned "i+cache"). But it is possible that these recollection are wrong.



Tom Kyte
November 10, 2002 - 4:33 pm UTC

I do not believe that was ever the behavior - the sequences are cached in the shared pool.

Maybe -- in version 6, before the shared pool .... but i cannot remember back that far anymore ;)

Can the sequences be altered in real time without consequence?

Bob Maggio, November 12, 2002 - 9:55 am UTC

Tom,
can I simply

alter sequence sequence_name cache 500;

to the sequences I want to change without issue? How about on live systems? Any chance of creating a duplicate sequence or something like that?

Tom Kyte
November 12, 2002 - 10:33 am UTC

no chance of creating duplicates, no.

On a live system, you would (as with all DDL) want to do this in a controlled fashion, during time of minimal user activity to avoid locking and contention issues.

sequences

Baqir Hussain, November 15, 2002 - 11:35 am UTC

Tom,
Happy OracleWorld
You suggested to read Conner remarks
"When you need to shut the database, on a shutdown trigger, make the sequence nocache then back to cache."

1. Please let us know what is hapenneing?
2. Could you please write a trigger on a shutdown on database to do nocache then cache. Thanks in advance

Tom Kyte
November 15, 2002 - 8:14 pm UTC

1) when you do the ddl on the sequence, it puts the value (current value) out to seq$. so the next time, the sequence starts with that value -- not some higher number.

It is a vain attempt to have gap free sequences which is of course not possible.

2) its pretty easy -- I'll let you read about it:

</code> http://docs.oracle.com/docs/cd/A87860_01/doc/appdev.817/a76939/adg14evt.htm#998000 <code>

I'm totally against wasting your time on this futile effort though, it is just such a waste of time, energy and resources.


Sequence cache in RAC

Sam, June 30, 2003 - 3:39 pm UTC

Tom,

In a RAC environment, for a particular sequence, does each node have its own sequence cache or is there one global sequence cache? We are trying to see if we use a sequence as a key, whether we can assume a row with a smaller key is always created before a row with a bigger key.



Tom Kyte
June 30, 2003 - 4:15 pm UTC

you could never assume that in single instance oracle really.


OPTIMALLY each instance has its own very big cache. and 101 might be hours newer than 55

sequence from dual

Ganesh, January 11, 2005 - 5:25 am UTC

Tom,

I have few questions regarding the usage of the below codes in a procedure with respect to performace.
1. Is it better to use
select abc_sequence.nextval into n from dual;
OR
n := abc_sequence.nextval;

2. SELECT EXTRACT(YEAR FROM ln_req_frm_dt ) INTO ls_as_year FROM dual;
OR
ls_as_year := EXTRACT(YEAR FROM ln_req_frm_dt);

3. In an IF condition, if there are 3 AND conditions, will oracle execute all the 3 cases and the result is 0, then it goes to ELSE OR if the first AND fails, it goes to ELSE.

Thanks in Advance,
Ganesh



Tom Kyte
January 11, 2005 - 9:16 am UTC

1) only one of those two snippets of code actually work!  and the best way to do it is not shown :)


   do not:

   select s.nextval into l_n from dual;
   insert into t ( pk, .... ) values ( l_n, .... );


   DO

   insert into t ( pk, .... ) values ( s.nextval );

   OR, if you need the value:

   insert into t ( pk, ..... ) values ( s.nextval ) RETURNING pk into l_n;



but it is rare to need the value, for you have S.CURRVAL you can reference in subsequent DML


2) In this case, both work -- and the second option, if you need th year in a variable, is the only reasonable approach.

NEVER
   select <something> into VAR from dual;

WHEN
   VAR := <something>;

works.


3) In plsql, it'll short circut:

ops$tkyte@ORA9IR2> exec if ( 1=0 and 1/0 > 5 ) then null; end if;
 
PL/SQL procedure successfully completed.
 
ops$tkyte@ORA9IR2> exec if ( 1=0 or 1/0 > 5 ) then null; end if;
BEGIN if ( 1=0 or 1/0 > 5 ) then null; end if; END;
 
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at line 1


In SQL, you have zero control over the order of anything, so do not rely on a predicate getting evaluated in any order.


 

Great!

Ganesh, January 12, 2005 - 4:03 am UTC

Fantastic!

Memory used by cached sequence

A reader, January 13, 2005 - 11:06 am UTC

Is there a relationship between the number of sequence values cached and the memory used?

i.e. Does a sequence with 10000 cached values use more than a sequence with 10 cached values?

Tom Kyte
January 13, 2005 - 11:39 am UTC

A sequence is more or less

- a name
- last incremented value
- a current value
- an increment size (cache size)

when you say nextval, they just do the logical equivalent of:

  if current_value >= last_incremented_value + increment_size
  then
      update seq$ to get another increment_size reserved;
      commit;
      last_incremented_value = current_value
  end if;
  current_value = current_value + 1;
  return current_value;

so, they need about the same amount of memory, regardless of cache size (but a bigger cache size can massively impact your performance if you hit these sequences alot -- removing that update is great)

ops$tkyte@ORA9IR2> create sequence s1;
 
Sequence created.
 
ops$tkyte@ORA9IR2> create sequence s2 cache 10000000000000000000;
 
Sequence created.
 
ops$tkyte@ORA9IR2> select s1.nextval from dual;
 
   NEXTVAL
----------
         1
 
ops$tkyte@ORA9IR2> select s2.nextval from dual;
 
   NEXTVAL
----------
         1
 
ops$tkyte@ORA9IR2> @printtbl8 'select * from v$db_object_cache where owner = user';
OWNER                         : "OPS$TKYTE"
NAME                          : "S2"
DB_LINK                       : ""
NAMESPACE                     : "TABLE/PROCEDURE"
TYPE                          : "SEQUENCE"
SHARABLE_MEM                  : "868"
LOADS                         : "1"
EXECUTIONS                    : "0"
LOCKS                         : "1"
PINS                          : "0"
KEPT                          : "NO"
CHILD_LATCH                   : "1"
-----------------
OWNER                         : "OPS$TKYTE"
NAME                          : "S1"
DB_LINK                       : ""
NAMESPACE                     : "TABLE/PROCEDURE"
TYPE                          : "SEQUENCE"
SHARABLE_MEM                  : "868"
LOADS                         : "1"
EXECUTIONS                    : "0"
LOCKS                         : "1"
PINS                          : "0"
KEPT                          : "NO"
CHILD_LATCH                   : "1"
-----------------
 

Pl/SQL Documentation says otherwise on short-circuit evaluation

KP, January 15, 2005 - 7:05 am UTC

The PL/SQL User's Guide and reference Chapter 12 - Tuning PL/SQL Applications state that:

"
When evaluating a logical expression, PL/SQL uses short-circuit evaluation. That is, PL/SQL stops evaluating the expression as soon as the result can be determined. For example, in the following OR expression, when the value of sal is less than 1500, the left operand yields TRUE, so PL/SQL need not evaluate the right operand (because OR returns TRUE if either of its operands is true):

IF (sal < 1500) OR (comm IS NULL) THEN
...
END IF ;

Now, consider the following AND expression:

IF credit_ok(cust_id) AND (loan < 5000) THEN
...
END IF ;

The Boolean function credit_ok is always called. However, if you switch the operands of AND as follows:

IF (loan < 5000) AND credit_ok(cust_id) THEN
...
END IF ;

the function is called only when the expression loan < 5000 is true (because AND returns TRUE only if both its operands are true).
"

So, is this specific to functions or to your example where you said IF (1=0 OR 1/0 > 5) THEN ...

Tom Kyte
January 15, 2005 - 9:49 am UTC

this agrees 100% with what i said?

its stops when it can stop.


where do you see a conflict/difference in these statements?

KP, January 16, 2005 - 2:36 am UTC

Oh, because you said,

"In SQL, you have zero control over the order of anything, so do not rely on a predicate getting evaluated in any order."

The example in the documentation said if you put the function in the right side of the AND, then, it is called only if the left side is true. So, I was thinking it always does left to right evaluation.

Tom Kyte
January 16, 2005 - 11:27 am UTC

IN PLSQL

I said "in SQL". to point out the difference between PLSQL and SQL.

PLSQL -- procedural.

SQL -- non procedural, any order we feel like doing it that day.

A reader, March 02, 2005 - 7:15 am UTC


sequence in RAC environment

James Su, November 05, 2006 - 11:33 pm UTC

hi Tom,

When we fetch seq_mysequence.nextval in a RAC environment, it takes too long (3 seconds). The following (cached ones) are very fast. When the cache is used up, the very next one becomes slow again. Can you tell me what's wrong? What kind of parameter may help on this? Thank you.

Tom Kyte
November 06, 2006 - 9:43 am UTC

enable sql tracing with wait events.

trace it.

see what you are waiting on exactly.

Sequence cache

Kishore KVR, September 06, 2007 - 8:18 am UTC

Hi,

We have a proc where we are passing a table name and it gives next value of a sequence corresponding to the table name. We have 100 such tables.

previously, the sequences were used with NOCACHE
which impacted the perf obviously.

We have tested again with (50,000 rows load) with cache 50000 and cache 1000 anc cache 500

--The performance was decreased when set 50000
-- Got max perf when set to 1000
-- Again perf decread when set to 500

How to know what is the optimal cache value for a sequence.
Does it depends on data load? or any DB parameter? or cache size (if so, what is that)

Thanks,
Kishore
Tom Kyte
September 11, 2007 - 8:04 am UTC

define "decreased" and how you actually measured.

what's your opinion about pining the sequence

AMIR RIAZ, September 13, 2007 - 9:21 am UTC

hi tom

what's your opinion about pining the sequence in the cache and dont let them age out by using some script. The main idea is to create the sequences with cache clause and then pin the sequence in cache so the gap between the values in the sequence can be avoid. I used this method in oracle 8. But can i use it in oracle10g also. here is the script

declare
cursor cached_sequences is
select
sequence_owner,
sequence_name
from
dba_sequences
where
cache_size > 0;
sequence_owner varchar2(30);
sequence_name varchar2(30);
begin
open cached_sequences;
loop
fetch cached_sequences into sequence_owner, sequence_name;
exit when cached_sequences%notfound;
dbms_shared_pool.keep(sequence_owner || '.' || sequence_name, 'Q');
end loop;
end;
/

regards
Amir Riaz
Tom Kyte
September 15, 2007 - 7:30 pm UTC

sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.
sequences have gaps, all of them, every single one, without a doubt.

Then how *do* you determine commit order?

Dan, April 13, 2009 - 2:40 pm UTC

Tom, (in your example below), I can see how 101 might be hours newer than 55. The question is this...if sequences cannot be relied upon for determining the exact commit order, then how the heck *do* you determine it? We have the same issue in our RAC environment...our instances all have their own caches for the same sequence, and running a program across RAC nodes is throwing off our ordering logic.


Original thread:

Tom,

In a RAC environment, for a particular sequence, does each node have its own sequence cache or is
there one global sequence cache? We are trying to see if we use a sequence as a key, whether we
can assume a row with a smaller key is always created before a row with a bigger key.




Followup June 30, 2003 - 4pm US/Eastern:

you could never assume that in single instance oracle really.


OPTIMALLY each instance has its own very big cache. and 101 might be hours newer than 55
Tom Kyte
April 13, 2009 - 5:39 pm UTC

you tell me, in your application - what RULE tells you what came first?

unless you serialize, one at a time, it is rather arbitrary. You have to look to your logic, your application and answer yourself "what one 'comes first', what does it mean to 'come first'".


We (the database) have commit ordering down to a science, for us, it is the SCN (system change number, system commit number). We maintain that for ourselves, so we know the commit order - for replication, recovery, etc. We care when the transaction ends.

But that is us, what are your exact needs here - why do you need an ordering 'thing', what is the underlying logic that you are performing.

Then, once we understand that, we can discuss how best to implement that requirement (and it probably won't involve 'ordering' anything).

Selecting sequence for caching

Shiva Ellur, July 16, 2010 - 12:22 am UTC

Tom,

Currently we have a 200+ sequences in our OLTP system with nocache mode. After going throgh this blog thread,I thought of moving these into cache mode.However we have 11 transaction tables and rest of them are master/reference tables. The transaction tables are getting populated heavily daily approximately 600 MB - 900 MB and most of these tables are partitioned for performance reasons. Master tables are rarely updated or inserted. Given this scenario, i decided to create sequence with cache mode only for the transction tables and for rest of them i will keep it no cache mode. Please shed your light on this.

Thanks in advance.

Best Regards
Shiva Prasad Ellur
Tom Kyte
July 19, 2010 - 1:11 pm UTC

why are you using nocache? You like things to go slow???????

I would use cache <some big number> for all of them - period.

Sequence Cache

Shiva Ellur, August 10, 2010 - 8:23 am UTC

Tom,

Thanks very much for your valuable feedback.

We rarely update the master tables and hence thought of creating a cache on these sequences will gain a negigible change in the performance.

However with your advice, I will turn them all the sequences into a CACHE mode.

Thanks & Regards
Shiva Ellur

memory consumption

pranav, June 28, 2012 - 1:40 pm UTC

Hi Tom,

Since there will be many sequences(for ex.,100K) used in a database, and let's suppose cache is set to 10000 for each of the sequence what would be the consequences? I know they all perform better :-) But what about the memory consumption? Do we need to worry about it? Is there a way we can calculate the memory consumption?

Thanks for all your help.
Tom Kyte
June 29, 2012 - 9:53 am UTC

why or how could you have 100,000 sequences???? seriously? How could that happen? I cannot imagine.


In any case, it takes as much memory to store a cache 10 sequence as a cache 10000000 sequence.

We only need to cache the current sequence value and the end point value - for example, if you have a sequence that caches 1000, we would store in the SGA:

current      highest
1            1000


when someone requests one, we just increment current. And we keep incrementing current until it is equal to highest - when it is - we update sys.seq$ and update the memory contents of current and highest to

1001,2000

and keep on going.

Memory consumption

pranav, June 29, 2012 - 10:51 am UTC

Thanks a lot Tom. 100K sequences is an exaggeration :-) I wanted to know what if it's the case.