How to store ordered items which often change position in DB

前端 未结 4 1561
别跟我提以往
别跟我提以往 2020-12-23 11:58

I need to be able to store a large list of ordered items in the DB. So far that\'s straight-forward:

ID Position OtherFields
 1     45      ...
 2   4736             


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-23 12:34

    Another solution would be to use lexical ranking. Whenever there is no value between two strings, one would simply add a new character. The only disadvantage is, that it consumes more memory compared to a numerical solution, which are named in other answers.

    A normalization isn't necessary for an error free database, but can be optionally done to reduce the string lenght.

    Here is an interesting video, which explains it in detail: https://www.youtube.com/watch?v=OjQv9xMoFbg&feature=youtu.be

提交回复
热议问题