Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jFylb-00081k-Sk for pgsql-general@arkaria.postgresql.org; Sun, 22 Mar 2020 11:27:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jFylY-0006KX-JS for pgsql-general@arkaria.postgresql.org; Sun, 22 Mar 2020 11:27:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jFylY-0006JP-9K for pgsql-general@lists.postgresql.org; Sun, 22 Mar 2020 11:27:40 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jFylU-00045p-EJ for pgsql-general@lists.postgresql.org; Sun, 22 Mar 2020 11:27:39 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 15BAF299E; Sun, 22 Mar 2020 12:27:33 +0100 (CET) Date: Sun, 22 Mar 2020 12:27:33 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Could postgres12 support millions of sequences? (like 10 million) Message-ID: <20200322112733.GA4548@hjp.at> References: <5ECC9E60-C4BF-47F2-AB6D-3782B05B438C@gmail.com> <20200321191336.GB5473@hjp.at> <4830DEFF-4229-4F28-9FFB-AF8186E42CD4@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="3V7upXqbjpZ4EhLz" Content-Disposition: inline In-Reply-To: <4830DEFF-4229-4F28-9FFB-AF8186E42CD4@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --3V7upXqbjpZ4EhLz Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2020-03-21 14:51:35 -0600, Rob Sargent wrote: > > On Mar 21, 2020, at 1:13 PM, Peter J. Holzer wrote: > >=20 > > On 2020-03-21 12:55:33 -0600, Rob Sargent wrote: > >> To me the description of the ID smacks of database-in-the-name folly. I > >> recognize that OP is likely unable to take another path. I=E2=80=99ll = not push this any > >> further.=20 > >=20 > > Identifiers often have internal structure. In Austria for example, the > > social security number contains the birth date. Invoice numbers, project > > numbers or court case numbers often contain the year. > >=20 > > That's because they are used by *people*, and people like their > > identifiers to make some kind of sense. The computer doesn't care. >=20 > Since OP said this was digital not paper, I see this as a presentation > problem bleeding into database design (assuming your response was an > invitation to push further). Well, that's the old natural primary key vs. surrogate primary key debate. (Trigger warning: You probably already heard that a gazillion times) A primary key is an attribute (or a combination of attributes) which unambiguosly identifies each entity.=20 If the entity in question already has such an atttribute (e.g. an SSN, invoice number, username, ...) and you use that as the primary key, is is called a natural primary key[1]. If you generate a new attribute not related to existing attributes it is called a surrogate (primary) key. If the entity already has an attribute suitable as a primary key, why would you want to use another one? * The key candidate may be unwieldy: It might be a combination of several attributes, it might be a very long string, etc. * You may suspect that the key candidate is not in fact a key. There have been cases of duplicate SSNs in several countries, and of course not every person has an SSN. Some people say you should always use surrogate keys, never natural keys. Mostly because of the second reason, I think: When you design a system you have limited knowledge, so you can never be absolutely sure that what appears to be a key candidate actually is one. OTOH, surrogate keys have downsides, too: The attributes which would have been a natural key are still there and must be stored, input, output, maybe generated, used in business rules, etc. So that's a (usually modest) increase in application complexity. More importantly, everywhere you would have had a (to a domain expert) meaningful key you now have a meaningless key - which makes it harder to understand the data and makes extra joins necessary. So to inspect the contents of a table instead of a simple "select * from tablename" you need a join over three or four tables. To get back to the OP's problem: As I understand it he needs to generate that compound identifier anyway, because it is used outside of the application. He could use a surrogate key in addition to that, but I don't see any advantage to that. Most importantly it doesn't solve the problem he wants to discuss in this thread[2]. hp [1] But note that these attributes are almost always already artificial: Humans aren't born with an SSN - that is assigned by an authority to uniquely identify their clients; courts have sat for centuries without the need to number their cases; etc. [2] I admit I haven't been very helpful in this regard, either, going off on tangents at every opportunity. --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --3V7upXqbjpZ4EhLz Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl53S6AACgkQ8g5IURL+ KF07Vw//UthJCfb3n9Es5DpTwOb1RGUV99rn0MWf8aJbm776ch26QBWEqkxRyPUm 8g9M3ltMasdPOo7o+vwOO3h1CoNNyvt34unCau7fPGlogjleHpZ871XkuE+c4T2C shzpSkDlUJRlxTFj57YJfNc1yUThALelZ450BmSzARJiFyKXAnfdjKmXmf7lbSx7 K5T+QOTLEyVv6ZyFbfpnUgNrsr2dE490yThaCWQFZQjM4mxQaG6zBEBr/SG3b2sW 2Skopo9h5c+k2ssxaEvJo9eBW83mqX60kKPB/BpCAXfbW6fPc7pnf4+eT6jmxK60 ARm0EpRHXv0GZ6WIppWG9CHLDjUgwLSO468nfkBAPXHXDhZxy1TKQamB5Oa+JsxI AQS8lHXsyZ5mM8cbBAExrGesktYef7MT3KcUukR1MWVfWsrA7qjeTuPGtJDkF9b/ 7irW6tleK8TyPcjSKh80jFnVfs7ZLIXlP7bo6TbKnyhdMeOkegHBxx/5c9YTQRxB bPzeaAFeJ4sxPykcJer2GOj3o7D1yx92cwR5tmzvMfH3c7RNkycAxAQjVsRFOsz+ BrR62pEn7d2H4vGpy7awxKt64PXmWPNMh0hsz8kUwT6tC0bgNh5xuNv8WMt4zePj w0GcNFP3pxtq0ysUBwiMUOMPqGPTVIzP+yz1jT9Df974ol751I4= =q7+g -----END PGP SIGNATURE----- --3V7upXqbjpZ4EhLz--