Ctid$
Has no params
Description:
Moxie.Build Time Ordered Unique Identifier which may be more suitable for transactional records and IDs than a purely random value such as a CUID or GUID.
A CTID is a 20 byte hex string and is made up of the following components:
- 5 bytes for the date
- Calculated as %Greg - 145731, for a base of 2000-01-01
- This value will not wrap until the year 4872
- 7 bytes for the time in milliseconds
- 2 bytes for a per-thread per-millisecond increment starting at 00
- If this increment wraps from FF to 00, the thread will sleep for 1 millisecond to ensure the first 14 bytes of the CTID are always unique and sortable per-thread
- 6 bytes of a GUID to ensure uniqueness across threads and distributed systems
The advantages of using a CTID over a CUID are:
- When used as a Record Alias, records are stored and retrieved in creation order (within the resolution and thread as defined above)
- Like CUIDs and GUIDs, they are effectively globally unique across distributed systems
- Saves 12 bytes compared a CUID, or 16 compared to a punctuated GUID
The disadvantages of using a CTID over a CUID are:
- They store and can therefore leak potentially sensitive information regarding date, time, and can help inform approaches to timing related attacks. Therefore, careful consideration must be taken in sharing these values or using them as IDs client-side with users of various roles within your application, if at all
- While CUIDs and GUIDs are often used for security requiring randomness, CTIDs in most cases should not be used for this role due to the limited six hex bytes for randomness plus the above issue regarding leaking potentially sensitive information
Example:
[New] MyVal = Ctid$
Example back to back Ctid$ values with a Sleep 1 in between these two blocks. Spaces added for readability here are not included in actual values.
Date Milli. Id Random
0223C 439D4D0 00 E3C507
0223C 439D4D0 01 C883F2
0223C 439D4D0 02 4E3A19
0223C 439D4D0 03 5263C7
0223C 439D4D0 04 61FFC2
0223C 439D4D0 05 7E81E5
0223C 439D4D0 06 579DA0
0223C 439D4DF 00 9BCD0E
0223C 439D4DF 01 F5BE4E
0223C 439D4DF 02 A1888C
0223C 439D4DF 03 4066FF
0223C 439D4DF 04 F892C9
0223C 439D4DF 05 7117A3
0223C 439D4DF 06 8F4293