I have a table with a auto-generated primary key and a DateTime field. And we have several clients inserting records, using the clock from the client computer for the Date/Time (i.e. it is not a true “TimeStamp” field). I have been tons of instances where the date/time is hours off when the records are ordered by the primary key. At first I presume the client computer clocks were off. But more and more I am thinking it could be some sort of caching mechanism on the database.
Is there anything that would explain this?
Oracle doesn’t cache inserts or updates: when a DML statement finishes, it means that the changes have been completed. When you commit they are permanent.
However, Oracle can cache the generation of the identifiers. If your primary key is generated by a sequence, by default Oracle will cache 20 keys and doesn’t guarantee that the keys will be distributed in the order they are asked.
Use the
ORDERkeyword to :Example:
Of course this assumes that all inserts also use
SYSTIMESTAMPorSYSDATE, if they use a client date setting, Oracle has no way to order the inserts.Ultimately, is it really important? For most applications only unicity matters and an auto-incremental field could be replaced by a GUID. Especially since you already have a timestamp column.