Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^5: Perl DBI and Foreign Keys

by soonix (Canon)
on Apr 08, 2019 at 12:55 UTC ( [id://1232294]=note: print w/replies, xml ) Need Help??

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

what if it's wrapped within a transaction?

Replies are listed 'Best First'.
Re^6: Perl DBI and Foreign Keys
by afoken (Chancellor) on Apr 09, 2019 at 23:24 UTC
    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.)


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

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-16 13:54 GMT
Find Nodes?
    Voting Booth?

    No recent polls found