Are GUIDs timely ordered ? If ORDER BY used with a GUID variable type, will records created lately come late?

前提是你 提交于 2019-12-08 15:50:32

问题


Are GUIDs timely ordered ? I mean if you use ORDER BY with a GUID variable type, will records created lately come late ?


回答1:


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:


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.

See also How Random is System.Guid.NewGuid()? (Take two)

source: https://stackoverflow.com/a/3011149/1714342




回答3:


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.



来源:https://stackoverflow.com/questions/17881897/are-guids-timely-ordered-if-order-by-used-with-a-guid-variable-type-will-reco

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!