Save a few bytes per CatCTup

From: cca5507 <cca5507(at)qq(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Save a few bytes per CatCTup
Date: 2026-03-11 03:25:22
Message-ID: tencent_A42E0544C6184FE940CD8E3B14A3F0A39605@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

The current code in CatalogCacheCreateEntry():

```
ct = (CatCTup *) palloc(sizeof(CatCTup) +
MAXIMUM_ALIGNOF + dtp->t_len);
ct->tuple.t_len = dtp->t_len;
ct->tuple.t_self = dtp->t_self;
ct->tuple.t_tableOid = dtp->t_tableOid;
ct->tuple.t_data = (HeapTupleHeader)
MAXALIGN(((char *) ct) + sizeof(CatCTup));
/* copy tuple contents */
memcpy((char *) ct->tuple.t_data,
(const char *) dtp->t_data,
dtp->t_len);
```

If I understand correctly, we just want "ct->tuple.t_data" align
to MAXIMUM_ALIGNOF here. So we can save MAXIMUM_ALIGNOF
bytes per CatCTup by this:

```
ct = (CatCTup *) palloc(MAXALIGN(sizeof(CatCTup)) +
dtp->t_len);
ct->tuple.t_len = dtp->t_len;
ct->tuple.t_self = dtp->t_self;
ct->tuple.t_tableOid = dtp->t_tableOid;
ct->tuple.t_data = (HeapTupleHeader)
(((char *) ct) + MAXALIGN(sizeof(CatCTup)));
/* copy tuple contents */
memcpy((char *) ct->tuple.t_data,
(const char *) dtp->t_data,
dtp->t_len);
```

It's correct because palloc() always return a max-aligned pointer.

--
Regards,
ChangAo Chen

Attachment Content-Type Size
v1-0001-Save-a-few-bytes-per-CatCTup.patch application/octet-stream 1.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2026-03-11 03:43:58 Re: support fast default for domain with constraints
Previous Message shveta malik 2026-03-11 03:24:46 Re: Skipping schema changes in publication