mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
Grab the low-hanging fruit from forcing sizeof(Datum) to 8.
Remove conditionally-compiled code for smaller Datum widths, and simplify comments that describe cases no longer of interest. I also fixed up a few more places that were not using DatumGetIntXX where they should, and made some cosmetic adjustments such as using sizeof(int64) not sizeof(Datum) in places where that fit better with the surrounding code. One thing I remembered while preparing this part is that SP-GiST stores pass-by-value prefix keys as Datums, so that the on-disk representation depends on sizeof(Datum). That's even more unfortunate than the existing commentary makes it out to be, because now there is a hazard that the change of sizeof(Datum) will break SP-GiST indexes on 32-bit machines. It appears that there are no existing SP-GiST opclasses that are actually affected; and if there are some that I didn't find, the number of installations that are using them on 32-bit machines is doubtless tiny. So I'm proceeding on the assumption that we can get away with this, but it's something to worry about. (gininsert.c looks like it has a similar problem, but it's okay because the "tuples" it's constructing are just transient data within the tuplesort step. That's pretty poorly documented though, so I added some comments.) Author: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://postgr.es/m/1749799.1752797397@sss.pgh.pa.us
This commit is contained in:
@@ -15,7 +15,9 @@
|
||||
#include "utils/sortsupport.h"
|
||||
|
||||
/*
|
||||
* Data for one key in a GIN index.
|
||||
* Data for one key in a GIN index. (This is not the permanent in-index
|
||||
* representation, but just a convenient format to use during the tuplesort
|
||||
* stage of building a new GIN index.)
|
||||
*/
|
||||
typedef struct GinTuple
|
||||
{
|
||||
|
||||
@@ -285,10 +285,12 @@ typedef struct SpGistCache
|
||||
* If the prefix datum is of a pass-by-value type, it is stored in its
|
||||
* Datum representation, that is its on-disk representation is of length
|
||||
* sizeof(Datum). This is a fairly unfortunate choice, because in no other
|
||||
* place does Postgres use Datum as an on-disk representation; it creates
|
||||
* an unnecessary incompatibility between 32-bit and 64-bit builds. But the
|
||||
* compatibility loss is mostly theoretical since MAXIMUM_ALIGNOF typically
|
||||
* differs between such builds, too. Anyway we're stuck with it now.
|
||||
* place does Postgres use Datum as an on-disk representation. Formerly it
|
||||
* meant an unnecessary incompatibility between 32-bit and 64-bit builds, and
|
||||
* as of v19 it instead creates a hazard for binary upgrades on 32-bit builds.
|
||||
* Fortunately, that hazard seems mostly theoretical for lack of affected
|
||||
* opclasses. Going forward, we will be using a fixed size of Datum so that
|
||||
* there's no longer any pressing reason to change this.
|
||||
*/
|
||||
typedef struct SpGistInnerTupleData
|
||||
{
|
||||
@@ -377,8 +379,8 @@ typedef SpGistNodeTupleData *SpGistNodeTuple;
|
||||
*
|
||||
* size must be a multiple of MAXALIGN; also, it must be at least SGDTSIZE
|
||||
* so that the tuple can be converted to REDIRECT status later. (This
|
||||
* restriction only adds bytes for a NULL leaf datum stored on a 32-bit
|
||||
* machine; otherwise alignment restrictions force it anyway.)
|
||||
* restriction only adds bytes for a NULL leaf datum; otherwise alignment
|
||||
* restrictions force it anyway.)
|
||||
*/
|
||||
typedef struct SpGistLeafTupleData
|
||||
{
|
||||
|
||||
@@ -39,9 +39,6 @@ att_isnull(int ATT, const bits8 *BITS)
|
||||
* return the correct number of bytes fetched from the data area and extended
|
||||
* to Datum form.
|
||||
*
|
||||
* On machines where Datum is 8 bytes, we support fetching 8-byte byval
|
||||
* attributes; otherwise, only 1, 2, and 4-byte values are supported.
|
||||
*
|
||||
* Note that T must already be properly aligned for this to work correctly.
|
||||
*/
|
||||
#define fetchatt(A,T) fetch_att(T, (A)->attbyval, (A)->attlen)
|
||||
@@ -62,10 +59,8 @@ fetch_att(const void *T, bool attbyval, int attlen)
|
||||
return Int16GetDatum(*((const int16 *) T));
|
||||
case sizeof(int32):
|
||||
return Int32GetDatum(*((const int32 *) T));
|
||||
#if SIZEOF_DATUM == 8
|
||||
case sizeof(Datum):
|
||||
return *((const Datum *) T);
|
||||
#endif
|
||||
case sizeof(int64):
|
||||
return Int64GetDatum(*((const int64 *) T));
|
||||
default:
|
||||
elog(ERROR, "unsupported byval length: %d", attlen);
|
||||
return 0;
|
||||
@@ -221,11 +216,9 @@ store_att_byval(void *T, Datum newdatum, int attlen)
|
||||
case sizeof(int32):
|
||||
*(int32 *) T = DatumGetInt32(newdatum);
|
||||
break;
|
||||
#if SIZEOF_DATUM == 8
|
||||
case sizeof(Datum):
|
||||
*(Datum *) T = newdatum;
|
||||
case sizeof(int64):
|
||||
*(int64 *) T = DatumGetInt64(newdatum);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
elog(ERROR, "unsupported byval length: %d", attlen);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user