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

前端 未结 4 533
一整个雨季
一整个雨季 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 03:58

    As you have already seemed to conclude, gapless sequences simply do not scale. Either you run the risk of dropping values when a rollback occurs, or you have a serialization point that will prevent a multi-user, concurrent transaction system from scaling. You cannot have both.

    My thought would be, what about a post processing action, where every day, you have a process that runs at close of business, checks for gaps, and renumbers anything that needs to be renumbered?

    One final thought: I don't know your requirement, but, I know you said this is "required by law". Well, ask yourself, what did people do before there were computers? How would this "requirement" be met? Assuming you have a stack of blank forms that come preprinted with a "sequence" number in the upper right corner? And what happens if someone spilled coffee on that form? How was that handled? It seems you need a similar method to handle that in your system.

    Hope that helps.

提交回复
热议问题