database - Reserve sequence range in DB2 -
we moving application oracle db2. batch job. there sequencing logic assigns ids entries before processing:
reserve range of sequences
select my_sequence.nextval; // range_start;
alter sequence my_sequence increment range_size;
select my_sequence.nextval;
alter sequence my_sequence increment 1;
select my_sequence.nextval; // range_end;
assign ids within range via in-memory incremented value:
for id = range_start:range_end do
this worked fine in oracle, gave unexpected results in db2.
in oracle:
drop sequence my_sequence; create sequence my_sequence minvalue 1 maxvalue 999999999999999999999999999 increment 1 start 1 cache 50000 noorder nocycle ; select my_sequence.nextval dual; // 1; select my_sequence.nextval dual; // 2; alter sequence my_sequence increment 100000; select my_sequence.nextval dual; // 100002; alter sequence my_sequence increment 1; select my_sequence.nextval dual; // 100003;
in db2:
drop sequence my_sequence; create sequence my_sequence decimal(27 , 0) start 1 increment 1 minvalue 1 maxvalue 999999999999999999999999999 no cycle cache 50000 no order; select my_sequence.nextval dual; // 1; select my_sequence.nextval dual; // 2; alter sequence my_sequence increment 100000; select my_sequence.nextval dual; // 150000; alter sequence my_sequence increment 1; select my_sequence.nextval dual; // 5000050001;
i think 150000 may explained cache size. have no idea yet 5000050001 value. here highly appreciated.
notes:
- im aware of alter statements being non-transactional. process have exclusive access db time launched , runs non-distributed , single-threaded.
- db2 runs in ora compatibility mode
- the same issue in db2 appears if db2 sequence next val used: values next value my_sequence;
- same issue ordered sequences
altering sequence no cache fixed issue.
Comments
Post a Comment