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.89) (envelope-from ) id 1iNNhw-0004Kf-0m for pgsql-general@arkaria.postgresql.org; Wed, 23 Oct 2019 20:58:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iNNhs-00059y-F4 for pgsql-general@arkaria.postgresql.org; Wed, 23 Oct 2019 20:58:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNNhr-00059p-Vp for pgsql-general@lists.postgresql.org; Wed, 23 Oct 2019 20:58:12 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iNNhp-0006eO-53 for pgsql-general@postgresql.org; Wed, 23 Oct 2019 20:58:10 +0000 Received: by mail-pf1-x432.google.com with SMTP id x127so13670144pfb.7 for ; Wed, 23 Oct 2019 13:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=F+XfUNfqN4jb+uJ2kLV/g2JehZiIVRxFLiyBDQBF0Dk=; b=QMyL4P9dTM3JBaKRV3sIcw8HU6bU7tjEhbDB+LCePnvsGC1EMTJKO/nQRzv+T1dQ4P Lf6MHKu3739875E+H7ToUMok3jKJhCf7lmEgJpMRsdr4l91yLQNiE9L7ju5PpyifXI1e kbKzMAtg9JLa7YP7HUFIbSJL0IK8NpMVNc1g+xOE7J2MDfmIlz7XfjmtvEBGycVlUyP1 LCSxahJ8uYNUidJw7dISOmquyT5PWrU/HQ5MSlPFTmDs0RxS0jMBoYkZB8slO10kEGQ3 7yxXA/EgvJuzeNqO8PLQW6K8iWtblCcynxhFywb28iIyJjHxH+VnfIw0DR37jYatGl4i zj5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=F+XfUNfqN4jb+uJ2kLV/g2JehZiIVRxFLiyBDQBF0Dk=; b=abzTHUqX+Dy/Uij96LyCgRckyNUI179NnjRKxSc/2GJpEqssW18aF49lLIS9ZRvlO6 LQLLL1+erL0RUVUTalTl8vz0rScV6FU/KzFSQO23odT8dEVmPjmpkBZsGyABvGcZ88zx X/jopFPB32SB+hD3bxXJurCNwzJNulm0kPNqEkd3gajl3kagdrhpLlxeXxeMFuzFoKgc u0zHHM7+vZZtNt3onOltGDWW9fx9lCxBXiuPiajbzQKoTBnBgbzclxz9uc/zRIL4EIt1 2UIqFeCon0W3yrA/FsBFLLWGgMDh2NVwbZubrezAvscLAdx6vvvK1YLZ10TDwH4sPewQ OuSA== X-Gm-Message-State: APjAAAXq155km/orUgl+vVTEYepj/tDGdEt+Rk0PD/65qXPPgVH5y5pp 7R0/Uw9v1xjAZJhEUbPjFeA= X-Google-Smtp-Source: APXvYqyp3PW4sOeDiJCnOmMnfpTQ5Iuicac3eCSKuLOAwOpDWMWzNC7Xe3S0xKznbUdyt6aR5vioSg== X-Received: by 2002:a63:d20c:: with SMTP id a12mr11385825pgg.402.1571864287589; Wed, 23 Oct 2019 13:58:07 -0700 (PDT) Received: from [10.106.132.111] ([155.100.47.7]) by smtp.gmail.com with ESMTPSA id j12sm182990pjz.12.2019.10.23.13.58.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Oct 2019 13:58:07 -0700 (PDT) From: Rob Sargent Message-Id: <90AA42A6-38FC-4117-90B5-4539302CA154@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_C92C99C1-20A1-4E3C-8297-D3770DB3C247" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: Composite type storage overhead Date: Wed, 23 Oct 2019 14:58:05 -0600 In-Reply-To: Cc: "pgsql-general@postgresql.org" To: =?utf-8?Q?Laiszner_Tam=C3=A1s?= References: X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_C92C99C1-20A1-4E3C-8297-D3770DB3C247 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Oct 23, 2019, at 1:32 PM, Laiszner Tam=C3=A1s = wrote: >=20 > Hey there, >=20 > I am currently exploring the options to utilize 128-bit numeric = primary keys. One of the options I am looking at is to store them as = composites of two 64-bit integers. >=20 > The documentation page on composite types does not tell too much about = the internal storage, so I've made my own experiment: >=20 > CREATE TYPE entity_id AS > (=E2=80=8B > high bigint,=E2=80=8B > low bigint=E2=80=8B > ); >=20 > CREATE TABLE composite_test > (=E2=80=8B > entity_id entity_id NOT NULL,=E2=80=8B > CONSTRAINT composite_test_pkey PRIMARY KEY (entity_id)=E2=80=8B > ) >=20 > INSERT INTO composite_test (entity_id) VALUES (ROW(0, 0)); >=20 > Now, as I am really interested in keeping the indexes compact, tried = pageinspect to find out what's going on internally: >=20 > SELECT * FROM bt_page_items(get_raw_page('composite_test_pkey', 1)); >=20 > It seems wrapping the values into a composite type has a pretty = significant storage overhead, as the index entry has a total size of 48 = bytes, end the data look like this: >=20 > 4b ff ff ff ff fa 40 00 00 ff ff ff ff 00 00 02 00 00 00 18 00 00 00 = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >=20 > For comparison, when simply using a composite primary key of two = columns, each index entry has a length of only 24 bytes - a 100% = overhead from wrapping the values in a composite type. >=20 > Now, I understand there might be valid reasons to store a structure = header alongside the plain data - e. g. to store version information so = when the type is altered there is no need to rebuild the whole table. >=20 > However, I also think this should be highlighted in the documentation. = (If it already is I apologise.) >=20 > Also, I would like ask if there is a way to instruct the storage = engine to omit the housekeeping information and simply store the plain = data, even if it comes with drawbacks. >=20 > I would highly appreciate any comments or additional information on = this topic. >=20 > Best regards, > Tamas Why not use UUID type? --Apple-Mail=_C92C99C1-20A1-4E3C-8297-D3770DB3C247 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Oct 23, 2019, at 1:32 PM, Laiszner Tam=C3=A1s <t.laiszner@outlook.com> wrote:

