Re: Making type Datum be 8 bytes everywhere

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
Cc: Tomas Vondra <tomas(at)vondra(dot)me>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Joe Conway <mail(at)joeconway(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: Making type Datum be 8 bytes everywhere
Date: 2025-09-11 15:36:20
Message-ID: 1787515.1757604980@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> writes:
> Em qua., 10 de set. de 2025 às 17:35, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> escreveu:
>> This is silently assuming that sizeof(SortItem) is a multiple of
>> alignof(Datum), which on a 32-bit-pointer platform is not true
>> any longer. We ought to MAXALIGN the two occurrences of
>> data->numrows * sizeof(SortItem).

> We possibly have two more instances?

> 1. Function ndistinct_for_combination (src/backend/statistics/mvdistinct.c)
> - items = (SortItem *) palloc(numrows * sizeof(SortItem));
> + items = (SortItem *) palloc(MAXALIGN(numrows * sizeof(SortItem)));

> 2. Function build_distinct_groups (src/backend/statistics/mcv.c)
> - SortItem *groups = (SortItem *) palloc(ngroups * sizeof(SortItem));
> + SortItem *groups = (SortItem *) palloc(MAXALIGN(ngroups *
> sizeof(SortItem)));

Neither of those have any hazard, because they are not trying to
allocate multiple arrays using address arithmetic. The part of
build_sorted_items that was actually problematic was doing

ptr += data->numrows * sizeof(SortItem);

and then assuming that the result was suitably aligned to be
cast to Datum*.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2025-09-11 15:41:23 Re: Adding basic NUMA awareness
Previous Message Tom Lane 2025-09-11 15:32:00 Re: [PATCH] Hex-coding optimizations using SVE on ARM.