Are GUIDs timely ordered ? I mean if you use ORDER BY with a GUID variable type, will records created lately come late ?
A simple LINQPad mockup answers your question:
var dictionary = new Dictionary<int, Guid>();
for (int i = 0; i < 5; i++)
dictionary.Add(i, Guid.NewGuid());
dictionary.OrderBy(d => d.Value);
Results in:
Key Value
2 3624183d-581a-45bc-9d3d-cafeddaf8585
0 4b4685c9-f163-4694-ae8c-4b83402a293c
4 7a14d8e4-d870-4f33-bfb3-f4337b756e18
1 b93131c7-c0d7-42b4-82b5-e3cc456214a9
3 cfdc0bc8-7f5a-4601-a927-a759bb9e33c6
-
2
-
1@ChrisMarisic How so? If GUIDs were ordered by creation as per the question, then the keys in the result would go in ascending order rather than random order. – dav_i Nov 29 '18 at 9:58
-
3Just because it appears random doesn't mean its actually random. Lexically they're unordered, but that doesn't mean with a different comparer that they are not in fact ordered. However @wudzik provides the meaningful answer that the guids are generated by cryptographic number generation and not with any time series component to create any type of implicit order. – Chris Marisic Nov 30 '18 at 20:06
On Windows, GUIDs (UUIDs) are created from a cryptographic random number generator with UuidCreate. They are version 4 UUIDs in terms of RFC 4122. No timestamps or ethernet cards are involved, unless you're using old school version 1 GUIDs created with UuidCreateSequential.
Please see this
A Globally Unique Identifier (GUID, /ˈɡwɪd/or /ˈɡuːɪd/) is a unique reference number used as an identifier in computer software. The term GUID typically refers to various implementations of the universally unique identifier (UUID) standard.1 GUIDs are usually stored as 128-bit values, and are commonly displayed as 32 hexadecimal digits with groups separated by hyphens, such as {21EC2020-3AEA-1069-A2DD-08002B30309D}. GUIDs generated from random numbers contain 6 fixed bits saying they are random and 122 random bits; the total number of unique such GUIDs is 2122 or 5.3×1036. This number is so large that the probability of the same number being generated randomly twice is negligible; however other GUID versions have different uniqueness properties and probabilities, ranging from guaranteed uniqueness to likely non-uniqueness.
newsequentialid()
was introduced to address that concern: "Using NEWSEQUENTIALID also helps to completely fill the data and index pages." – Damien_The_Unbeliever Jul 26 '13 at 13:11