Change xl_hash_vacuum_one_page.ntuples from int to uint16 - Mailing list pgsql-hackers

From Drouvot, Bertrand
Subject Change xl_hash_vacuum_one_page.ntuples from int to uint16
Date
Msg-id b0e20c40-cb7a-fc1c-c607-2a78dac5021e@gmail.com
Whole thread Raw
Responses Re: Change xl_hash_vacuum_one_page.ntuples from int to uint16
List pgsql-hackers
Hi hackers,

While working on [1], I noticed that xl_hash_vacuum_one_page.ntuples is an int.

Unless I'm missing something, It seems to me that it would make more sense to use an uint16 (like this is done for
gistxlogDelete.ntodelete for example).

Please find attached a patch proposal to do so.

While that does not currently change the struct size:

No patch:

(gdb) ptype /o struct xl_hash_vacuum_one_page
/* offset      |    size */  type = struct xl_hash_vacuum_one_page {
/*      0      |       4 */    TransactionId snapshotConflictHorizon;
/*      4      |       4 */    int ntuples;

                                /* total size (bytes):    8 */
                              }
With patch:

(gdb) ptype /o struct xl_hash_vacuum_one_page
/* offset      |    size */  type = struct xl_hash_vacuum_one_page {
/*      0      |       4 */    TransactionId snapshotConflictHorizon;
/*      4      |       2 */    uint16 ntuples;
/* XXX  2-byte padding   */

                                /* total size (bytes):    8 */
                              }

It could reduce it when adding new fields (like this is is done in [1]).

We would get:

No patch:

(gdb) ptype /o struct xl_hash_vacuum_one_page
/* offset      |    size */  type = struct xl_hash_vacuum_one_page {
/*      0      |       4 */    TransactionId snapshotConflictHorizon;
/*      4      |       4 */    int ntuples;
/*      8      |       1 */    _Bool isCatalogRel;
/* XXX  3-byte padding   */

                                /* total size (bytes):   12 */
                              }

With patch:

(gdb) ptype /o struct xl_hash_vacuum_one_page
/* offset      |    size */  type = struct xl_hash_vacuum_one_page {
/*      0      |       4 */    TransactionId snapshotConflictHorizon;
/*      4      |       2 */    uint16 ntuples;
/*      6      |       1 */    _Bool isCatalogRel;
/* XXX  1-byte padding   */

                                /* total size (bytes):    8 */
                              }

Means saving 4 bytes in that case.

Looking forward to your feedback,

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Attachment

pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Collation version tracking for macOS
Next
From: Dean Rasheed
Date:
Subject: Re: Add proper planner support for ORDER BY / DISTINCT aggregates