Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^6: Perl DBI and Foreign Keys

by afoken (Canon)
on Apr 09, 2019 at 23:24 UTC ( #1232375=note: print w/replies, xml ) Need Help??


in reply to Re^5: Perl DBI and Foreign Keys
in thread Perl DBI and Foreign Keys

what if it's wrapped within a transaction?

Still a race. This is really a FAQ. The only clean way is to use what the database offers, either sequences or their crippled replacement, auto-generated IDs. See Re^2: Perl DBI and Foreign Keys.


Of course, you could build your own service to generate unique IDs without race conditions and add that on top. (Quite a challenge if you want it to work with high load ...) But as already explained, this service is already provided by almost any SQL database at no extra cost.

(And please don't come up with UUIDs. They come in different classes, with different properties (see UUID), and some of them are actually quite unlikely to collide. Others are more likely to collide. IDs generated by the database are guaranteed not to collide, and you don't need anything else but the existing database engine.)

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1232375]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2020-08-05 10:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (35 votes). Check out past polls.

    Notices?