Disk space is cheap… That's not the point
sqlskills.com
sqlskills.com
The take-away, as far as I can tell, is that database design requires some analysis of what's best for one's particular data set, rather than duplicating what looks hot right now. Which is a good idea in any context if performance really matters.
[1] http://www.codinghorror.com/blog/2007/03/primary-keys-ids-ve...
But seriously. Global-id-space is something I'll probably use on every new project I touch... presumably for the same reasons people use GUIDs. So nice to know that you can change data types, pack things into caches without type-ids, or log identifiers without extra metadata. Super handy.
On the other hand, they take up a lot of space, in particular, they fill RAM. They make the most used indexes in your system large and slow.
Practically, the need for GUIDs can be eliminated by establishing a server that works like the "take a ticket" machine at the supermarket. Any node that makes a new object makes an API call and gets a new id.
(You can also add an identifier for each system and the current time, if you don't trust your source of randomness. But that's beside the point.)
Think about it this way: with careful planning, you can use a 24-bit number and have a reasonably large space of non-conflicting values. I wouldn't trust rand() for this, but if there was a single server allocating numbers in sequential order, this would be fine.
While at 128-bits, rand() starts becoming reasonable, the UUID algorithm is designed to produce the "actually guaranteed to be globally unique" experience that the sequentially incrementing counter did.
On an individual computer, this requires coordinating with a library (preferably OS-supported, such as on Windows) in order to obtain global locks, allowing identifiers to then be identified by a timestamp (to guarantee that you can reuse the hardware later; this requires your clock to be monotonically increasing on any given piece of hardware, which in practice means "make it accurate"; there is a sequence numbering mechanism for allowing clock rollbacks).
Between computers, node identifiers are MAC addresses, which are unique by administrative fiat (blocks are allocated to companies, who are responsible for guaranteeing the uniqueness of their devices; if you feel like some of these providers are not abiding by this, you can simply not use their hardware for your networking infrastructure, which is a good idea anyway due to how Ethernet works).
If you haven't skimmed the spec, I recommend you do at some point: http://www.ics.uci.edu/~ejw/authoring/uuid-guid/draft-leach-...
"""This specification defines the format of UUIDs (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDentifier). A UUID is 128 bits long, and if generated according to the one of the mechanisms in this document, is either guaranteed to be different from all other UUIDs/GUIDs generated until 3400 A.D. or extremely likely to be different (depending on the mechanism chosen). UUIDs were originally used in the Network Computing System (NCS) [1] and later in the Open Software Foundation's (OSF) Distributed Computing Environment [2]."""
Meta: I don't get why you are being downmodded, especially as I am being upvoted. Can someone help me understand why? Even though I disagree with you, famousactress, I do find your comments contributing to the discussion.
Now, the table is not just sequentially written records, they are actually organized as some b-tree variant. Still, appending to a b-tree is a faster operation than inserting in the middle.
Rebuilding the index (actually the table) with a FILLFACTOR parameter makes space in each b-tree node so that new records don't cause too much reordering. This is not much of a solution though, because as the table grows the 10% unallocated space will fill up and the performance will be back where we started.
To explain the benchmarks shortly:
- the performance difference between ints and sequential GUIDs is because GUIDs are larger
- the performance difference between sequental and random GUIDs comes from appending records to the table vs inserts at random positions in the table
- FILLFACTOR helps temporarily with random inserts by making space available before the inserts happen
Also i don't think that the percentage of applications that need this level of performance and no more is as small as you think it is. plenty of successful businesses run critical application on SQL server (and other dbs) and this kind of degradation could be disastrous. I don't think the necessity for SQL tuning is as esoteric at all.
Another possible advantage of "sequential" UUIDs comes when a number of them get transmitted in a textual form, for instance if they are product IDs and you are sending out a long HTML page of links to products. The sequential IDs will offer more redundancy for any transport level compression to chew on than the normal random ones (assuming they are indeed sufficiently random) will. This may also come into play if your database engine supports compressed storage directly, as MSSQL 2008 does for backups (std and enterprise editions) and live data files (ent edition only), though to a much lesser extent unless the compression algorithm chosen is specifically optimal for small variations in to 128-bit aligned data.
I've been told many times, even in university by seemingly educated professors, that disk space is not a major factor while programming. But that doesn't mean it can be dismissed either.
I have seen some terrible waste of space by programmers that don't know or care about the cost of enterprise disk space (let alone performance of system/app).