Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^5: Perl DBI and Foreign Keys

by soonix (Abbot)
on Apr 08, 2019 at 12:55 UTC ( #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 (Abbot) 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
Node Status?
node history
Node Type: note [id://1232294]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2019-05-24 17:55 GMT
Find Nodes?
    Voting Booth?
    Do you enjoy 3D movies?

    Results (151 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!