Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Architecture design for full stack development.

by sundialsvc4 (Abbot)
on Jun 24, 2017 at 03:12 UTC ( #1193426=note: print w/replies, xml ) Need Help??


in reply to Re^2: Architecture design for full stack development.
in thread Architecture design for full stack development.

I believe that you have somehow entirely missed my most-essential(!) point that “defrag code” is not only unnecessary, but specifically should not be pursued.

If you suppose that Primary Keys should need to be “defragmented,” then this indicates that you are attaching to them “some (any ...) intrinsic meaning.”   (Why?   Because it seems to bother you that the values might not be consecutive!)

If, for any legitimate business reason or otherwise, you need some sort of identifier that is “consecutive” and that therefore might from time-to-time need to be “defragmented” ... (although I certainly do not recommend such a thing) ... “feel free.™”   However, do not make this value “your primary key!”   Instead, make it “just another column.”

(For a more thorough background of what I am talking about, let me please now refer to Database Normalization in WikiPedia.)

The “primary key” of any and every(!) table within your database should be a perfectly-arbitrary, yet guaranteed-unique, “identifier ... and nothing more™ ...” of a particular row.   All such values should be entirely internal to the database, and never exposed to, therefore also never of material interest to, the outside world.

If you feel any need whatsoever to “defragment” those values, then this necessarily proves(!) that you are violating this precept ... and you should immediately redesign your database architecture accordingly.

“Do you really care what the exact numeric value of ‘your credit-card number’ is?”   “No, as long as it is unique!”   (And, but of course, as long as it works.)   Otherwise, it’s just a well-behaved “primary key.”   It uniquely identifies your account, but does nothing more.   And the credit-card company doesn’t give a damn whether it is “consecutive.”   Any valid but otherwise-random string of numbers is equally satisfactory ... as any good primary-key should always be.

  • Comment on Re^3: Architecture design for full stack development.

Replies are listed 'Best First'.
Re^4: Architecture design for full stack development.
by erix (Parson) on Jun 24, 2017 at 05:41 UTC

    The “primary key” of any and every(!) table within your database should be a perfectly-arbitrary, yet guaranteed-unique, “identifier ... and nothing more™ ...” of a particular row. All such values should be entirely internal to the database, and never exposed to, therefore also never of material interest to, the outside world.

    This touches on the general question on whether or not to use Natural Keys [1]. Apparently you think one should not use natural keys. You think surrogate keys are always necessary.

    That's fine, but it certainly isn't received wisdom. It is an open question: many people will argue that natural keys have important advantages [2]. I will always use natural keys where possible.

    [1] https://en.wikipedia.org/wiki/Natural_key

    [2] http://www.databasesoup.com/2015/03/primary-keyvil-reprised.html

      Nice post. That covers it at a high level pretty well. Thank you.

      it certainly isn't received wisdom.

      Not only that, i think most people who do that, do so out of sheer ignorance. When i ask them for the reasons, they repeat non-trueisms about how the RDBMS does things.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1193426]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2017-09-21 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (245 votes). Check out past polls.

    Notices?