Save a few bytes per CatCTup

Started by cca5507about 1 month ago2 messageshackers
Jump to latest
#1cca5507
cca5507@qq.com

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

Attachments:

v1-0001-Save-a-few-bytes-per-CatCTup.patchapplication/octet-stream; charset=utf-8; name=v1-0001-Save-a-few-bytes-per-CatCTup.patchDownload+3-4
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: cca5507 (#1)
Re: Save a few bytes per CatCTup

"=?utf-8?B?Y2NhNTUwNw==?=" <cca5507@qq.com> writes:

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:

Good catch, pushed.

regards, tom lane