I have a table where the rows have a particular order. Users can insert new rows at any place in the ordering.
Our current strategy is:
- Use column called "order_index" with
Integer
type - Have rows with their "order_index" separated by 10000
- When new row is inserted, assign integer halfway in between its neighbors
- If rows become too tightly packed (have separation of one), then lock and re-assign "order_index" to all rows, incrementing by 10000
This is obviously somewhat complex and the re-assigning is not optimal since it takes longer than we'd like. Any better approach to this?