AW: UUID vs. Sequential ID as Primary

From: <ahmed.fikri_at_t-online.de>
Date: Thu, 11 Apr 2024 19:52:49 +0200 (CEST)
Message-ID: <1712857969930.150718.bbe2194345e98de2446251dff1be061d6892ad74_at_spica.telekom.de>





Thank you all for your insightful responses. I share the concern about mistakenly assuming uniqueness, as it could have serious consequences down the line.
As for Peter's suggestion, the challenge lies in the fact that the client doesn't handle the insertion process; it simply needs to generate a unique ID for an entity without directly "interacting" with the database. This can be achieved if the client understands how IDs are generated, such as being aware of a sequence on the database side and can access that sequence. However, when using identities, there's a significant hurdle because the client lacks access to the internally generated sequence, even if one is utilized server-side. Consequently using IDENTITY leads to poor performance as just creating a row at client side require round trip to the database (The client determines when and whether to insert eventual rows into the database, so it creates a sort of local cache that should, at a certain point, mirror the database). The system only functions smoothly if the client can interact with the sequence directly.  

Personally, I lean towards using sequences, but I hesitate to recommend them to others without being able to precisely justify why. Perhaps there's a benefit to using UUIDs that I'm not yet aware of.            

-----Original-Nachricht-----
Betreff: RE: Re: UUID vs. Sequential ID as Primary Datum: 2024-04-11T19:18:50+0200
Von: "Clay Jackson (cjackson)" <Clay.Jackson_at_quest.com> An: "ahmed.fikri_at_t-online.de" <ahmed.fikri_at_t-online.de>, "peter.m.gram_at_gmail.com" <peter.m.gram_at_gmail.com>      

I think MWF hit most of the high points, ESPECIALLY, “it depends” and “trusting” the generator of the UUIDs.  

I’ve actually seen cases where “We THOUGHT the UUID was unique”; but data can persist for a LONG time, in many cases longer than whatever code or application generates the UUID.  

Peter makes some good points about minimizing database round trips (SQL*NET Wait for Client, anyone?). I would assert that the “best of both worlds” could be had by using a DATABASE sequence as the primary key; then storing the UUID as a separate, uniquely indexed field. Storage and CPU are relatively inexpensive.  

Clay Jackson

Database Solutions Sales Engineer
<https://www.quest.com/solutions/database-performance-monitoring/>

clay.jackson_at_quest.com <mailto:clay.jackson_at_quest.com>

office 949-754-1203 mobile 425-802-9603  

From: oracle-l-bounce_at_freelists.org <oracle-l-bounce_at_freelists.org> On Behalf Of ahmed.fikri_at_t-online.de
Sent: Thursday, April 11, 2024 7:35 AM
To: peter.m.gram_at_gmail.com
Cc: list, oracle <oracle-l_at_freelists.org> Subject: AW: Re: UUID vs. Sequential ID as Primary  

CAUTION: This email originated from outside of the organization. Do not follow guidance, click links, or open attachments unless you recognize the sender and know the content is safe.  

Thanks for the hint, you’re right, one can use that. The problem is that when working with hibernate (or any other client lib) one doesn’t want to go to the database to fetch the IDs when creating an entry on the client side. While one does want to create the ID uniquely, it should be done with minimum visiting the database (using sequences has now been optimally solved e.g. hilo algorithm, not just for Oracle, but almost all other databases).

I’m interested in our experts have to say about this: is the trend of using UUID legitimate, or is using numbers better?

Gesendet mit der Telekom Mail App
<http://www.t-online.de/service/redir/emailmobilapp_ios_smartphone_footerlink.htm>

-----Original-Nachricht-----
Von: Peter Gram <peter.m.gram_at_gmail.com <mailto:peter.m.gram_at_gmail.com> > Betreff: Re: UUID vs. Sequential ID as Primary Datum: 11.04.2024, 16:10 Uhr
An: <ahmed.fikri_at_t-online.de <mailto:ahmed.fikri_at_t-online.de> > CC: list, oracle <oracle-l_at_freelists.org <mailto:oracle-l_at_freelists.org> >

Hi  

If you use the returning clause on the first statement you don’t get a extra round trip to the database to get the sequence.

Med venlig hilsen

Peter Gram
Sæbyholmsvej 18

2500 Valby

Mobile: (+45) 5374 7107

Email: peter.m.gram_at_gmail.com <mailto:peter.m.gram_at_gmail.com>      

On Wed, 10 Apr 2024 at 23.38, ahmed.fikri_at_t-online.de
<mailto:ahmed.fikri_at_t-online.de> < ahmed.fikri_at_t-online.de
<mailto:ahmed.fikri_at_t-online.de> > wrote:

 Hi there,   

 Once more, a question about fundamentals:   

 In several Hibernate projects, I've observed developers leaning towards  using UUIDs as primary keys instead of numerical values. This preference  likely stems from the avoidance of sequences for numerical primary keys,  which necessitate round trips to the database after each insertion.  Additionally, there's a concern about potential contention with sequences,  and some developers may prefer to avoid predictability in the next  generated value. Personally, I remain skeptical about the widespread use  of UUIDs due to their larger storage footprint (both in tables and  indexes) compared to numerical IDs. Numeric IDs also offer benefits in  issue analysis. However, it's worth noting that Hibernate employs  algorithms to minimize round trips to the database, effectively reducing  their impact. Could you please share your experience and preference? What  choice would you make?   

 Regards
 Ahmed     





--
http://www.freelists.org/webpage/oracle-l


image001.jpg
(image/jpeg attachment: image001.jpg)

Received on Thu Apr 11 2024 - 19:52:49 CEST

Original text of this message