ORM or something to handle SQL tables with an order column efficiently

后端 未结 2 1276
被撕碎了的回忆
被撕碎了的回忆 2021-01-03 00:29

I got an Java application using SQL tables that contains an ordered list of entities, ordered by an order column. I would like to add/remove things in/from the middle of the

2条回答
  •  生来不讨喜
    2021-01-03 01:24

    My advice is to do two things:

    1. Choose very large increments between your items, say one million. This way you can move an item at 8,000,000 to before 7,000,000 by changing just it to 6,500,000; and
    2. Every now and again reorder the items as a batch job.

    The large increments don't eliminate the problem of doing a large reorder but the need to do a big reorder highly unlikely and the batch job is there to reorder them say once every day/week/month as required.

    Changing a whole bunch of items at once is just messy and asking for trouble.

提交回复
热议问题