Hey there,

I am currently exploring = the options to utilize 128-bit numeric primary keys. One of the options = I am looking at is to store them as composites of two 64-bit = integers.

The documentation page on = composite types does not tell too much about the internal storage, so = I've made my own experiment:

CREATE = TYPE entity_id AS
(=E2=80=8B
    high bigint,=E2=80=8B
    low bigint=E2=80=8B
);

CREATE TABLE composite_test
(=E2=80=8B
  =   entity_id entity_id NOT NULL,=E2=80=8B
  =   CONSTRAINT composite_test_pkey PRIMARY KEY = (entity_id)=E2=80=8B
)

INSERT INTO composite_test (entity_id) = VALUES (ROW(0, 0));

Now, as I am really interested in = keeping the indexes compact, tried pageinspect to find out what's going = on internally:

SELECT * FROM =  bt_page_items(get_raw_page('composite_test_pkey', 1));

It seems wrapping the = values into a composite type has a pretty significant storage overhead, = as the index entry has a total size of 48 bytes, end the data look like = this:

4b ff ff = ff ff fa 40 00 00 ff ff ff ff 00 00 02 00 00 00 18 00 00 00 00 00 00 00 = 00 00 00 00 00 00 00 00 00 00 00 00 00

For comparison, when simply using a = composite primary key of two columns, each index entry has a length of = only 24 bytes - a 100% overhead from wrapping the values in a composite = type.

Now, I = understand there might be valid reasons to store a structure header = alongside the plain data - e. g. to store version information so when = the type is altered there is no need to rebuild the whole = table.

However, = I also think this should be highlighted in the documentation. (If it = already is I apologise.)

Also, I would like ask if there is a way to instruct the = storage engine to omit the housekeeping information and simply store the = plain data, even if it comes with drawbacks.

I would highly appreciate any comments = or additional information on this topic.

Best regards,
Tamas
Why not use = UUID type?

= --Apple-Mail=_C92C99C1-20A1-4E3C-8297-D3770DB3C247--