Save a few bytes per CatCTup - Mailing list pgsql-hackers

From cca5507
Subject Save a few bytes per CatCTup
Date
Msg-id tencent_A42E0544C6184FE940CD8E3B14A3F0A39605@qq.com
Whole thread Raw
Responses Re: Save a few bytes per CatCTup
List 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

pgsql-hackers by date:

Previous
From: shveta malik
Date:
Subject: Re: Skipping schema changes in publication
Next
From: jian he
Date:
Subject: Re: support fast default for domain with constraints