1

For example, when an issue tracker offers the functionality to users to keep a prioritized backlog of tasks and used a relational database for persisting this information, what are effective ways to encode this information?

Of course one could introduce an integral field priority (possibly unique) and sort entries according to that priority field, but this might not be a good solution when considering that the priorities might have to be reordered by the user. I wonder if there is a body of work on this or good practices.

wirrbel
  • 3,018
  • 2
  • 21
  • 33
  • Are you looking for a doubly linked list? First Stack Overflow search result: [loading a double linked list from a sql database](https://stackoverflow.com/q/732436) – fheub Jun 25 '18 at 09:55

1 Answers1

2

It depends on what your goal is. If you just want a simple ordering, then you can just an integer column for order, or priority, etc. But if you want columns for priority, like a kanban board, you might encode that differently by having for example an M to N mapping of issues and columns. In that case, you can also have an order or priority for your issue, so that in can be ordered correctly in the column.

Reordering by the user is a trivial problem. You would simply keep track of the original order of the issue (i.e. the integer value order); once you know the updated/new order, it’s some basic math to get all issues for that column and update their orders as well. For example, you have these 3 issues in the column named “TODO”:

  • “Fix database bug” - order = 1
  • “Fix UI bug” - order = 2
  • “Implement feature” - order = 3

you could move “Implement feature” to the top and adjust the order values for the other issues in that column to:

  • “Implement feature” - order = 1
  • “Fix database bug” - order = 2
  • “Fix UI bug” - order = 3

So, to answer the root question, it depends on your use case!

But all in all I think most people just use a simple integer column and some basic order-update logic when things get moved around. Note that this requires 1 database record update for every item that needs to have its order adjusted (in the above example, 3 records are updated). However, this shouldn’t be an issue for most relational databases as you could (and should) wrap those updates in a transaction.

Chris Cirefice
  • 2,984
  • 4
  • 17
  • 37
  • Agree that its normally just a numeric column - note that doesn't need to be exposed at the UI level. You can provide mechanisms that order (via drag and drop for example) and the UI code (or server code) can handle the renumbering. – Egret Jun 25 '18 at 19:20