We have an application that needs precise order of items in a table based on datetime item (actually, autoincrement Id primary key) was created. It has to be without gaps and once created, never changed. Order number is later used as a legal identifier (its just a requirement). There could be thousands of items per partition.
Question is what is the better practice:
1) Calculate DENSE_RANK() on each retrieval of item from DB (which means calculating it over thousands of items)
OR
2) Calculate it on item creation and save in a dedicated column?
Additionally, if 2) is the better option, is there a way to optimize calculating it so that it starts from the previous one that has order number assigned or is it safer to always run DENSE_RANK() function on full partition?