web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Hidden Gem: Entity Primary Key GUID - sort order

Arun Vinoth Profile Picture Arun Vinoth 11,615 Moderator
This is a very interesting research & quite a new learning for me, so thought of sharing. As usual it all started with a Stack Overflow question.

I am surprised that there is a special GUID sort algorithm, gist is below:

The comparison is made by looking at byte "groups" right-to-left, and left-to-right within a byte "group". A byte group is what is delimited by the '-' character. More technically, we look at bytes {10 to 15} first, then {8-9}, then {6-7}, then {4-5}, and lastly {0 to 3}.

Let's take the example of below three sample GUIDs
b9b0f003-356d-e911-a966-000d3a1d7430
4298cdf4-4370-e911-a966-000d3a1d7430
97582b3c-2f6d-e911-a971-000d3a1d7b43
Why they are in this particular sort order, the reason is above algorithm.

b9b0f003-356d-e911-a966-000d3a1d7430 is smaller than 4298cdf4-4370-e911-a966-000d3a1d7430.
Similarly 4298cdf4-4370-e911-a966-000d3a1d7430 is smaller than 97582b3c-2f6d-e911-a971-000d3a1d7b43.

This was originally posted here.

Comments

*This post is locked for comments