Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phAvp-0006xW-2s for pgsql-general@arkaria.postgresql.org; Tue, 28 Mar 2023 15:08:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1phAvn-000434-VK for pgsql-general@arkaria.postgresql.org; Tue, 28 Mar 2023 15:08:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phAvn-00042t-Kf for pgsql-general@lists.postgresql.org; Tue, 28 Mar 2023 15:08:15 +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 1phAvi-0007ua-Ly for pgsql-general@lists.postgresql.org; Tue, 28 Mar 2023 15:08:15 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 811CC1DDE5; Tue, 28 Mar 2023 17:08:09 +0200 (CEST) Date: Tue, 28 Mar 2023 17:08:09 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Cluster table based on grand parent? Message-ID: <20230328150809.myepvgkbvytazk2d@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <28cfc94c-f778-548d-1159-e33627e44eec@aklaver.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="6vrsee3ccjvuyihx" Content-Disposition: inline In-Reply-To: <28cfc94c-f778-548d-1159-e33627e44eec@aklaver.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --6vrsee3ccjvuyihx Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2023-03-28 07:26:47 -0700, Adrian Klaver wrote: > On 3/28/23 06:17, Dominique Devienne wrote: > > PS: At this point, I don't even know how much cluster affects performan= ce. I think that this depends a lot on your access patterns (especially on how much you update the grandchild table and whether those updates can be HOT), so you will probably have to measure it yourself with a realistic work load. (Personally I doubt the impact is large, but I don't know your data or your access patterns.) > > =A0 =A0 But because it can affect the schema structure (by denormalizi= ng), > > i'd rather know early. >=20 > You will need to explain to me how it denormalizes? It reorders rows by > index definition and does not maintain that order over updates and insert= s. I think he means that in order to cluster the grandchild table by the paren= t.id he would have to denormalize the table. I.e. instead of like this: > > ``` > > dd=3D> create table parent (id int generated always as identity primary > > key, name text not null unique); > > CREATE TABLE > >=20 > > dd=3D> create table child (id int generated always as identity primary > > key, parent int not null references parent(id) on delete cascade, name > > text not null, unique(parent, name)); > > CREATE TABLE > >=20 > > dd=3D> create table grandchild (id int generated always as identity > > primary key, parent int not null references child(id) on delete cascade, > > name text not null, unique(parent, name)); > > CREATE TABLE > > ``` The last create statement would have to be like this: create table grandchild ( id int generated always as identity primary key, parent int not null references child(id) on delete cascade, grandparent int not null references parent(id) on delete cascade, name text not null, unique(grandparent, parent, name) ); hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --6vrsee3ccjvuyihx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmQjAtIACgkQ8g5IURL+ KF1EYw/+IJNGv2xJtyM5RF0UkZSAQHG8moKgdv4xV6/e43H5nUaESD2GmsOp7zfd BebnCnl48FPZ/vkLPeJgkq36sw93b0gAAgb+dMrnPe6YPP8KUnfP64J8MdKBr26C ecoDXlWKXx0JLnHCRDnuM73YknSywXYNlLPr5EZczPl38VTl3tt9ZMDSUAQooS4K zg/lET+MZ6djIB0Qxnq1E1e/ykiZ8WTA+q0dVZEEtcTkj5lYGpXNpmSgNJXWp7X0 Jsm7rz4csqnEuZHroEKqTT9T5CLrfUmiZ+1F0cKXMhPbGikp7Hust559BcRPp0rF pzXtuuDqrmn/iFcSZXys3fWvK5KdIrSk3qu0E7RShRRK5u+/unHgnjwQVMC4qQaP cIcHV5oVPzxF6BfYiTAZ5tunV7eNAhdmhAz+fUNZg/+SILv8uU1dN5L/LI+f1+Pe rSufg3oYkwcBrq9kTb0yt1Pd6lUjaX+9datp98QR4dvSdHxXQOIV65bOdATUAWVc oUJOMjVQ4n08/RCR5QZefLGEdWpPtp7Dz3KsEYZ7DlYWz+weQSjbv2I/F4Xge71J N8km58XvkVssWcmMbH1PDFgmNFhPk2b2L0ROBqRYPSTFJxsKVzpia+WjShtFuHfO IiiqwfqkTInXWUcsJnQlB5lLlxhAMf787cCLCBxkfV7t+rCJf7g= =iWcG -----END PGP SIGNATURE----- --6vrsee3ccjvuyihx--