On Fri, Jul 31, 2026 at 1:10 PM Matthias van de Meent
<[email protected]> wrote:
>
...
> This test is not representative of real toast indexes, because it
> skips the chunk number column. The addition of the chunk number column
> will impact the size of the index, because now the index items are 16B
> for OID vs 24B for OID8, for 20B and 28B page data usage respectively
> after taking the 4-byte line pointer into account. Back of the
> envelope calculations indicate this means the OID8 index will be about
> 40% larger.

Yes, you are right:

hannuk=# create table oid_vs_bigint(id oid, int8 bigint, chunk_id int,
unique(id, chunk_id), unique(int8, chunk_id));
CREATE TABLE
hannuk=# insert into oid_vs_bigint select i, i, 0 from
generate_series(1,100000) g(i);
INSERT 0 100000
hannuk=# select indexrelid::regclass, pg_relation_size(indexrelid)
from pg_index where indrelid = 'oid_vs_bigint'::regclass;
           indexrelid            │ pg_relation_size
─────────────────────────────────┼──────────────────
 oid_vs_bigint_id_chunk_id_key   │          2260992
 oid_vs_bigint_int8_chunk_id_key │          3162112
(2 rows)

So indeed 40% more, and you get the *same* number even if you used
OID6 (i.e 6-byte tid)

hannuk=# create table oid_vs_bigint(id oid, int8 tid, chunk_id int,
unique(id, chunk_id), unique(int8, chunk_id));
CREATE TABLE
hannuk=# insert into oid_vs_bigint select i, format('(%s,1)',i)::tid,
0 from generate_series(1,100000) g(i);
INSERT 0 100000
hannuk=# select * from oid_vs_bigint limit 2;
 id │ int8  │ chunk_id
────┼───────┼──────────
  1 │ (1,1) │        0
  2 │ (2,1) │        0
(2 rows)
hannuk=# select indexrelid::regclass, pg_relation_size(indexrelid)
from pg_index where indrelid = 'oid_vs_bigint'::regclass;
           indexrelid            │ pg_relation_size
─────────────────────────────────┼──────────────────
 oid_vs_bigint_id_chunk_id_key   │          2260992
 oid_vs_bigint_int8_chunk_id_key │          3162112
(2 rows)

----
Hannu

Reply via email to