Gap-less sequence where multiple transactions with multiple tables are involved

前端 未结 4 550
一整个雨季
一整个雨季 2020-12-22 03:54

I have a requirement (by law) for a gap-less numbers on different tables. The IDs can have holes in them but not the sequences.

This is something I have to either so

4条回答
  •  北海茫月
    2020-12-22 04:01

    Here is an idea that should support both high performance and high concurrency:

    1. Use a highly concurrent, cached Oracle sequence to generate a dumb unique identifier for the gap-less table row. Call this entity MASTER_TABLE

    2. Use the dumb unique identifier for all internal referential integrity from the MASTER_TABLE to other dependent detail tables.

    3. Now your gap-less MASTER_TABLE sequence number can be implemented as an additional attribute on the MASTER_TABLE, and will be populated by a process that is separate from the MASTER_TABLE row creation. In fact, the gap-less additional attribute should be maintained in a 4th normal form attribute table of the MASTER_TABLE, and hence then a single background thread can then populate it at leisure, without concern for any row-locks on the MASTER_TABLE.

    4. All queries that need to display the gap-less sequence number on a screen or report or whatever, would join the MASTER_TABLE with the gap-less additional attribute 4th normal form table. Note, these joins will be satisfied only after the background thread had populated the gap-less additional attribute 4th normal form table.

提交回复
热议问题