Decoupling our alignment assumptions about int64 and double
Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Over in the long-running thread about resurrecting AIX support,
one salient concern is that AIX has alignof(int64) = 8 but
alignof(double) = 4. This breaks all our code that supposes
that ALIGNOF_DOUBLE is the platform's maximum alignment spec.
We had coped with this via various unspeakable klugery back
when AIX was considered supported, but nobody wants to put
back those restrictions if we re-support AIX. (See my gripe
at [1], but I believe Heikki and Andres complained of this
in more detail long ago.)
Here is a modest proposal for fixing that in a clean way.
Let's break TYPALIGN_DOUBLE into three values, TYPALIGN_DOUBLE
for float8 only, TYPALIGN_INT64 for 64-bit integral types
including pointers, and TYPALIGN_MAX to represent MAXALIGN
alignment regardless of which of the first two determine it.
We need TYPALIGN_MAX because that's the value composite
types should use, so that their alignment doesn't change
if somebody adds or deletes a column of a relevant type.
Given that design, the patch is pretty straightforward,
and smaller than I feared it might be. (Though I might
have missed a spot or two.)
I think this is good cleanup and deserves consideration
whether we accept the AIX patch soon or not.
A loose end that deserves mention is that I noticed we
are very inconsistent about the length/alignment
attributed to polymorphic types:
select typname, typlen, typalign from pg_type where typname like 'any%';
typname | typlen | typalign
-------------------------+--------+----------
any | 4 | i
anyarray | -1 | m
anycompatible | 4 | i
anycompatiblearray | -1 | m
anycompatiblemultirange | -1 | m
anycompatiblenonarray | 4 | i
anycompatiblerange | -1 | m
anyelement | 4 | i
anyenum | 4 | i
anymultirange | -1 | m
anynonarray | 4 | i
anyrange | -1 | m
(12 rows)
(Previous to this patch, the 'm' entries were 'd'.)
In one sense this doesn't really matter, since no actual
value should have any of these types attributed to it;
but it annoys me that they're not all alike. I'm tempted to
make them all 4/'i' which seems to be the older convention.
A more aggressive answer would be to change these to some
actually-illegal values, in hopes of catching anyplace where
we did try to rely on the values. But that seems like
material for a different patch.
regards, tom lane
[1] https://www.postgresql.org/message-id/581905.1769550155%40sss.pgh.pa.us
From 4474db54e4c481c7a919062812b33ba2e703d626 Mon Sep 17 00:00:00 2001
From: Tom Lane
Date: Wed, 28 Jan 2026 19:54:46 -0500
Subject: [PATCH v1] Decouple our alignment assumptions about int64 and double.
Up to now we have assumed that int64 and double have the same
alignment requirement, but there are platforms on which that's
not true (notably AIX). This assumption is a bit of a wart anyway,
since it leads to confusion about which alignment setting to use.
Let's break that apart.
We actually need to split TYPALIGN_DOUBLE into three values not
two, because we need a representation for "the maximum alignment
on this platform"; composite types need to use that setting.
So this patch invents TYPALIGN_INT64 and TYPALIGN_MAX, and
propagates those into all the necessary places. It's pretty
straightforward really, though it's certainly possible I missed
a few places to change.
One of the concerns that prevented this from being done long
ago was not wanting to add overhead to tuple forming/deforming.
However that concern seems gone now, because we map TYPALIGN_xxx
values to numeric alignments in populate_compact_attribute()
which is not so performance-critical. It might be worth
worrying about the increased cost of att_align_nominal(),
but that macro is not that heavily used IMO.
An issue not resolved here is that we are not consistent
about the pg_type typlen/typalign values for polymorphic
types (the "any*" types). Those shouldn't actually matter,
but why aren't they all alike?
Side notes:
I got rid of LONGALIGN[_DOWN] along with the configure probes
for ALIGNOF_LONG. We were not using those anywhere and it
seems highly unlikely that we'd do so in future.
bootstrap.c turns out to have had the wrong alignment value
for _aclitem; seems that was missed when we widened AclMode
to 64 bits. AFAICT the value wasn't used so there were no
ill effects.
I fixed a couple of places that were using hard-coded values
when they could have used TYPALIGN_xxx macros.
This will require a catversion bump.
---
configure | 64 +++----------------
configure.ac | 30 +++------
doc/src/sgml/catalogs.sgml | 8 ++-
doc/src/sgml/ref/create_type.sgml | 9 ++-
meson.build | 31 ++++-----
src/backend/access/common/tupdesc.c | 8 ++-
src/backend/bootstrap/bootstrap.c | 4 +-
src/backend/catalog/Catalog.pm | 10 ++-
src/backend/catalog/heap.c | 4 +-
src/backend/catalog/pg_type.c | 9 ++-
src/backend/commands/typecmds.c | 38 +++++++++--
src/backend/tsearch/ts_typanalyze.c | 2 +-
src/backend/utils/adt/arrayfuncs.c | 2 +-
src/backend/utils/adt/orderedsetaggs.c | 2 +-
src/backend/utils/adt/rangetypes_typanalyze.c | 2 +-
src/bin/initdb/initdb.c | 2 +-
src/bin/pg_dump/pg_dump.c | 4 ++
src/include/access/tupmacs.h | 12 ++--
src/include/c.h | 4 +-
src/include/catalog/pg_type.dat | 62 +++++++++---------
src/include/catalog/pg_type.h | 2 +
src/include/pg_config.h.in | 3 -
src/pl/plpython/plpy_typeio.c | 4 +-
src/test/regress/expected/float8.out | 8 ++-
src/test/regress/expected/type_sanity.out | 8 ++-
src/test/regress/sql/float8.sql | 6 +-
src/test/regress/sql/type_sanity.sql | 8 ++-
27 files changed, 177 insertions(+), 169 deletions(-)
diff --git a/configure b/configure
index a10a2c85c6a..5adfb3eba45 100755
--- a/configure
+++ b/configure
@@ -17095,41 +17095,6 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
-# The cast to long int works around a bug in the HP C Compiler,
-# see AC_CHECK_SIZEOF for more information.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of long" >&5
-$as_echo_n "checking alignment of long... " >&6; }
-if ${ac_cv_alignof_long+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- if ac_fn_c_compute_int "$LINENO" "(long int) offsetof (ac__type_alignof_, y)" "ac_cv_alignof_long" "$ac_includes_default
-#ifndef offsetof
-# define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
-#endif
-typedef struct { char x; long y; } ac__type_alignof_;"; then :
-
-else
- if test "$ac_cv_type_long" = yes; then
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error 77 "cannot compute alignment of long
-See \`config.log' for more details" "$LINENO" 5; }
- else
- ac_cv_alignof_long=0
- fi
-fi
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_alignof_long" >&5
-$as_echo "$ac_cv_alignof_long" >&6; }
-
-
-
-cat >>confdefs.h <<_ACEOF
-#define ALIGNOF_LONG $ac_cv_alignof_long
-_ACEOF
-
-
# The cast to long int works around a bug in the HP C Compiler,
# see AC_CHECK_SIZEOF for more information.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of int64_t" >&5
@@ -17203,27 +17168,16 @@ _ACEOF
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that long's alignment is at least as strong as
-# char, short, or int. Note that we intentionally do not consider any types
-# wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
-# much of a penalty for disk and memory space.
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) Note that we intentionally do not consider any types wider
+# than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much
+# of a penalty for disk and memory space.
-MAX_ALIGNOF=$ac_cv_alignof_double
-
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
- as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
- as_fn_error $? "alignment of 'int64_t' is greater than the alignment of 'double'" "$LINENO" 5
+if test $ac_cv_alignof_int64_t -gt $ac_cv_alignof_double ; then
+ MAX_ALIGNOF=$ac_cv_alignof_int64_t
+else
+ MAX_ALIGNOF=$ac_cv_alignof_double
fi
cat >>confdefs.h <<_ACEOF
diff --git a/configure.ac b/configure.ac
index 814e64a967e..a5eab2e5fff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2031,33 +2031,21 @@ AC_CHECK_SIZEOF([intmax_t])
AC_CHECK_ALIGNOF(short)
AC_CHECK_ALIGNOF(int)
-AC_CHECK_ALIGNOF(long)
AC_CHECK_ALIGNOF(int64_t)
AC_CHECK_ALIGNOF(double)
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that long's alignment is at least as strong as
-# char, short, or int. Note that we intentionally do not consider any types
-# wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
-# much of a penalty for disk and memory space.
-
-MAX_ALIGNOF=$ac_cv_alignof_double
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) Note that we intentionally do not consider any types wider
+# than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much
+# of a penalty for disk and memory space.
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
- AC_MSG_ERROR([alignment of 'long' is greater than the alignment of 'double'])
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
- AC_MSG_ERROR([alignment of 'int64_t' is greater than the alignment of 'double'])
+if test $ac_cv_alignof_int64_t -gt $ac_cv_alignof_double ; then
+ MAX_ALIGNOF=$ac_cv_alignof_int64_t
+else
+ MAX_ALIGNOF=$ac_cv_alignof_double
fi
AC_DEFINE_UNQUOTED(MAXIMUM_ALIGNOF, $MAX_ALIGNOF, [Define as the maximum alignment requirement of any C data type.])
diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index 332193565e2..12608d00a18 100644
--- a/doc/src/sgml/catalogs.sgml
+++ b/doc/src/sgml/catalogs.sgml
@@ -9567,7 +9567,13 @@ SCRAM-SHA-256$<iteration count>:&l
i = int alignment (4 bytes on most machines).
- d = double alignment (8 bytes on many machines, but by no means all).
+ l = int64 alignment (8 bytes on most machines, but by no means all).
+
+
+ d = double alignment (8 bytes on most machines, but by no means all).
+
+
+ m = maximum alignment (8 bytes on most machines).
diff --git a/doc/src/sgml/ref/create_type.sgml b/doc/src/sgml/ref/create_type.sgml
index 994dfc65268..006db624094 100644
--- a/doc/src/sgml/ref/create_type.sgml
+++ b/doc/src/sgml/ref/create_type.sgml
@@ -748,8 +748,15 @@ CREATE TYPE name
The storage alignment requirement of the data type. If specified,
it must be char, int2,
- int4, or double; the
+ int4, int8,
+ double, or max; the
default is int4.
+ int8 and double usually
+ have the same behavior, but there are platforms on which they are
+ different because integer and floating-point values have different
+ requirements. max means the maximum alignment
+ requirement for any of these types; it is often used for container
+ types such as records.
diff --git a/meson.build b/meson.build
index df907b62da3..bb17859fee4 100644
--- a/meson.build
+++ b/meson.build
@@ -1798,32 +1798,27 @@ endif
# Determine memory alignment requirements for the basic C data types.
-alignof_types = ['short', 'int', 'long', 'double']
+alignof_types = ['short', 'int', 'int64_t', 'double']
foreach t : alignof_types
- align = cc.alignment(t, args: test_c_args)
+ align = cc.alignment(t, args: test_c_args, prefix: '#include ')
cdata.set('ALIGNOF_@0@'.format(t.to_upper()), align)
endforeach
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that int64_t's alignment is at least as strong
-# as long, char, short, or int. Note that we intentionally do not consider
-# any types wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8
-# would be too much of a penalty for disk and memory space.
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) Note that we intentionally do not consider any types wider
+# than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much
+# of a penalty for disk and memory space.
+
+alignof_int64_t = cdata.get('ALIGNOF_INT64_T')
alignof_double = cdata.get('ALIGNOF_DOUBLE')
-if cc.alignment('int64_t', args: test_c_args, prefix: '#include ') > alignof_double
- error('alignment of int64_t is greater than the alignment of double')
+if alignof_int64_t > alignof_double
+ cdata.set('MAXIMUM_ALIGNOF', alignof_int64_t)
+else
+ cdata.set('MAXIMUM_ALIGNOF', alignof_double)
endif
-cdata.set('MAXIMUM_ALIGNOF', alignof_double)
cdata.set('SIZEOF_LONG', cc.sizeof('long', args: test_c_args))
cdata.set('SIZEOF_LONG_LONG', cc.sizeof('long long', args: test_c_args))
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index 94b4f1f9975..49e5cd6c117 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -94,9 +94,15 @@ populate_compact_attribute_internal(Form_pg_attribute src,
case TYPALIGN_CHAR:
dst->attalignby = sizeof(char);
break;
+ case TYPALIGN_INT64:
+ dst->attalignby = ALIGNOF_INT64_T;
+ break;
case TYPALIGN_DOUBLE:
dst->attalignby = ALIGNOF_DOUBLE;
break;
+ case TYPALIGN_MAX:
+ dst->attalignby = MAXIMUM_ALIGNOF;
+ break;
case TYPALIGN_SHORT:
dst->attalignby = ALIGNOF_SHORT;
break;
@@ -994,7 +1000,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
case INT8OID:
att->attlen = 8;
att->attbyval = true;
- att->attalign = TYPALIGN_DOUBLE;
+ att->attalign = TYPALIGN_INT64;
att->attstorage = TYPSTORAGE_PLAIN;
att->attcompression = InvalidCompressionMethod;
att->attcollation = InvalidOid;
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index dd57624b4f9..7a3a13a6ec7 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -115,7 +115,7 @@ static const struct typinfo TypInfo[] = {
F_TEXTIN, F_TEXTOUT},
{"oid", OIDOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_OIDIN, F_OIDOUT},
- {"oid8", OID8OID, 0, 8, true, TYPALIGN_DOUBLE, TYPSTORAGE_PLAIN, InvalidOid,
+ {"oid8", OID8OID, 0, 8, true, TYPALIGN_INT64, TYPSTORAGE_PLAIN, InvalidOid,
F_OID8IN, F_OID8OUT},
{"tid", TIDOID, 0, 6, false, TYPALIGN_SHORT, TYPSTORAGE_PLAIN, InvalidOid,
F_TIDIN, F_TIDOUT},
@@ -137,7 +137,7 @@ static const struct typinfo TypInfo[] = {
F_ARRAY_IN, F_ARRAY_OUT},
{"_char", 1002, CHAROID, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
F_ARRAY_IN, F_ARRAY_OUT},
- {"_aclitem", 1034, ACLITEMOID, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
+ {"_aclitem", 1034, ACLITEMOID, -1, false, TYPALIGN_INT64, TYPSTORAGE_EXTENDED, InvalidOid,
F_ARRAY_IN, F_ARRAY_OUT}
};
diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm
index 219af5884d9..20884f45bd8 100644
--- a/src/backend/catalog/Catalog.pm
+++ b/src/backend/catalog/Catalog.pm
@@ -464,9 +464,13 @@ sub GenerateArrayTypes
$array_type{typname} = '_' . $elem_type->{typname};
$array_type{typelem} = $elem_type->{typname};
- # Arrays require INT alignment, unless the element type requires
- # DOUBLE alignment.
- $array_type{typalign} = $elem_type->{typalign} eq 'd' ? 'd' : 'i';
+ # Arrays require INT alignment, unless the element type requires more.
+ $array_type{typalign} =
+ $elem_type->{typalign} eq 'l' ? 'l'
+ : (
+ $elem_type->{typalign} eq 'd' ? 'd'
+ : ( $elem_type->{typalign} eq 'm' ? 'm'
+ : 'i'));
# Fill in the rest of the array entry's fields.
foreach my $column (@$pgtype_schema)
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 606434823cf..27cc09a7680 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1075,7 +1075,7 @@ AddNewRelationType(const char *typeName,
NULL, /* default value - none */
NULL, /* default binary representation */
false, /* passed by reference */
- TYPALIGN_DOUBLE, /* alignment - must be the largest! */
+ TYPALIGN_MAX, /* alignment - must be the largest! */
TYPSTORAGE_EXTENDED, /* fully TOASTable */
-1, /* typmod */
0, /* array dimensions for typBaseType */
@@ -1399,7 +1399,7 @@ heap_create_with_catalog(const char *relname,
NULL, /* default value - none */
NULL, /* default binary representation */
false, /* passed by reference */
- TYPALIGN_DOUBLE, /* alignment - must be the largest! */
+ TYPALIGN_MAX, /* alignment - must be the largest! */
TYPSTORAGE_EXTENDED, /* fully TOASTable */
-1, /* typmod */
0, /* array dimensions for typBaseType */
diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c
index fc369c35aa6..f079fa32b40 100644
--- a/src/backend/catalog/pg_type.c
+++ b/src/backend/catalog/pg_type.c
@@ -287,7 +287,9 @@ TypeCreate(Oid newTypeOid,
}
else if (internalSize == (int16) sizeof(int64))
{
- if (alignment != TYPALIGN_DOUBLE)
+ /* We have to trust the user to get this distinction right ... */
+ if (!(alignment == TYPALIGN_INT64 ||
+ alignment == TYPALIGN_DOUBLE))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("alignment \"%c\" is invalid for passed-by-value type of size %d",
@@ -303,7 +305,10 @@ TypeCreate(Oid newTypeOid,
{
/* varlena types must have int align or better */
if (internalSize == -1 &&
- !(alignment == TYPALIGN_INT || alignment == TYPALIGN_DOUBLE))
+ !(alignment == TYPALIGN_INT ||
+ alignment == TYPALIGN_INT64 ||
+ alignment == TYPALIGN_DOUBLE ||
+ alignment == TYPALIGN_MAX))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("alignment \"%c\" is invalid for variable-length type",
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 288edb25f2f..2f919f764aa 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -117,6 +117,7 @@ static void makeMultirangeConstructors(const char *name, Oid namespace,
Oid multirangeOid, Oid rangeOid,
Oid rangeArrayOid,
Oid *mltrngConstruct0_p, Oid *mltrngConstruct1_p, Oid *mltrngConstruct2_p);
+static char containerAlignment(char elemalign);
static Oid findTypeInputFunction(List *procname, Oid typeOid);
static Oid findTypeOutputFunction(List *procname, Oid typeOid);
static Oid findTypeReceiveFunction(List *procname, Oid typeOid);
@@ -424,6 +425,9 @@ DefineType(ParseState *pstate, List *names, List *parameters)
pg_strcasecmp(a, "float8") == 0 ||
pg_strcasecmp(a, "pg_catalog.float8") == 0)
alignment = TYPALIGN_DOUBLE;
+ else if (pg_strcasecmp(a, "int8") == 0 ||
+ pg_strcasecmp(a, "pg_catalog.int8") == 0)
+ alignment = TYPALIGN_INT64;
else if (pg_strcasecmp(a, "int4") == 0 ||
pg_strcasecmp(a, "pg_catalog.int4") == 0)
alignment = TYPALIGN_INT;
@@ -433,6 +437,9 @@ DefineType(ParseState *pstate, List *names, List *parameters)
else if (pg_strcasecmp(a, "char") == 0 ||
pg_strcasecmp(a, "pg_catalog.bpchar") == 0)
alignment = TYPALIGN_CHAR;
+ else if (pg_strcasecmp(a, "max") == 0 ||
+ pg_strcasecmp(a, "pg_catalog.max") == 0)
+ alignment = TYPALIGN_MAX;
else
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -611,8 +618,8 @@ DefineType(ParseState *pstate, List *names, List *parameters)
*/
array_type = makeArrayTypeName(typeName, typeNamespace);
- /* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for arrays */
- alignment = (alignment == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
+ /* alignment must be TYPALIGN_INT or more for arrays */
+ alignment = containerAlignment(alignment);
TypeCreate(array_oid, /* force assignment of this type OID */
array_type, /* type name */
@@ -1095,8 +1102,8 @@ DefineDomain(ParseState *pstate, CreateDomainStmt *stmt)
*/
domainArrayName = makeArrayTypeName(domainName, domainNamespace);
- /* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for arrays */
- alignment = (alignment == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
+ /* alignment must be TYPALIGN_INT or more for arrays */
+ alignment = containerAlignment(alignment);
TypeCreate(domainArrayOid, /* force assignment of this type OID */
domainArrayName, /* type name */
@@ -1557,8 +1564,8 @@ DefineRange(ParseState *pstate, CreateRangeStmt *stmt)
get_typlenbyvalalign(rangeSubtype,
&subtyplen, &subtypbyval, &subtypalign);
- /* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for ranges */
- alignment = (subtypalign == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
+ /* alignment must be TYPALIGN_INT or more for ranges */
+ alignment = containerAlignment(subtypalign);
/* Allocate OID for array type, its multirange, and its multirange array */
rangeArrayOid = AssignTypeArrayOid();
@@ -2005,6 +2012,25 @@ makeMultirangeConstructors(const char *name, Oid namespace,
pfree(parameterModes);
}
+/*
+ * Compute the appropriate typalign for a container (array or range)
+ * given the typalign of its members. The container type requires at
+ * least int alignment, but more if the members need more.
+ */
+static char
+containerAlignment(char elemalign)
+{
+ switch (elemalign)
+ {
+ case TYPALIGN_INT64:
+ case TYPALIGN_DOUBLE:
+ case TYPALIGN_MAX:
+ return elemalign;
+ default:
+ return TYPALIGN_INT;
+ }
+}
+
/*
* Find suitable I/O and other support functions for a type.
*
diff --git a/src/backend/tsearch/ts_typanalyze.c b/src/backend/tsearch/ts_typanalyze.c
index 0c513d694e7..48ee050e37f 100644
--- a/src/backend/tsearch/ts_typanalyze.c
+++ b/src/backend/tsearch/ts_typanalyze.c
@@ -444,7 +444,7 @@ compute_tsvector_stats(VacAttrStats *stats,
stats->statypid[0] = TEXTOID;
stats->statyplen[0] = -1; /* typlen, -1 for varlena */
stats->statypbyval[0] = false;
- stats->statypalign[0] = 'i';
+ stats->statypalign[0] = TYPALIGN_INT;
}
}
else
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index e71d32773b5..0d185f5be8a 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -3426,7 +3426,7 @@ construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
case INT8OID:
elmlen = sizeof(int64);
elmbyval = true;
- elmalign = TYPALIGN_DOUBLE;
+ elmalign = TYPALIGN_INT64;
break;
case NAMEOID:
diff --git a/src/backend/utils/adt/orderedsetaggs.c b/src/backend/utils/adt/orderedsetaggs.c
index 3b6da8e36ac..27b8cfa7064 100644
--- a/src/backend/utils/adt/orderedsetaggs.c
+++ b/src/backend/utils/adt/orderedsetaggs.c
@@ -1021,7 +1021,7 @@ percentile_cont_interval_multi_final(PG_FUNCTION_ARGS)
return percentile_cont_multi_final_common(fcinfo,
INTERVALOID,
/* hard-wired info on type interval */
- 16, false, TYPALIGN_DOUBLE,
+ 16, false, TYPALIGN_INT64,
interval_lerp);
}
diff --git a/src/backend/utils/adt/rangetypes_typanalyze.c b/src/backend/utils/adt/rangetypes_typanalyze.c
index 38d12dedbc5..278d4e6941a 100644
--- a/src/backend/utils/adt/rangetypes_typanalyze.c
+++ b/src/backend/utils/adt/rangetypes_typanalyze.c
@@ -398,7 +398,7 @@ compute_range_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
stats->statypid[slot_idx] = FLOAT8OID;
stats->statyplen[slot_idx] = sizeof(float8);
stats->statypbyval[slot_idx] = true;
- stats->statypalign[slot_idx] = 'd';
+ stats->statypalign[slot_idx] = TYPALIGN_DOUBLE;
/* Store the fraction of empty ranges */
emptyfrac = palloc_object(float4);
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index a3980e5535f..e550e9cf0a3 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -1580,7 +1580,7 @@ bootstrap_template1(void)
bki_lines = replace_token(bki_lines, "SIZEOF_POINTER", buf);
bki_lines = replace_token(bki_lines, "ALIGNOF_POINTER",
- (sizeof(Pointer) == 4) ? "i" : "d");
+ (sizeof(Pointer) == 4) ? "i" : "l");
bki_lines = replace_token(bki_lines, "POSTGRES",
escape_quotes_bki(username));
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 078ee8500ad..b94121ceb32 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -12652,8 +12652,12 @@ dumpBaseType(Archive *fout, const TypeInfo *tyinfo)
appendPQExpBufferStr(q, ",\n ALIGNMENT = int2");
else if (*typalign == TYPALIGN_INT)
appendPQExpBufferStr(q, ",\n ALIGNMENT = int4");
+ else if (*typalign == TYPALIGN_INT64)
+ appendPQExpBufferStr(q, ",\n ALIGNMENT = int8");
else if (*typalign == TYPALIGN_DOUBLE)
appendPQExpBufferStr(q, ",\n ALIGNMENT = double");
+ else if (*typalign == TYPALIGN_MAX)
+ appendPQExpBufferStr(q, ",\n ALIGNMENT = max");
if (*typstorage == TYPSTORAGE_PLAIN)
appendPQExpBufferStr(q, ",\n STORAGE = plain");
diff --git a/src/include/access/tupmacs.h b/src/include/access/tupmacs.h
index 3e5530658c9..c5462d6fba1 100644
--- a/src/include/access/tupmacs.h
+++ b/src/include/access/tupmacs.h
@@ -146,11 +146,13 @@ fetch_att(const void *T, bool attbyval, int attlen)
( \
((attalign) == TYPALIGN_INT) ? INTALIGN(cur_offset) : \
(((attalign) == TYPALIGN_CHAR) ? (uintptr_t) (cur_offset) : \
- (((attalign) == TYPALIGN_DOUBLE) ? DOUBLEALIGN(cur_offset) : \
- ( \
- AssertMacro((attalign) == TYPALIGN_SHORT), \
- SHORTALIGN(cur_offset) \
- ))) \
+ (((attalign) == TYPALIGN_INT64) ? INT64ALIGN(cur_offset) : \
+ (((attalign) == TYPALIGN_DOUBLE) ? DOUBLEALIGN(cur_offset) : \
+ (((attalign) == TYPALIGN_MAX) ? MAXALIGN(cur_offset) : \
+ ( \
+ AssertMacro((attalign) == TYPALIGN_SHORT), \
+ SHORTALIGN(cur_offset) \
+ ))))) \
)
/*
diff --git a/src/include/c.h b/src/include/c.h
index 48e4087c09c..f802633bde4 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -821,7 +821,7 @@ typedef NameData *Name;
#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
-#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
+#define INT64ALIGN(LEN) TYPEALIGN(ALIGNOF_INT64_T, (LEN))
#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
/* MAXALIGN covers only built-in types, not buffers */
@@ -833,7 +833,7 @@ typedef NameData *Name;
#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
-#define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN))
+#define INT64ALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT64_T, (LEN))
#define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
#define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
#define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_BUFFER, (LEN))
diff --git a/src/include/catalog/pg_type.dat b/src/include/catalog/pg_type.dat
index a1a753d1797..d511493f761 100644
--- a/src/include/catalog/pg_type.dat
+++ b/src/include/catalog/pg_type.dat
@@ -56,7 +56,7 @@
descr => '~18 digit integer, 8-byte storage',
typname => 'int8', typlen => '8', typbyval => 't',
typcategory => 'N', typinput => 'int8in', typoutput => 'int8out',
- typreceive => 'int8recv', typsend => 'int8send', typalign => 'd' },
+ typreceive => 'int8recv', typsend => 'int8send', typalign => 'l' },
{ oid => '21', array_type_oid => '1005',
descr => '-32 thousand to 32 thousand, 2-byte storage',
typname => 'int2', typlen => '2', typbyval => 't', typcategory => 'N',
@@ -116,22 +116,22 @@
typname => 'pg_type', typlen => '-1', typbyval => 'f', typtype => 'c',
typcategory => 'C', typrelid => 'pg_type', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
{ oid => '75', array_type_oid => '270',
typname => 'pg_attribute', typlen => '-1', typbyval => 'f', typtype => 'c',
typcategory => 'C', typrelid => 'pg_attribute', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
{ oid => '81', array_type_oid => '272',
typname => 'pg_proc', typlen => '-1', typbyval => 'f', typtype => 'c',
typcategory => 'C', typrelid => 'pg_proc', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
{ oid => '83', array_type_oid => '273',
typname => 'pg_class', typlen => '-1', typbyval => 'f', typtype => 'c',
typcategory => 'C', typrelid => 'pg_class', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
# OIDS 100 - 199
@@ -174,7 +174,7 @@
{ oid => '5069', array_type_oid => '271', descr => 'full transaction id',
typname => 'xid8', typlen => '8', typbyval => 't',
typcategory => 'U', typinput => 'xid8in', typoutput => 'xid8out',
- typreceive => 'xid8recv', typsend => 'xid8send', typalign => 'd' },
+ typreceive => 'xid8recv', typsend => 'xid8send', typalign => 'l' },
# OIDS 600 - 699
@@ -239,7 +239,7 @@
descr => 'monetary amounts, $d,ddd.cc',
typname => 'money', typlen => '8', typbyval => 't',
typcategory => 'N', typinput => 'cash_in', typoutput => 'cash_out',
- typreceive => 'cash_recv', typsend => 'cash_send', typalign => 'd' },
+ typreceive => 'cash_recv', typsend => 'cash_send', typalign => 'l' },
# OIDS 800 - 899
@@ -270,7 +270,7 @@
{ oid => '1033', array_type_oid => '1034', descr => 'access control list',
typname => 'aclitem', typlen => '16', typbyval => 'f', typcategory => 'U',
typinput => 'aclitemin', typoutput => 'aclitemout', typreceive => '-',
- typsend => '-', typalign => 'd' },
+ typsend => '-', typalign => 'l' },
{ oid => '1042', array_type_oid => '1014',
descr => '\'char(length)\' blank-padded string, fixed storage length',
typname => 'bpchar', typlen => '-1', typbyval => 'f', typcategory => 'S',
@@ -293,7 +293,7 @@
typname => 'time', typlen => '8', typbyval => 't',
typcategory => 'D', typinput => 'time_in', typoutput => 'time_out',
typreceive => 'time_recv', typsend => 'time_send', typmodin => 'timetypmodin',
- typmodout => 'timetypmodout', typalign => 'd' },
+ typmodout => 'timetypmodout', typalign => 'l' },
# OIDS 1100 - 1199
@@ -302,21 +302,21 @@
typcategory => 'D', typinput => 'timestamp_in', typoutput => 'timestamp_out',
typreceive => 'timestamp_recv', typsend => 'timestamp_send',
typmodin => 'timestamptypmodin', typmodout => 'timestamptypmodout',
- typalign => 'd' },
+ typalign => 'l' },
{ oid => '1184', array_type_oid => '1185',
descr => 'date and time with time zone',
typname => 'timestamptz', typlen => '8', typbyval => 't',
typcategory => 'D', typispreferred => 't', typinput => 'timestamptz_in',
typoutput => 'timestamptz_out', typreceive => 'timestamptz_recv',
typsend => 'timestamptz_send', typmodin => 'timestamptztypmodin',
- typmodout => 'timestamptztypmodout', typalign => 'd' },
+ typmodout => 'timestamptztypmodout', typalign => 'l' },
{ oid => '1186', array_type_oid => '1187',
descr => 'time interval, format \'number units ...\'',
typname => 'interval', typlen => '16', typbyval => 'f', typcategory => 'T',
typispreferred => 't', typinput => 'interval_in', typoutput => 'interval_out',
typreceive => 'interval_recv', typsend => 'interval_send',
typmodin => 'intervaltypmodin', typmodout => 'intervaltypmodout',
- typalign => 'd' },
+ typalign => 'l' },
# OIDS 1200 - 1299
@@ -326,7 +326,7 @@
typinput => 'timetz_in', typoutput => 'timetz_out',
typreceive => 'timetz_recv', typsend => 'timetz_send',
typmodin => 'timetztypmodin', typmodout => 'timetztypmodout',
- typalign => 'd' },
+ typalign => 'l' },
# OIDS 1500 - 1599
@@ -415,7 +415,7 @@
{ oid => '3220', array_type_oid => '3221', descr => 'PostgreSQL LSN',
typname => 'pg_lsn', typlen => '8', typbyval => 't',
typcategory => 'U', typinput => 'pg_lsn_in', typoutput => 'pg_lsn_out',
- typreceive => 'pg_lsn_recv', typsend => 'pg_lsn_send', typalign => 'd' },
+ typreceive => 'pg_lsn_recv', typsend => 'pg_lsn_send', typalign => 'l' },
# text search
{ oid => '3614', array_type_oid => '3643',
@@ -462,12 +462,12 @@
typname => 'txid_snapshot', typlen => '-1', typbyval => 'f',
typcategory => 'U', typinput => 'txid_snapshot_in',
typoutput => 'txid_snapshot_out', typreceive => 'txid_snapshot_recv',
- typsend => 'txid_snapshot_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'txid_snapshot_send', typalign => 'l', typstorage => 'x' },
{ oid => '5038', array_type_oid => '5039', descr => 'transaction snapshot',
typname => 'pg_snapshot', typlen => '-1', typbyval => 'f', typcategory => 'U',
typinput => 'pg_snapshot_in', typoutput => 'pg_snapshot_out',
typreceive => 'pg_snapshot_recv', typsend => 'pg_snapshot_send',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'l', typstorage => 'x' },
# range types
{ oid => '3904', array_type_oid => '3905', descr => 'range of integers',
@@ -485,13 +485,13 @@
typname => 'tsrange', typlen => '-1', typbyval => 'f', typtype => 'r',
typcategory => 'R', typinput => 'range_in', typoutput => 'range_out',
typreceive => 'range_recv', typsend => 'range_send',
- typanalyze => 'range_typanalyze', typalign => 'd', typstorage => 'x' },
+ typanalyze => 'range_typanalyze', typalign => 'l', typstorage => 'x' },
{ oid => '3910', array_type_oid => '3911',
descr => 'range of timestamps with time zone',
typname => 'tstzrange', typlen => '-1', typbyval => 'f', typtype => 'r',
typcategory => 'R', typinput => 'range_in', typoutput => 'range_out',
typreceive => 'range_recv', typsend => 'range_send',
- typanalyze => 'range_typanalyze', typalign => 'd', typstorage => 'x' },
+ typanalyze => 'range_typanalyze', typalign => 'l', typstorage => 'x' },
{ oid => '3912', array_type_oid => '3913', descr => 'range of dates',
typname => 'daterange', typlen => '-1', typbyval => 'f', typtype => 'r',
typcategory => 'R', typinput => 'range_in', typoutput => 'range_out',
@@ -501,7 +501,7 @@
typname => 'int8range', typlen => '-1', typbyval => 'f', typtype => 'r',
typcategory => 'R', typinput => 'range_in', typoutput => 'range_out',
typreceive => 'range_recv', typsend => 'range_send',
- typanalyze => 'range_typanalyze', typalign => 'd', typstorage => 'x' },
+ typanalyze => 'range_typanalyze', typalign => 'l', typstorage => 'x' },
# multirange types
{ oid => '4451', array_type_oid => '6150', descr => 'multirange of integers',
@@ -522,14 +522,14 @@
typcategory => 'R', typinput => 'multirange_in',
typoutput => 'multirange_out', typreceive => 'multirange_recv',
typsend => 'multirange_send', typanalyze => 'multirange_typanalyze',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'l', typstorage => 'x' },
{ oid => '4534', array_type_oid => '6153',
descr => 'multirange of timestamps with time zone',
typname => 'tstzmultirange', typlen => '-1', typbyval => 'f', typtype => 'm',
typcategory => 'R', typinput => 'multirange_in',
typoutput => 'multirange_out', typreceive => 'multirange_recv',
typsend => 'multirange_send', typanalyze => 'multirange_typanalyze',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'l', typstorage => 'x' },
{ oid => '4535', array_type_oid => '6155', descr => 'multirange of dates',
typname => 'datemultirange', typlen => '-1', typbyval => 'f', typtype => 'm',
typcategory => 'R', typinput => 'multirange_in',
@@ -541,7 +541,7 @@
typcategory => 'R', typinput => 'multirange_in',
typoutput => 'multirange_out', typreceive => 'multirange_recv',
typsend => 'multirange_send', typanalyze => 'multirange_typanalyze',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'l', typstorage => 'x' },
# pseudo-types
# types with typtype='p' represent various special cases in the type system.
@@ -556,14 +556,14 @@
typname => 'record', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typarray => '_record', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
# Arrays of records have typcategory P, so they can't be autogenerated.
{ oid => '2287',
typname => '_record', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typsubscript => 'array_subscript_handler',
typelem => 'record', typinput => 'array_in', typoutput => 'array_out',
typreceive => 'array_recv', typsend => 'array_send',
- typanalyze => 'array_typanalyze', typalign => 'd', typstorage => 'x' },
+ typanalyze => 'array_typanalyze', typalign => 'm', typstorage => 'x' },
{ oid => '2275', array_type_oid => '1263', descr => 'C-style string',
typname => 'cstring', typlen => '-2', typbyval => 'f', typtype => 'p',
typcategory => 'P', typinput => 'cstring_in', typoutput => 'cstring_out',
@@ -575,7 +575,7 @@
{ oid => '2277', descr => 'pseudo-type representing a polymorphic array type',
typname => 'anyarray', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typinput => 'anyarray_in', typoutput => 'anyarray_out',
- typreceive => 'anyarray_recv', typsend => 'anyarray_send', typalign => 'd',
+ typreceive => 'anyarray_recv', typsend => 'anyarray_send', typalign => 'm',
typstorage => 'x' },
{ oid => '2278',
descr => 'pseudo-type for the result of a function with no real result',
@@ -648,7 +648,7 @@
descr => 'pseudo-type representing a range over a polymorphic base type',
typname => 'anyrange', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typinput => 'anyrange_in', typoutput => 'anyrange_out',
- typreceive => '-', typsend => '-', typalign => 'd', typstorage => 'x' },
+ typreceive => '-', typsend => '-', typalign => 'm', typstorage => 'x' },
{ oid => '5077',
descr => 'pseudo-type representing a polymorphic common type',
typname => 'anycompatible', typlen => '4', typbyval => 't', typtype => 'p',
@@ -661,7 +661,7 @@
typtype => 'p', typcategory => 'P', typinput => 'anycompatiblearray_in',
typoutput => 'anycompatiblearray_out',
typreceive => 'anycompatiblearray_recv', typsend => 'anycompatiblearray_send',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'm', typstorage => 'x' },
{ oid => '5079',
descr => 'pseudo-type representing a polymorphic common type that is not an array',
typname => 'anycompatiblenonarray', typlen => '4', typbyval => 't',
@@ -673,19 +673,19 @@
typname => 'anycompatiblerange', typlen => '-1', typbyval => 'f',
typtype => 'p', typcategory => 'P', typinput => 'anycompatiblerange_in',
typoutput => 'anycompatiblerange_out', typreceive => '-', typsend => '-',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'm', typstorage => 'x' },
{ oid => '4537',
descr => 'pseudo-type representing a polymorphic base type that is a multirange',
typname => 'anymultirange', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typinput => 'anymultirange_in',
typoutput => 'anymultirange_out', typreceive => '-', typsend => '-',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'm', typstorage => 'x' },
{ oid => '4538',
descr => 'pseudo-type representing a multirange over a polymorphic common type',
typname => 'anycompatiblemultirange', typlen => '-1', typbyval => 'f',
typtype => 'p', typcategory => 'P', typinput => 'anycompatiblemultirange_in',
typoutput => 'anycompatiblemultirange_out', typreceive => '-', typsend => '-',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'm', typstorage => 'x' },
{ oid => '4600', descr => 'pseudo-type representing BRIN bloom summary',
typname => 'pg_brin_bloom_summary', typlen => '-1', typbyval => 'f',
typcategory => 'Z', typinput => 'brin_bloom_summary_in',
@@ -704,5 +704,5 @@
descr => 'object identifier(oid8), 8 bytes',
typname => 'oid8', typlen => '8', typbyval => 't', typcategory => 'N',
typinput => 'oid8in', typoutput => 'oid8out', typreceive => 'oid8recv',
- typsend => 'oid8send', typalign => 'd' },
+ typsend => 'oid8send', typalign => 'l' },
]
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 70d4a20c02b..b749a47d651 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -302,7 +302,9 @@ MAKE_SYSCACHE(TYPENAMENSP, pg_type_typname_nsp_index, 64);
#define TYPALIGN_CHAR 'c' /* char alignment (i.e. unaligned) */
#define TYPALIGN_SHORT 's' /* short alignment (typically 2 bytes) */
#define TYPALIGN_INT 'i' /* int alignment (typically 4 bytes) */
+#define TYPALIGN_INT64 'l' /* int64 alignment (often 8 bytes) */
#define TYPALIGN_DOUBLE 'd' /* double alignment (often 8 bytes) */
+#define TYPALIGN_MAX 'm' /* maximum alignment (usually 8 bytes) */
#define TYPSTORAGE_PLAIN 'p' /* type not prepared for toasting */
#define TYPSTORAGE_EXTERNAL 'e' /* toastable, don't try to compress */
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 339268dc8ef..5699c033ade 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -12,9 +12,6 @@
/* The normal alignment of `int64_t', in bytes. */
#undef ALIGNOF_INT64_T
-/* The normal alignment of `long', in bytes. */
-#undef ALIGNOF_LONG
-
/* The normal alignment of `PG_INT128_TYPE', in bytes. */
#undef ALIGNOF_PG_INT128_TYPE
diff --git a/src/pl/plpython/plpy_typeio.c b/src/pl/plpython/plpy_typeio.c
index 1f69109b081..91e40327788 100644
--- a/src/pl/plpython/plpy_typeio.c
+++ b/src/pl/plpython/plpy_typeio.c
@@ -329,7 +329,7 @@ PLy_output_setup_func(PLyObToDatum *arg, MemoryContext arg_mcxt,
/* hard-wired knowledge about type RECORD: */
arg->typbyval = false;
arg->typlen = -1;
- arg->typalign = TYPALIGN_DOUBLE;
+ arg->typalign = TYPALIGN_MAX;
}
/*
@@ -452,7 +452,7 @@ PLy_input_setup_func(PLyDatumToOb *arg, MemoryContext arg_mcxt,
/* hard-wired knowledge about type RECORD: */
arg->typbyval = false;
arg->typlen = -1;
- arg->typalign = TYPALIGN_DOUBLE;
+ arg->typalign = TYPALIGN_MAX;
}
/*
diff --git a/src/test/regress/expected/float8.out b/src/test/regress/expected/float8.out
index 9c519f1a1a1..a688cbc3c83 100644
--- a/src/test/regress/expected/float8.out
+++ b/src/test/regress/expected/float8.out
@@ -1088,8 +1088,10 @@ LINE 1: ...8 (input = xfloat8in, output = xfloat8out, like = no_such_ty...
create type xfloat8 (input = xfloat8in, output = xfloat8out, like = float8);
create cast (xfloat8 as float8) without function;
create cast (float8 as xfloat8) without function;
-create cast (xfloat8 as bigint) without function;
-create cast (bigint as xfloat8) without function;
+-- this hack depends on bigint and float8 having the same pass-by-value-ness:
+create function bigint_xfloat8(bigint) returns xfloat8 immutable strict
+ language internal as 'int8up';
+create cast (bigint as xfloat8) with function bigint_xfloat8(bigint);
-- float8: seeeeeee eeeeeeee eeeeeeee mmmmmmmm mmmmmmmm(x4)
-- we don't care to assume the platform's strtod() handles subnormals
-- correctly; those are "use at your own risk". However we do test
@@ -1503,5 +1505,5 @@ DETAIL: drop cascades to function xfloat8in(cstring)
drop cascades to function xfloat8out(xfloat8)
drop cascades to cast from xfloat8 to double precision
drop cascades to cast from double precision to xfloat8
-drop cascades to cast from xfloat8 to bigint
+drop cascades to function bigint_xfloat8(bigint)
drop cascades to cast from bigint to xfloat8
diff --git a/src/test/regress/expected/type_sanity.out b/src/test/regress/expected/type_sanity.out
index 1d21d3eb446..936fa36a600 100644
--- a/src/test/regress/expected/type_sanity.out
+++ b/src/test/regress/expected/type_sanity.out
@@ -23,7 +23,7 @@ WHERE t1.typnamespace = 0 OR
(t1.typlen <= 0 AND t1.typlen != -1 AND t1.typlen != -2) OR
(t1.typtype not in ('b', 'c', 'd', 'e', 'm', 'p', 'r')) OR
NOT t1.typisdefined OR
- (t1.typalign not in ('c', 's', 'i', 'd')) OR
+ (t1.typalign not in ('c', 's', 'i', 'l', 'd', 'm')) OR
(t1.typstorage not in ('p', 'x', 'e', 'm'));
oid | typname
-----+---------
@@ -36,7 +36,7 @@ WHERE t1.typbyval AND
(t1.typlen != 1 OR t1.typalign != 'c') AND
(t1.typlen != 2 OR t1.typalign != 's') AND
(t1.typlen != 4 OR t1.typalign != 'i') AND
- (t1.typlen != 8 OR t1.typalign != 'd');
+ (t1.typlen != 8 OR (t1.typalign != 'l' AND t1.typalign != 'd'));
oid | typname
-----+---------
(0 rows)
@@ -108,6 +108,8 @@ FROM pg_type as t1
LEFT JOIN pg_type as t2 ON rngsubtype = t2.oid
WHERE t1.typtype = 'r' AND
(t1.typalign != (CASE WHEN t2.typalign = 'd' THEN 'd'::"char"
+ WHEN t2.typalign = 'l' THEN 'l'::"char"
+ WHEN t2.typalign = 'm' THEN 'm'::"char"
ELSE 'i'::"char" END)
OR t2.oid IS NULL);
oid | typname | typalign | typname | typalign
@@ -423,6 +425,8 @@ SELECT t1.oid, t1.typname, t1.typalign, t2.typname, t2.typalign
FROM pg_type AS t1, pg_type AS t2
WHERE t1.typarray = t2.oid AND
t2.typalign != (CASE WHEN t1.typalign = 'd' THEN 'd'::"char"
+ WHEN t1.typalign = 'l' THEN 'l'::"char"
+ WHEN t1.typalign = 'm' THEN 'm'::"char"
ELSE 'i'::"char" END);
oid | typname | typalign | typname | typalign
-----+---------+----------+---------+----------
diff --git a/src/test/regress/sql/float8.sql b/src/test/regress/sql/float8.sql
index 0ef271f2702..c6b59a322ab 100644
--- a/src/test/regress/sql/float8.sql
+++ b/src/test/regress/sql/float8.sql
@@ -355,8 +355,10 @@ create type xfloat8 (input = xfloat8in, output = xfloat8out, like = no_such_type
create type xfloat8 (input = xfloat8in, output = xfloat8out, like = float8);
create cast (xfloat8 as float8) without function;
create cast (float8 as xfloat8) without function;
-create cast (xfloat8 as bigint) without function;
-create cast (bigint as xfloat8) without function;
+-- this hack depends on bigint and float8 having the same pass-by-value-ness:
+create function bigint_xfloat8(bigint) returns xfloat8 immutable strict
+ language internal as 'int8up';
+create cast (bigint as xfloat8) with function bigint_xfloat8(bigint);
-- float8: seeeeeee eeeeeeee eeeeeeee mmmmmmmm mmmmmmmm(x4)
diff --git a/src/test/regress/sql/type_sanity.sql b/src/test/regress/sql/type_sanity.sql
index 95d5b6e0915..625305c42bc 100644
--- a/src/test/regress/sql/type_sanity.sql
+++ b/src/test/regress/sql/type_sanity.sql
@@ -28,7 +28,7 @@ WHERE t1.typnamespace = 0 OR
(t1.typlen <= 0 AND t1.typlen != -1 AND t1.typlen != -2) OR
(t1.typtype not in ('b', 'c', 'd', 'e', 'm', 'p', 'r')) OR
NOT t1.typisdefined OR
- (t1.typalign not in ('c', 's', 'i', 'd')) OR
+ (t1.typalign not in ('c', 's', 'i', 'l', 'd', 'm')) OR
(t1.typstorage not in ('p', 'x', 'e', 'm'));
-- Look for "pass by value" types that can't be passed by value.
@@ -39,7 +39,7 @@ WHERE t1.typbyval AND
(t1.typlen != 1 OR t1.typalign != 'c') AND
(t1.typlen != 2 OR t1.typalign != 's') AND
(t1.typlen != 4 OR t1.typalign != 'i') AND
- (t1.typlen != 8 OR t1.typalign != 'd');
+ (t1.typlen != 8 OR (t1.typalign != 'l' AND t1.typalign != 'd'));
-- Look for "toastable" types that aren't varlena.
@@ -90,6 +90,8 @@ FROM pg_type as t1
LEFT JOIN pg_type as t2 ON rngsubtype = t2.oid
WHERE t1.typtype = 'r' AND
(t1.typalign != (CASE WHEN t2.typalign = 'd' THEN 'd'::"char"
+ WHEN t2.typalign = 'l' THEN 'l'::"char"
+ WHEN t2.typalign = 'm' THEN 'm'::"char"
ELSE 'i'::"char" END)
OR t2.oid IS NULL);
@@ -302,6 +304,8 @@ SELECT t1.oid, t1.typname, t1.typalign, t2.typname, t2.typalign
FROM pg_type AS t1, pg_type AS t2
WHERE t1.typarray = t2.oid AND
t2.typalign != (CASE WHEN t1.typalign = 'd' THEN 'd'::"char"
+ WHEN t1.typalign = 'l' THEN 'l'::"char"
+ WHEN t1.typalign = 'm' THEN 'm'::"char"
ELSE 'i'::"char" END);
-- Check for typelem set without a handler
--
2.43.7
Re: Decoupling our alignment assumptions about int64 and double
От:
Andres Freund <andres@anarazel.de>
Дата:
Hi, Thanks for the patch. Looks like a decent improvement. On 2026-01-28 20:20:24 -0500, Tom Lane wrote: > One of the concerns that prevented this from being done long > ago was not wanting to add overhead to tuple forming/deforming. > However that concern seems gone now, because we map TYPALIGN_xxx > values to numeric alignments in populate_compact_attribute() > which is not so performance-critical. It might be worth > worrying about the increased cost of att_align_nominal(), > but that macro is not that heavily used IMO. Yea, it shouldn't matter too much these days. We might want to verify that the array code isn't overly affected, e.g. array_iter_next() was deemed perf critical enough by someone to make it an inline function. I don't know if the compiler is somehow smart enough to move the conditionals outside of a loop over array_iter_next(). Perhaps we should make att_align_nominal() first determine the numerical alignment value and then have it use TYPEALIGN()? I think that'd be more likely to be pulled out of loops by the compile. Perhaps it's time to reformat att_align_nominal() into an static inline? It's pretty hard to read. I don't love the 'l' for TYPALIGN_INT64, but I guess I don't really have a better suggestion. It wouldn't hurt to have a short SQL level test for creating a type with int8 & max alignments. Greetings, Andres Freund
Re: Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Andres Freund writes: > Thanks for the patch. Looks like a decent improvement. Thanks for looking! > On 2026-01-28 20:20:24 -0500, Tom Lane wrote: >> ... It might be worth >> worrying about the increased cost of att_align_nominal(), >> but that macro is not that heavily used IMO. > Perhaps we should make att_align_nominal() first determine the numerical > alignment value and then have it use TYPEALIGN()? I think that'd be more > likely to be pulled out of loops by the compile. Yeah, I was thinking about actually breaking that into two source-code steps, a function to map TYPALIGN_xxx to numeric alignment and then a replacement for att_align_nominal that takes a numeric alignment. If you think it's worth worrying about I'm happy to do that. > Perhaps it's time to reformat att_align_nominal() into an static inline? It's > pretty hard to read. +1, I was not revisiting any of that for this draft, but if we're going to refactor it then an inline function seems good. > I don't love the 'l' for TYPALIGN_INT64, but I guess I don't really have a > better suggestion. Of course I was thinking 'l' for "long", but I agree it's not great typographically. One idea is 'L' not 'l', but that gives up consistency for visual separation. Any other ideas out there? > It wouldn't hurt to have a short SQL level test for creating a type with int8 > & max alignments. hmm ... yeah, I guess those code paths might not be covered already. regards, tom lane
Re: Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Here's a v2 responding to your suggestions. 0001 refactors
att_align_nominal(), and then 0002 is nearly the same as the
prior patch except for rebasing over that change. I added
a test case for alignment = max too (the other cases seem
covered already, somewhat indirectly via pg_upgrade testing).
I think this might be about ready to go, unless somebody has
a better idea than 'l' for the catalog representation of
TYPALIGN_INT64.
regards, tom lane
From 7b2949390ab32ec4d3c77dc1c1e239325bd3ec58 Mon Sep 17 00:00:00 2001
From: Tom Lane
Date: Thu, 29 Jan 2026 18:34:26 -0500
Subject: [PATCH v2 1/2] Refactor att_align_nominal() to improve performance.
Separate att_align_nominal() into two macros, similarly to what
was already done with att_align_datum() and att_align_pointer().
The inner macro att_nominal_alignby() is really just TYPEALIGN(),
while att_align_nominal() retains its previous API by mapping
TYPALIGN_xxx values to numbers of bytes to align to and then
calling att_nominal_alignby(). In support of this, split out
tupdesc.c's logic to do that mapping into a publicly visible
function typalign_to_alignby().
Having done that, we can replace performance-critical uses of
att_align_nominal() with att_nominal_alignby(), where the
typalign_to_alignby() mapping is done just once outside the loop.
In most places I settled for doing typalign_to_alignby() once
per function. We could in many places pass the alignby value
in from the caller if we wanted to change function APIs for this
purpose; but I'm a bit loath to do that, especially for exported
APIs that extensions might call. Replacing a char typalign
argument by a uint8 typalignby argument would be an API change
that compilers would fail to warn about, thus silently breaking
code in hard-to-debug ways. I did revise the APIs of array_iter_setup
and array_iter_next, moving the element type attribute arguments to
the former; if any external code uses those, the argument-count
change will cause visible compile failures.
I've not bothered to try to measure the actual performance benefit
from doing this; it may not be measurable on normal workloads.
The main point is to make sure that an upcoming patch that will
complicate the typalign_to_alignby mapping will not cause any
performance decrease.
Discussion: https://postgr.es/m/1127261.1769649624@sss.pgh.pa.us
---
contrib/dblink/dblink.c | 4 +-
src/backend/access/common/tupdesc.c | 21 +---
src/backend/executor/execExprInterp.c | 8 +-
src/backend/utils/adt/array_expanded.c | 4 +-
src/backend/utils/adt/arrayfuncs.c | 149 +++++++++++++-----------
src/backend/utils/adt/multirangetypes.c | 16 +--
src/backend/utils/adt/varlena.c | 4 +-
src/include/access/tupmacs.h | 51 ++++++--
src/include/utils/arrayaccess.h | 25 ++--
src/pl/plpython/plpy_typeio.c | 3 +-
10 files changed, 166 insertions(+), 119 deletions(-)
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 8cb3166495c..2498d80c8e7 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -2069,6 +2069,7 @@ get_text_array_contents(ArrayType *array, int *numitems)
int16 typlen;
bool typbyval;
char typalign;
+ uint8 typalignby;
char **values;
char *ptr;
bits8 *bitmap;
@@ -2081,6 +2082,7 @@ get_text_array_contents(ArrayType *array, int *numitems)
get_typlenbyvalalign(ARR_ELEMTYPE(array),
&typlen, &typbyval, &typalign);
+ typalignby = typalign_to_alignby(typalign);
values = palloc_array(char *, nitems);
@@ -2098,7 +2100,7 @@ get_text_array_contents(ArrayType *array, int *numitems)
{
values[i] = TextDatumGetCString(PointerGetDatum(ptr));
ptr = att_addlength_pointer(ptr, typlen, ptr);
- ptr = (char *) att_align_nominal(ptr, typalign);
+ ptr = (char *) att_nominal_alignby(ptr, typalignby);
}
/* advance bitmap pointer if any */
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index 94b4f1f9975..b69d10f0a45 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -86,25 +86,8 @@ populate_compact_attribute_internal(Form_pg_attribute src,
IsCatalogRelationOid(src->attrelid) ? ATTNULLABLE_VALID :
ATTNULLABLE_UNKNOWN;
- switch (src->attalign)
- {
- case TYPALIGN_INT:
- dst->attalignby = ALIGNOF_INT;
- break;
- case TYPALIGN_CHAR:
- dst->attalignby = sizeof(char);
- break;
- case TYPALIGN_DOUBLE:
- dst->attalignby = ALIGNOF_DOUBLE;
- break;
- case TYPALIGN_SHORT:
- dst->attalignby = ALIGNOF_SHORT;
- break;
- default:
- dst->attalignby = 0;
- elog(ERROR, "invalid attalign value: %c", src->attalign);
- break;
- }
+ /* Compute numeric alignment requirement, too */
+ dst->attalignby = typalign_to_alignby(src->attalign);
}
/*
diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c
index a7a5ac1e83b..61ff5ddc74c 100644
--- a/src/backend/executor/execExprInterp.c
+++ b/src/backend/executor/execExprInterp.c
@@ -4032,6 +4032,7 @@ ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op)
int16 typlen;
bool typbyval;
char typalign;
+ uint8 typalignby;
char *s;
bits8 *bitmap;
int bitmask;
@@ -4086,6 +4087,7 @@ ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op)
typlen = op->d.scalararrayop.typlen;
typbyval = op->d.scalararrayop.typbyval;
typalign = op->d.scalararrayop.typalign;
+ typalignby = typalign_to_alignby(typalign);
/* Initialize result appropriately depending on useOr */
result = BoolGetDatum(!useOr);
@@ -4111,7 +4113,7 @@ ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op)
{
elt = fetch_att(s, typbyval, typlen);
s = att_addlength_pointer(s, typlen, s);
- s = (char *) att_align_nominal(s, typalign);
+ s = (char *) att_nominal_alignby(s, typalignby);
fcinfo->args[1].value = elt;
fcinfo->args[1].isnull = false;
}
@@ -4255,6 +4257,7 @@ ExecEvalHashedScalarArrayOp(ExprState *state, ExprEvalStep *op, ExprContext *eco
int16 typlen;
bool typbyval;
char typalign;
+ uint8 typalignby;
int nitems;
bool has_nulls = false;
char *s;
@@ -4272,6 +4275,7 @@ ExecEvalHashedScalarArrayOp(ExprState *state, ExprEvalStep *op, ExprContext *eco
&typlen,
&typbyval,
&typalign);
+ typalignby = typalign_to_alignby(typalign);
oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
@@ -4318,7 +4322,7 @@ ExecEvalHashedScalarArrayOp(ExprState *state, ExprEvalStep *op, ExprContext *eco
element = fetch_att(s, typbyval, typlen);
s = att_addlength_pointer(s, typlen, s);
- s = (char *) att_align_nominal(s, typalign);
+ s = (char *) att_nominal_alignby(s, typalignby);
saophash_insert(elements_tab->hashtab, element, &hashfound);
}
diff --git a/src/backend/utils/adt/array_expanded.c b/src/backend/utils/adt/array_expanded.c
index 01e3dddcbbb..7e8352af52b 100644
--- a/src/backend/utils/adt/array_expanded.c
+++ b/src/backend/utils/adt/array_expanded.c
@@ -238,6 +238,7 @@ EA_get_flat_size(ExpandedObjectHeader *eohptr)
Datum *dvalues;
bool *dnulls;
Size nbytes;
+ uint8 typalignby;
int i;
Assert(eah->ea_magic == EA_MAGIC);
@@ -261,12 +262,13 @@ EA_get_flat_size(ExpandedObjectHeader *eohptr)
dvalues = eah->dvalues;
dnulls = eah->dnulls;
nbytes = 0;
+ typalignby = typalign_to_alignby(eah->typalign);
for (i = 0; i < nelems; i++)
{
if (dnulls && dnulls[i])
continue;
nbytes = att_addlength_datum(nbytes, eah->typlen, dvalues[i]);
- nbytes = att_align_nominal(nbytes, eah->typalign);
+ nbytes = att_nominal_alignby(nbytes, typalignby);
/* check for overflow of total request */
if (!AllocSizeIsValid(nbytes))
ereport(ERROR,
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index e71d32773b5..da68915ee20 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -75,6 +75,7 @@ typedef struct ArrayIteratorData
int16 typlen; /* element type's length */
bool typbyval; /* element type's byval property */
char typalign; /* element type's align property */
+ uint8 typalignby; /* typalign mapped to numeric alignment */
/* information about the requested slice size */
int slice_ndim; /* slice dimension, or 0 if not slicing */
@@ -123,7 +124,7 @@ static bool array_get_isnull(const bits8 *nullbitmap, int offset);
static void array_set_isnull(bits8 *nullbitmap, int offset, bool isNull);
static Datum ArrayCast(char *value, bool byval, int len);
static int ArrayCastAndSet(Datum src,
- int typlen, bool typbyval, char typalign,
+ int typlen, bool typbyval, uint8 typalignby,
char *dest);
static char *array_seek(char *ptr, int offset, bits8 *nullbitmap, int nitems,
int typlen, bool typbyval, char typalign);
@@ -187,6 +188,7 @@ array_in(PG_FUNCTION_ARGS)
int typlen;
bool typbyval;
char typalign;
+ uint8 typalignby;
char typdelim;
Oid typioparam;
char *p;
@@ -232,6 +234,7 @@ array_in(PG_FUNCTION_ARGS)
typlen = my_extra->typlen;
typbyval = my_extra->typbyval;
typalign = my_extra->typalign;
+ typalignby = typalign_to_alignby(typalign);
typdelim = my_extra->typdelim;
typioparam = my_extra->typioparam;
@@ -328,7 +331,7 @@ array_in(PG_FUNCTION_ARGS)
if (typlen == -1)
values[i] = PointerGetDatum(PG_DETOAST_DATUM(values[i]));
nbytes = att_addlength_datum(nbytes, typlen, values[i]);
- nbytes = att_align_nominal(nbytes, typalign);
+ nbytes = att_nominal_alignby(nbytes, typalignby);
/* check for overflow of total request */
if (!AllocSizeIsValid(nbytes))
ereturn(escontext, (Datum) 0,
@@ -972,6 +975,7 @@ CopyArrayEls(ArrayType *array,
bits8 *bitmap = ARR_NULLBITMAP(array);
int bitval = 0;
int bitmask = 1;
+ uint8 typalignby = typalign_to_alignby(typalign);
int i;
if (typbyval)
@@ -988,7 +992,7 @@ CopyArrayEls(ArrayType *array,
else
{
bitval |= bitmask;
- p += ArrayCastAndSet(values[i], typlen, typbyval, typalign, p);
+ p += ArrayCastAndSet(values[i], typlen, typbyval, typalignby, p);
if (freedata)
pfree(DatumGetPointer(values[i]));
}
@@ -1112,7 +1116,7 @@ array_out(PG_FUNCTION_ARGS)
needquotes = (bool *) palloc(nitems * sizeof(bool));
overall_length = 0;
- array_iter_setup(&iter, v);
+ array_iter_setup(&iter, v, typlen, typbyval, typalign);
for (i = 0; i < nitems; i++)
{
@@ -1121,8 +1125,7 @@ array_out(PG_FUNCTION_ARGS)
bool needquote;
/* Get source element, checking for NULL */
- itemvalue = array_iter_next(&iter, &isnull, i,
- typlen, typbyval, typalign);
+ itemvalue = array_iter_next(&iter, &isnull, i);
if (isnull)
{
@@ -1468,6 +1471,7 @@ ReadArrayBinary(StringInfo buf,
int i;
bool hasnull;
int32 totbytes;
+ uint8 typalignby = typalign_to_alignby(typalign);
for (i = 0; i < nitems; i++)
{
@@ -1526,7 +1530,7 @@ ReadArrayBinary(StringInfo buf,
if (typlen == -1)
values[i] = PointerGetDatum(PG_DETOAST_DATUM(values[i]));
totbytes = att_addlength_datum(totbytes, typlen, values[i]);
- totbytes = att_align_nominal(totbytes, typalign);
+ totbytes = att_nominal_alignby(totbytes, typalignby);
/* check for overflow of total request */
if (!AllocSizeIsValid(totbytes))
ereport(ERROR,
@@ -1614,7 +1618,7 @@ array_send(PG_FUNCTION_ARGS)
}
/* Send the array elements using the element's own sendproc */
- array_iter_setup(&iter, v);
+ array_iter_setup(&iter, v, typlen, typbyval, typalign);
for (i = 0; i < nitems; i++)
{
@@ -1622,8 +1626,7 @@ array_send(PG_FUNCTION_ARGS)
bool isnull;
/* Get source element, checking for NULL */
- itemvalue = array_iter_next(&iter, &isnull, i,
- typlen, typbyval, typalign);
+ itemvalue = array_iter_next(&iter, &isnull, i);
if (isnull)
{
@@ -2231,6 +2234,7 @@ array_set_element(Datum arraydatum,
addedafter,
lenbefore,
lenafter;
+ uint8 elmalignby = typalign_to_alignby(elmalign);
if (arraytyplen > 0)
{
@@ -2258,7 +2262,7 @@ array_set_element(Datum arraydatum,
resultarray = (char *) palloc(arraytyplen);
memcpy(resultarray, DatumGetPointer(arraydatum), arraytyplen);
elt_ptr = resultarray + indx[0] * elmlen;
- ArrayCastAndSet(dataValue, elmlen, elmbyval, elmalign, elt_ptr);
+ ArrayCastAndSet(dataValue, elmlen, elmbyval, elmalignby, elt_ptr);
return PointerGetDatum(resultarray);
}
@@ -2416,7 +2420,7 @@ array_set_element(Datum arraydatum,
else
{
olditemlen = att_addlength_pointer(0, elmlen, elt_ptr);
- olditemlen = att_align_nominal(olditemlen, elmalign);
+ olditemlen = att_nominal_alignby(olditemlen, elmalignby);
}
lenafter = olddatasize - lenbefore - olditemlen;
}
@@ -2426,7 +2430,7 @@ array_set_element(Datum arraydatum,
else
{
newitemlen = att_addlength_datum(0, elmlen, dataValue);
- newitemlen = att_align_nominal(newitemlen, elmalign);
+ newitemlen = att_nominal_alignby(newitemlen, elmalignby);
}
newsize = overheadlen + lenbefore + newitemlen + lenafter;
@@ -2449,7 +2453,7 @@ array_set_element(Datum arraydatum,
(char *) array + oldoverheadlen,
lenbefore);
if (!isNull)
- ArrayCastAndSet(dataValue, elmlen, elmbyval, elmalign,
+ ArrayCastAndSet(dataValue, elmlen, elmbyval, elmalignby,
(char *) newarray + overheadlen + lenbefore);
memcpy((char *) newarray + overheadlen + lenbefore + newitemlen,
(char *) array + oldoverheadlen + lenbefore + olditemlen,
@@ -3221,6 +3225,7 @@ array_map(Datum arrayd,
int typlen;
bool typbyval;
char typalign;
+ uint8 typalignby;
array_iter iter;
ArrayMetaState *inp_extra;
ArrayMetaState *ret_extra;
@@ -3270,21 +3275,21 @@ array_map(Datum arrayd,
typlen = ret_extra->typlen;
typbyval = ret_extra->typbyval;
typalign = ret_extra->typalign;
+ typalignby = typalign_to_alignby(typalign);
/* Allocate temporary arrays for new values */
values = (Datum *) palloc(nitems * sizeof(Datum));
nulls = (bool *) palloc(nitems * sizeof(bool));
/* Loop over source data */
- array_iter_setup(&iter, v);
+ array_iter_setup(&iter, v, inp_typlen, inp_typbyval, inp_typalign);
hasnulls = false;
for (i = 0; i < nitems; i++)
{
/* Get source element, checking for NULL */
*transform_source =
- array_iter_next(&iter, transform_source_isnull, i,
- inp_typlen, inp_typbyval, inp_typalign);
+ array_iter_next(&iter, transform_source_isnull, i);
/* Apply the given expression to source element */
values[i] = ExecEvalExpr(exprstate, econtext, &nulls[i]);
@@ -3298,7 +3303,7 @@ array_map(Datum arrayd,
values[i] = PointerGetDatum(PG_DETOAST_DATUM(values[i]));
/* Update total result size */
nbytes = att_addlength_datum(nbytes, typlen, values[i]);
- nbytes = att_align_nominal(nbytes, typalign);
+ nbytes = att_nominal_alignby(nbytes, typalignby);
/* check for overflow of total request */
if (!AllocSizeIsValid(nbytes))
ereport(ERROR,
@@ -3505,6 +3510,7 @@ construct_md_array(Datum *elems,
int32 dataoffset;
int i;
int nelems;
+ uint8 elmalignby = typalign_to_alignby(elmalign);
if (ndims < 0) /* we do allow zero-dimension arrays */
ereport(ERROR,
@@ -3538,7 +3544,7 @@ construct_md_array(Datum *elems,
if (elmlen == -1)
elems[i] = PointerGetDatum(PG_DETOAST_DATUM(elems[i]));
nbytes = att_addlength_datum(nbytes, elmlen, elems[i]);
- nbytes = att_align_nominal(nbytes, elmalign);
+ nbytes = att_nominal_alignby(nbytes, elmalignby);
/* check for overflow of total request */
if (!AllocSizeIsValid(nbytes))
ereport(ERROR,
@@ -3641,6 +3647,7 @@ deconstruct_array(const ArrayType *array,
bits8 *bitmap;
int bitmask;
int i;
+ uint8 elmalignby = typalign_to_alignby(elmalign);
Assert(ARR_ELEMTYPE(array) == elmtype);
@@ -3673,7 +3680,7 @@ deconstruct_array(const ArrayType *array,
{
elems[i] = fetch_att(p, elmbyval, elmlen);
p = att_addlength_pointer(p, elmlen, p);
- p = (char *) att_align_nominal(p, elmalign);
+ p = (char *) att_nominal_alignby(p, elmalignby);
}
/* advance bitmap pointer if any */
@@ -3878,8 +3885,8 @@ array_eq(PG_FUNCTION_ARGS)
/* Loop over source data */
nitems = ArrayGetNItems(ndims1, dims1);
- array_iter_setup(&it1, array1);
- array_iter_setup(&it2, array2);
+ array_iter_setup(&it1, array1, typlen, typbyval, typalign);
+ array_iter_setup(&it2, array2, typlen, typbyval, typalign);
for (i = 0; i < nitems; i++)
{
@@ -3890,10 +3897,8 @@ array_eq(PG_FUNCTION_ARGS)
bool oprresult;
/* Get elements, checking for NULL */
- elt1 = array_iter_next(&it1, &isnull1, i,
- typlen, typbyval, typalign);
- elt2 = array_iter_next(&it2, &isnull2, i,
- typlen, typbyval, typalign);
+ elt1 = array_iter_next(&it1, &isnull1, i);
+ elt2 = array_iter_next(&it2, &isnull2, i);
/*
* We consider two NULLs equal; NULL and not-NULL are unequal.
@@ -4042,8 +4047,8 @@ array_cmp(FunctionCallInfo fcinfo)
/* Loop over source data */
min_nitems = Min(nitems1, nitems2);
- array_iter_setup(&it1, array1);
- array_iter_setup(&it2, array2);
+ array_iter_setup(&it1, array1, typlen, typbyval, typalign);
+ array_iter_setup(&it2, array2, typlen, typbyval, typalign);
for (i = 0; i < min_nitems; i++)
{
@@ -4054,8 +4059,8 @@ array_cmp(FunctionCallInfo fcinfo)
int32 cmpresult;
/* Get elements, checking for NULL */
- elt1 = array_iter_next(&it1, &isnull1, i, typlen, typbyval, typalign);
- elt2 = array_iter_next(&it2, &isnull2, i, typlen, typbyval, typalign);
+ elt1 = array_iter_next(&it1, &isnull1, i);
+ elt2 = array_iter_next(&it2, &isnull2, i);
/*
* We consider two NULLs equal; NULL > not-NULL.
@@ -4238,7 +4243,7 @@ hash_array(PG_FUNCTION_ARGS)
/* Loop over source data */
nitems = ArrayGetNItems(ndims, dims);
- array_iter_setup(&iter, array);
+ array_iter_setup(&iter, array, typlen, typbyval, typalign);
for (i = 0; i < nitems; i++)
{
@@ -4247,7 +4252,7 @@ hash_array(PG_FUNCTION_ARGS)
uint32 elthash;
/* Get element, checking for NULL */
- elt = array_iter_next(&iter, &isnull, i, typlen, typbyval, typalign);
+ elt = array_iter_next(&iter, &isnull, i);
if (isnull)
{
@@ -4328,7 +4333,7 @@ hash_array_extended(PG_FUNCTION_ARGS)
/* Loop over source data */
nitems = ArrayGetNItems(ndims, dims);
- array_iter_setup(&iter, array);
+ array_iter_setup(&iter, array, typlen, typbyval, typalign);
for (i = 0; i < nitems; i++)
{
@@ -4337,7 +4342,7 @@ hash_array_extended(PG_FUNCTION_ARGS)
uint64 elthash;
/* Get element, checking for NULL */
- elt = array_iter_next(&iter, &isnull, i, typlen, typbyval, typalign);
+ elt = array_iter_next(&iter, &isnull, i);
if (isnull)
{
@@ -4451,7 +4456,7 @@ array_contain_compare(AnyArrayType *array1, AnyArrayType *array2, Oid collation,
/* Loop over source data */
nelems1 = ArrayGetNItems(AARR_NDIM(array1), AARR_DIMS(array1));
- array_iter_setup(&it1, array1);
+ array_iter_setup(&it1, array1, typlen, typbyval, typalign);
for (i = 0; i < nelems1; i++)
{
@@ -4459,7 +4464,7 @@ array_contain_compare(AnyArrayType *array1, AnyArrayType *array2, Oid collation,
bool isnull1;
/* Get element, checking for NULL */
- elt1 = array_iter_next(&it1, &isnull1, i, typlen, typbyval, typalign);
+ elt1 = array_iter_next(&it1, &isnull1, i);
/*
* We assume that the comparison operator is strict, so a NULL can't
@@ -4626,6 +4631,7 @@ array_create_iterator(ArrayType *arr, int slice_ndim, ArrayMetaState *mstate)
&iterator->typlen,
&iterator->typbyval,
&iterator->typalign);
+ iterator->typalignby = typalign_to_alignby(iterator->typalign);
/*
* Remember the slicing parameters.
@@ -4700,7 +4706,7 @@ array_iterate(ArrayIterator iterator, Datum *value, bool *isnull)
/* Move our data pointer forward to the next element */
p = att_addlength_pointer(p, iterator->typlen, p);
- p = (char *) att_align_nominal(p, iterator->typalign);
+ p = (char *) att_nominal_alignby(p, iterator->typalignby);
iterator->data_ptr = p;
}
}
@@ -4730,7 +4736,7 @@ array_iterate(ArrayIterator iterator, Datum *value, bool *isnull)
/* Move our data pointer forward to the next element */
p = att_addlength_pointer(p, iterator->typlen, p);
- p = (char *) att_align_nominal(p, iterator->typalign);
+ p = (char *) att_nominal_alignby(p, iterator->typalignby);
}
}
@@ -4828,7 +4834,7 @@ static int
ArrayCastAndSet(Datum src,
int typlen,
bool typbyval,
- char typalign,
+ uint8 typalignby,
char *dest)
{
int inc;
@@ -4839,14 +4845,14 @@ ArrayCastAndSet(Datum src,
store_att_byval(dest, src, typlen);
else
memmove(dest, DatumGetPointer(src), typlen);
- inc = att_align_nominal(typlen, typalign);
+ inc = att_nominal_alignby(typlen, typalignby);
}
else
{
Assert(!typbyval);
inc = att_addlength_datum(0, typlen, src);
memmove(dest, DatumGetPointer(src), inc);
- inc = att_align_nominal(inc, typalign);
+ inc = att_nominal_alignby(inc, typalignby);
}
return inc;
@@ -4867,12 +4873,13 @@ static char *
array_seek(char *ptr, int offset, bits8 *nullbitmap, int nitems,
int typlen, bool typbyval, char typalign)
{
+ uint8 typalignby = typalign_to_alignby(typalign);
int bitmask;
int i;
/* easy if fixed-size elements and no NULLs */
if (typlen > 0 && !nullbitmap)
- return ptr + nitems * ((Size) att_align_nominal(typlen, typalign));
+ return ptr + nitems * ((Size) att_nominal_alignby(typlen, typalignby));
/* seems worth having separate loops for NULL and no-NULLs cases */
if (nullbitmap)
@@ -4885,7 +4892,7 @@ array_seek(char *ptr, int offset, bits8 *nullbitmap, int nitems,
if (*nullbitmap & bitmask)
{
ptr = att_addlength_pointer(ptr, typlen, ptr);
- ptr = (char *) att_align_nominal(ptr, typalign);
+ ptr = (char *) att_nominal_alignby(ptr, typalignby);
}
bitmask <<= 1;
if (bitmask == 0x100)
@@ -4900,7 +4907,7 @@ array_seek(char *ptr, int offset, bits8 *nullbitmap, int nitems,
for (i = 0; i < nitems; i++)
{
ptr = att_addlength_pointer(ptr, typlen, ptr);
- ptr = (char *) att_align_nominal(ptr, typalign);
+ ptr = (char *) att_nominal_alignby(ptr, typalignby);
}
}
return ptr;
@@ -5050,12 +5057,13 @@ array_slice_size(char *arraydataptr, bits8 *arraynullsptr,
j,
inc;
int count = 0;
+ uint8 typalignby = typalign_to_alignby(typalign);
mda_get_range(ndim, span, st, endp);
/* Pretty easy for fixed element length without nulls ... */
if (typlen > 0 && !arraynullsptr)
- return ArrayGetNItems(ndim, span) * att_align_nominal(typlen, typalign);
+ return ArrayGetNItems(ndim, span) * att_nominal_alignby(typlen, typalignby);
/* Else gotta do it the hard way */
src_offset = ArrayGetOffset(ndim, dim, lb, st);
@@ -5077,7 +5085,7 @@ array_slice_size(char *arraydataptr, bits8 *arraynullsptr,
if (!array_get_isnull(arraynullsptr, src_offset))
{
inc = att_addlength_pointer(0, typlen, ptr);
- inc = att_align_nominal(inc, typalign);
+ inc = att_nominal_alignby(inc, typalignby);
ptr += inc;
count += inc;
}
@@ -6096,6 +6104,7 @@ array_fill_internal(ArrayType *dims, ArrayType *lbs,
int16 elmlen;
bool elmbyval;
char elmalign;
+ uint8 elmalignby;
ArrayMetaState *my_extra;
/*
@@ -6190,6 +6199,7 @@ array_fill_internal(ArrayType *dims, ArrayType *lbs,
elmlen = my_extra->typlen;
elmbyval = my_extra->typbyval;
elmalign = my_extra->typalign;
+ elmalignby = typalign_to_alignby(elmalign);
/* compute required space */
if (!isnull)
@@ -6204,7 +6214,7 @@ array_fill_internal(ArrayType *dims, ArrayType *lbs,
value = PointerGetDatum(PG_DETOAST_DATUM(value));
nbytes = att_addlength_datum(0, elmlen, value);
- nbytes = att_align_nominal(nbytes, elmalign);
+ nbytes = att_nominal_alignby(nbytes, elmalignby);
Assert(nbytes > 0);
totbytes = nbytes * nitems;
@@ -6228,7 +6238,7 @@ array_fill_internal(ArrayType *dims, ArrayType *lbs,
p = ARR_DATA_PTR(result);
for (i = 0; i < nitems; i++)
- p += ArrayCastAndSet(value, elmlen, elmbyval, elmalign, p);
+ p += ArrayCastAndSet(value, elmlen, elmbyval, elmalignby, p);
}
else
{
@@ -6259,9 +6269,6 @@ array_unnest(PG_FUNCTION_ARGS)
array_iter iter;
int nextelem;
int numelems;
- int16 elmlen;
- bool elmbyval;
- char elmalign;
} array_unnest_fctx;
FuncCallContext *funcctx;
@@ -6272,6 +6279,9 @@ array_unnest(PG_FUNCTION_ARGS)
if (SRF_IS_FIRSTCALL())
{
AnyArrayType *arr;
+ int16 elmlen;
+ bool elmbyval;
+ char elmalign;
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
@@ -6293,23 +6303,24 @@ array_unnest(PG_FUNCTION_ARGS)
/* allocate memory for user context */
fctx = palloc_object(array_unnest_fctx);
- /* initialize state */
- array_iter_setup(&fctx->iter, arr);
- fctx->nextelem = 0;
- fctx->numelems = ArrayGetNItems(AARR_NDIM(arr), AARR_DIMS(arr));
-
+ /* get element-type data */
if (VARATT_IS_EXPANDED_HEADER(arr))
{
/* we can just grab the type data from expanded array */
- fctx->elmlen = arr->xpn.typlen;
- fctx->elmbyval = arr->xpn.typbyval;
- fctx->elmalign = arr->xpn.typalign;
+ elmlen = arr->xpn.typlen;
+ elmbyval = arr->xpn.typbyval;
+ elmalign = arr->xpn.typalign;
}
else
get_typlenbyvalalign(AARR_ELEMTYPE(arr),
- &fctx->elmlen,
- &fctx->elmbyval,
- &fctx->elmalign);
+ &elmlen,
+ &elmbyval,
+ &elmalign);
+
+ /* initialize state */
+ array_iter_setup(&fctx->iter, arr, elmlen, elmbyval, elmalign);
+ fctx->nextelem = 0;
+ fctx->numelems = ArrayGetNItems(AARR_NDIM(arr), AARR_DIMS(arr));
funcctx->user_fctx = fctx;
MemoryContextSwitchTo(oldcontext);
@@ -6324,8 +6335,7 @@ array_unnest(PG_FUNCTION_ARGS)
int offset = fctx->nextelem++;
Datum elem;
- elem = array_iter_next(&fctx->iter, &fcinfo->isnull, offset,
- fctx->elmlen, fctx->elmbyval, fctx->elmalign);
+ elem = array_iter_next(&fctx->iter, &fcinfo->isnull, offset);
SRF_RETURN_NEXT(funcctx, elem);
}
@@ -6401,6 +6411,7 @@ array_replace_internal(ArrayType *array,
int typlen;
bool typbyval;
char typalign;
+ uint8 typalignby;
char *arraydataptr;
bits8 *bitmap;
int bitmask;
@@ -6445,6 +6456,7 @@ array_replace_internal(ArrayType *array,
typlen = typentry->typlen;
typbyval = typentry->typbyval;
typalign = typentry->typalign;
+ typalignby = typalign_to_alignby(typalign);
/*
* Detoast values if they are toasted. The replacement value must be
@@ -6506,7 +6518,7 @@ array_replace_internal(ArrayType *array,
isNull = false;
elt = fetch_att(arraydataptr, typbyval, typlen);
arraydataptr = att_addlength_datum(arraydataptr, typlen, elt);
- arraydataptr = (char *) att_align_nominal(arraydataptr, typalign);
+ arraydataptr = (char *) att_nominal_alignby(arraydataptr, typalignby);
if (search_isnull)
{
@@ -6553,7 +6565,7 @@ array_replace_internal(ArrayType *array,
{
/* Update total result size */
nbytes = att_addlength_datum(nbytes, typlen, values[nresult]);
- nbytes = att_align_nominal(nbytes, typalign);
+ nbytes = att_nominal_alignby(nbytes, typalignby);
/* check for overflow of total request */
if (!AllocSizeIsValid(nbytes))
ereport(ERROR,
@@ -6860,6 +6872,7 @@ width_bucket_array_variable(Datum operand,
int typlen = typentry->typlen;
bool typbyval = typentry->typbyval;
char typalign = typentry->typalign;
+ uint8 typalignby = typalign_to_alignby(typalign);
int left;
int right;
@@ -6883,7 +6896,7 @@ width_bucket_array_variable(Datum operand,
for (i = left; i < mid; i++)
{
ptr = att_addlength_pointer(ptr, typlen, ptr);
- ptr = (char *) att_align_nominal(ptr, typalign);
+ ptr = (char *) att_nominal_alignby(ptr, typalignby);
}
locfcinfo->args[0].value = operand;
@@ -6908,7 +6921,7 @@ width_bucket_array_variable(Datum operand,
* ensures we do only O(N) array indexing work, not O(N^2).
*/
ptr = att_addlength_pointer(ptr, typlen, ptr);
- thresholds_data = (char *) att_align_nominal(ptr, typalign);
+ thresholds_data = (char *) att_nominal_alignby(ptr, typalignby);
}
}
diff --git a/src/backend/utils/adt/multirangetypes.c b/src/backend/utils/adt/multirangetypes.c
index 07e2a81d46a..b1942387dc5 100644
--- a/src/backend/utils/adt/multirangetypes.c
+++ b/src/backend/utils/adt/multirangetypes.c
@@ -572,21 +572,22 @@ multirange_size_estimate(TypeCacheEntry *rangetyp, int32 range_count,
RangeType **ranges)
{
char elemalign = rangetyp->rngelemtype->typalign;
+ uint8 elemalignby = typalign_to_alignby(elemalign);
Size size;
int32 i;
/*
* Count space for MultirangeType struct, items and flags.
*/
- size = att_align_nominal(sizeof(MultirangeType) +
- Max(range_count - 1, 0) * sizeof(uint32) +
- range_count * sizeof(uint8), elemalign);
+ size = att_nominal_alignby(sizeof(MultirangeType) +
+ Max(range_count - 1, 0) * sizeof(uint32) +
+ range_count * sizeof(uint8), elemalignby);
/* Count space for range bounds */
for (i = 0; i < range_count; i++)
- size += att_align_nominal(VARSIZE(ranges[i]) -
- sizeof(RangeType) -
- sizeof(char), elemalign);
+ size += att_nominal_alignby(VARSIZE(ranges[i]) -
+ sizeof(RangeType) -
+ sizeof(char), elemalignby);
return size;
}
@@ -605,6 +606,7 @@ write_multirange_data(MultirangeType *multirange, TypeCacheEntry *rangetyp,
const char *begin;
char *ptr;
char elemalign = rangetyp->rngelemtype->typalign;
+ uint8 elemalignby = typalign_to_alignby(elemalign);
items = MultirangeGetItemsPtr(multirange);
flags = MultirangeGetFlagsPtr(multirange);
@@ -630,7 +632,7 @@ write_multirange_data(MultirangeType *multirange, TypeCacheEntry *rangetyp,
flags[i] = *((char *) ranges[i] + VARSIZE(ranges[i]) - sizeof(char));
len = VARSIZE(ranges[i]) - sizeof(RangeType) - sizeof(char);
memcpy(ptr, ranges[i] + 1, len);
- ptr += att_align_nominal(len, elemalign);
+ ptr += att_nominal_alignby(len, elemalignby);
}
}
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 6c1ebb0866d..552ac0c61d3 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -3898,6 +3898,7 @@ array_to_text_internal(FunctionCallInfo fcinfo, ArrayType *v,
int typlen;
bool typbyval;
char typalign;
+ uint8 typalignby;
StringInfoData buf;
bool printed = false;
char *p;
@@ -3947,6 +3948,7 @@ array_to_text_internal(FunctionCallInfo fcinfo, ArrayType *v,
typlen = my_extra->typlen;
typbyval = my_extra->typbyval;
typalign = my_extra->typalign;
+ typalignby = typalign_to_alignby(typalign);
p = ARR_DATA_PTR(v);
bitmap = ARR_NULLBITMAP(v);
@@ -3983,7 +3985,7 @@ array_to_text_internal(FunctionCallInfo fcinfo, ArrayType *v,
printed = true;
p = att_addlength_pointer(p, typlen, p);
- p = (char *) att_align_nominal(p, typalign);
+ p = (char *) att_nominal_alignby(p, typalignby);
}
/* advance bitmap pointer if any */
diff --git a/src/include/access/tupmacs.h b/src/include/access/tupmacs.h
index 3e5530658c9..d64c18b950b 100644
--- a/src/include/access/tupmacs.h
+++ b/src/include/access/tupmacs.h
@@ -71,6 +71,43 @@ fetch_att(const void *T, bool attbyval, int attlen)
}
#endif /* FRONTEND */
+/*
+ * typalign_to_alignby: map a TYPALIGN_xxx value to the numeric alignment
+ * value it represents. (We store TYPALIGN_xxx codes not the real alignment
+ * values mainly so that initial catalog contents can be machine-independent.)
+ */
+static inline uint8
+typalign_to_alignby(char typalign)
+{
+ uint8 alignby;
+
+ switch (typalign)
+ {
+ case TYPALIGN_CHAR:
+ alignby = sizeof(char);
+ break;
+ case TYPALIGN_SHORT:
+ alignby = ALIGNOF_SHORT;
+ break;
+ case TYPALIGN_INT:
+ alignby = ALIGNOF_INT;
+ break;
+ case TYPALIGN_DOUBLE:
+ alignby = ALIGNOF_DOUBLE;
+ break;
+ default:
+#ifndef FRONTEND
+ elog(ERROR, "invalid typalign value: %c", typalign);
+#else
+ fprintf(stderr, "invalid typalign value: %c\n", typalign);
+ exit(1);
+#endif
+ alignby = 0;
+ break;
+ }
+ return alignby;
+}
+
/*
* att_align_datum aligns the given offset as needed for a datum of alignment
* requirement attalign and typlen attlen. attdatum is the Datum variable
@@ -139,19 +176,11 @@ fetch_att(const void *T, bool attbyval, int attlen)
* * within arrays and multiranges, we unconditionally align varlenas (XXX this
* should be revisited, probably).
*
- * The attalign cases are tested in what is hopefully something like their
- * frequency of occurrence.
+ * In performance-critical loops, avoid using this macro; instead use
+ * att_nominal_alignby with a pre-computed alignby value.
*/
#define att_align_nominal(cur_offset, attalign) \
-( \
- ((attalign) == TYPALIGN_INT) ? INTALIGN(cur_offset) : \
- (((attalign) == TYPALIGN_CHAR) ? (uintptr_t) (cur_offset) : \
- (((attalign) == TYPALIGN_DOUBLE) ? DOUBLEALIGN(cur_offset) : \
- ( \
- AssertMacro((attalign) == TYPALIGN_SHORT), \
- SHORTALIGN(cur_offset) \
- ))) \
-)
+ att_nominal_alignby(cur_offset, typalign_to_alignby(attalign))
/*
* Similar to att_align_nominal, but accepts a number of bytes, typically from
diff --git a/src/include/utils/arrayaccess.h b/src/include/utils/arrayaccess.h
index abb8659de02..a325ae52574 100644
--- a/src/include/utils/arrayaccess.h
+++ b/src/include/utils/arrayaccess.h
@@ -22,8 +22,8 @@
* Functions for iterating through elements of a flat or expanded array.
* These require a state struct "array_iter iter".
*
- * Use "array_iter_setup(&iter, arrayptr);" to prepare to iterate, and
- * "datumvar = array_iter_next(&iter, &isnullvar, index, ...);" to fetch
+ * Use "array_iter_setup(&iter, arrayptr, ...);" to prepare to iterate,
+ * and "datumvar = array_iter_next(&iter, &isnullvar, index);" to fetch
* the next element into datumvar/isnullvar.
* "index" must be the zero-origin element number; we make caller provide
* this since caller is generally counting the elements anyway. Despite
@@ -42,11 +42,17 @@ typedef struct array_iter
char *dataptr; /* Current spot in the data area */
bits8 *bitmapptr; /* Current byte of the nulls bitmap, or NULL */
int bitmask; /* mask for current bit in nulls bitmap */
+
+ /* Fields used in both cases: data about array's element type */
+ int elmlen;
+ bool elmbyval;
+ uint8 elmalignby;
} array_iter;
static inline void
-array_iter_setup(array_iter *it, AnyArrayType *a)
+array_iter_setup(array_iter *it, AnyArrayType *a,
+ int elmlen, bool elmbyval, char elmalign)
{
if (VARATT_IS_EXPANDED_HEADER(a))
{
@@ -75,11 +81,13 @@ array_iter_setup(array_iter *it, AnyArrayType *a)
it->bitmapptr = ARR_NULLBITMAP((ArrayType *) a);
}
it->bitmask = 1;
+ it->elmlen = elmlen;
+ it->elmbyval = elmbyval;
+ it->elmalignby = typalign_to_alignby(elmalign);
}
static inline Datum
-array_iter_next(array_iter *it, bool *isnull, int i,
- int elmlen, bool elmbyval, char elmalign)
+array_iter_next(array_iter *it, bool *isnull, int i)
{
Datum ret;
@@ -98,10 +106,11 @@ array_iter_next(array_iter *it, bool *isnull, int i,
else
{
*isnull = false;
- ret = fetch_att(it->dataptr, elmbyval, elmlen);
- it->dataptr = att_addlength_pointer(it->dataptr, elmlen,
+ ret = fetch_att(it->dataptr, it->elmbyval, it->elmlen);
+ it->dataptr = att_addlength_pointer(it->dataptr, it->elmlen,
it->dataptr);
- it->dataptr = (char *) att_align_nominal(it->dataptr, elmalign);
+ it->dataptr = (char *) att_nominal_alignby(it->dataptr,
+ it->elmalignby);
}
it->bitmask <<= 1;
if (it->bitmask == 0x100)
diff --git a/src/pl/plpython/plpy_typeio.c b/src/pl/plpython/plpy_typeio.c
index 1f69109b081..44055de6aeb 100644
--- a/src/pl/plpython/plpy_typeio.c
+++ b/src/pl/plpython/plpy_typeio.c
@@ -735,6 +735,7 @@ PLyList_FromArray_recurse(PLyDatumToOb *elm, int *dims, int ndim, int dim,
char *dataptr = *dataptr_p;
bits8 *bitmap = *bitmap_p;
int bitmask = *bitmask_p;
+ uint8 typalignby = typalign_to_alignby(elm->typalign);
for (i = 0; i < dims[dim]; i++)
{
@@ -751,7 +752,7 @@ PLyList_FromArray_recurse(PLyDatumToOb *elm, int *dims, int ndim, int dim,
itemvalue = fetch_att(dataptr, elm->typbyval, elm->typlen);
PyList_SetItem(list, i, elm->func(elm, itemvalue));
dataptr = att_addlength_pointer(dataptr, elm->typlen, dataptr);
- dataptr = (char *) att_align_nominal(dataptr, elm->typalign);
+ dataptr = (char *) att_nominal_alignby(dataptr, typalignby);
}
/* advance bitmap pointer if any */
--
2.43.7
From 9a98723f4ba74543e304c5b76213c05cde809df6 Mon Sep 17 00:00:00 2001
From: Tom Lane
Date: Thu, 29 Jan 2026 20:11:28 -0500
Subject: [PATCH v2 2/2] Decouple our alignment assumptions about int64 and
double.
Up to now we have assumed that int64 and double have the same
alignment requirement, but there are platforms on which that's
not true (notably AIX). This assumption is a bit of a wart anyway,
since it leads to confusion about which alignment setting to use.
Let's break that apart.
We actually need to split TYPALIGN_DOUBLE into three values not
two, because we need a representation for "the maximum alignment
on this platform"; composite types need to use that setting.
So this patch invents TYPALIGN_INT64 and TYPALIGN_MAX, and
propagates those into all the necessary places. It's pretty
straightforward really, though it's certainly possible I missed
a few places to change.
One of the concerns that prevented this from being done long
ago was not wanting to add overhead to tuple forming/deforming.
However that concern seems gone now, because we map TYPALIGN_xxx
values to numeric alignments in typalign_to_alignby() which
we can usually avoid using within performance-critical loops.
An issue not resolved here is that we are not consistent
about the pg_type typlen/typalign values for polymorphic
types (the "any*" types). Those shouldn't actually matter,
but why aren't they all alike?
Side notes:
I got rid of LONGALIGN[_DOWN] along with the configure probes
for ALIGNOF_LONG. We were not using those anywhere and it
seems highly unlikely that we'd do so in future.
bootstrap.c turns out to have had the wrong alignment value
for _aclitem; seems that was missed when we widened AclMode
to 64 bits. AFAICT the value wasn't used so there were no
ill effects.
I fixed a couple of places that were using hard-coded values
when they could have used TYPALIGN_xxx macros.
This will require a catversion bump.
Author: Tom Lane
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/1127261.1769649624@sss.pgh.pa.us
---
configure | 64 +++----------------
configure.ac | 30 +++------
doc/src/sgml/catalogs.sgml | 8 ++-
doc/src/sgml/ref/create_type.sgml | 9 ++-
meson.build | 31 ++++-----
src/backend/access/common/tupdesc.c | 2 +-
src/backend/bootstrap/bootstrap.c | 4 +-
src/backend/catalog/Catalog.pm | 10 ++-
src/backend/catalog/heap.c | 4 +-
src/backend/catalog/pg_type.c | 9 ++-
src/backend/commands/typecmds.c | 38 +++++++++--
src/backend/tsearch/ts_typanalyze.c | 2 +-
src/backend/utils/adt/arrayfuncs.c | 2 +-
src/backend/utils/adt/orderedsetaggs.c | 2 +-
src/backend/utils/adt/rangetypes_typanalyze.c | 2 +-
src/bin/initdb/initdb.c | 2 +-
src/bin/pg_dump/pg_dump.c | 4 ++
src/include/access/tupmacs.h | 6 ++
src/include/c.h | 4 +-
src/include/catalog/pg_type.dat | 62 +++++++++---------
src/include/catalog/pg_type.h | 2 +
src/include/pg_config.h.in | 3 -
src/pl/plpython/plpy_typeio.c | 4 +-
src/test/regress/expected/create_type.out | 1 +
src/test/regress/expected/float8.out | 8 ++-
src/test/regress/expected/type_sanity.out | 8 ++-
src/test/regress/sql/create_type.sql | 1 +
src/test/regress/sql/float8.sql | 6 +-
src/test/regress/sql/type_sanity.sql | 8 ++-
29 files changed, 172 insertions(+), 164 deletions(-)
diff --git a/configure b/configure
index a10a2c85c6a..5adfb3eba45 100755
--- a/configure
+++ b/configure
@@ -17095,41 +17095,6 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
-# The cast to long int works around a bug in the HP C Compiler,
-# see AC_CHECK_SIZEOF for more information.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of long" >&5
-$as_echo_n "checking alignment of long... " >&6; }
-if ${ac_cv_alignof_long+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- if ac_fn_c_compute_int "$LINENO" "(long int) offsetof (ac__type_alignof_, y)" "ac_cv_alignof_long" "$ac_includes_default
-#ifndef offsetof
-# define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
-#endif
-typedef struct { char x; long y; } ac__type_alignof_;"; then :
-
-else
- if test "$ac_cv_type_long" = yes; then
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error 77 "cannot compute alignment of long
-See \`config.log' for more details" "$LINENO" 5; }
- else
- ac_cv_alignof_long=0
- fi
-fi
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_alignof_long" >&5
-$as_echo "$ac_cv_alignof_long" >&6; }
-
-
-
-cat >>confdefs.h <<_ACEOF
-#define ALIGNOF_LONG $ac_cv_alignof_long
-_ACEOF
-
-
# The cast to long int works around a bug in the HP C Compiler,
# see AC_CHECK_SIZEOF for more information.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of int64_t" >&5
@@ -17203,27 +17168,16 @@ _ACEOF
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that long's alignment is at least as strong as
-# char, short, or int. Note that we intentionally do not consider any types
-# wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
-# much of a penalty for disk and memory space.
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) Note that we intentionally do not consider any types wider
+# than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much
+# of a penalty for disk and memory space.
-MAX_ALIGNOF=$ac_cv_alignof_double
-
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
- as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
- as_fn_error $? "alignment of 'int64_t' is greater than the alignment of 'double'" "$LINENO" 5
+if test $ac_cv_alignof_int64_t -gt $ac_cv_alignof_double ; then
+ MAX_ALIGNOF=$ac_cv_alignof_int64_t
+else
+ MAX_ALIGNOF=$ac_cv_alignof_double
fi
cat >>confdefs.h <<_ACEOF
diff --git a/configure.ac b/configure.ac
index 814e64a967e..a5eab2e5fff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2031,33 +2031,21 @@ AC_CHECK_SIZEOF([intmax_t])
AC_CHECK_ALIGNOF(short)
AC_CHECK_ALIGNOF(int)
-AC_CHECK_ALIGNOF(long)
AC_CHECK_ALIGNOF(int64_t)
AC_CHECK_ALIGNOF(double)
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that long's alignment is at least as strong as
-# char, short, or int. Note that we intentionally do not consider any types
-# wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
-# much of a penalty for disk and memory space.
-
-MAX_ALIGNOF=$ac_cv_alignof_double
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) Note that we intentionally do not consider any types wider
+# than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much
+# of a penalty for disk and memory space.
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
- AC_MSG_ERROR([alignment of 'long' is greater than the alignment of 'double'])
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
- AC_MSG_ERROR([alignment of 'int64_t' is greater than the alignment of 'double'])
+if test $ac_cv_alignof_int64_t -gt $ac_cv_alignof_double ; then
+ MAX_ALIGNOF=$ac_cv_alignof_int64_t
+else
+ MAX_ALIGNOF=$ac_cv_alignof_double
fi
AC_DEFINE_UNQUOTED(MAXIMUM_ALIGNOF, $MAX_ALIGNOF, [Define as the maximum alignment requirement of any C data type.])
diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index 332193565e2..12608d00a18 100644
--- a/doc/src/sgml/catalogs.sgml
+++ b/doc/src/sgml/catalogs.sgml
@@ -9567,7 +9567,13 @@ SCRAM-SHA-256$<iteration count>:&l
i = int alignment (4 bytes on most machines).
- d = double alignment (8 bytes on many machines, but by no means all).
+ l = int64 alignment (8 bytes on most machines, but by no means all).
+
+
+ d = double alignment (8 bytes on most machines, but by no means all).
+
+
+ m = maximum alignment (8 bytes on most machines).
diff --git a/doc/src/sgml/ref/create_type.sgml b/doc/src/sgml/ref/create_type.sgml
index 994dfc65268..006db624094 100644
--- a/doc/src/sgml/ref/create_type.sgml
+++ b/doc/src/sgml/ref/create_type.sgml
@@ -748,8 +748,15 @@ CREATE TYPE name
The storage alignment requirement of the data type. If specified,
it must be char, int2,
- int4, or double; the
+ int4, int8,
+ double, or max; the
default is int4.
+ int8 and double usually
+ have the same behavior, but there are platforms on which they are
+ different because integer and floating-point values have different
+ requirements. max means the maximum alignment
+ requirement for any of these types; it is often used for container
+ types such as records.
diff --git a/meson.build b/meson.build
index df907b62da3..bb17859fee4 100644
--- a/meson.build
+++ b/meson.build
@@ -1798,32 +1798,27 @@ endif
# Determine memory alignment requirements for the basic C data types.
-alignof_types = ['short', 'int', 'long', 'double']
+alignof_types = ['short', 'int', 'int64_t', 'double']
foreach t : alignof_types
- align = cc.alignment(t, args: test_c_args)
+ align = cc.alignment(t, args: test_c_args, prefix: '#include ')
cdata.set('ALIGNOF_@0@'.format(t.to_upper()), align)
endforeach
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that int64_t's alignment is at least as strong
-# as long, char, short, or int. Note that we intentionally do not consider
-# any types wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8
-# would be too much of a penalty for disk and memory space.
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) Note that we intentionally do not consider any types wider
+# than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much
+# of a penalty for disk and memory space.
+
+alignof_int64_t = cdata.get('ALIGNOF_INT64_T')
alignof_double = cdata.get('ALIGNOF_DOUBLE')
-if cc.alignment('int64_t', args: test_c_args, prefix: '#include ') > alignof_double
- error('alignment of int64_t is greater than the alignment of double')
+if alignof_int64_t > alignof_double
+ cdata.set('MAXIMUM_ALIGNOF', alignof_int64_t)
+else
+ cdata.set('MAXIMUM_ALIGNOF', alignof_double)
endif
-cdata.set('MAXIMUM_ALIGNOF', alignof_double)
cdata.set('SIZEOF_LONG', cc.sizeof('long', args: test_c_args))
cdata.set('SIZEOF_LONG_LONG', cc.sizeof('long long', args: test_c_args))
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index b69d10f0a45..47b9f8b5459 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -977,7 +977,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
case INT8OID:
att->attlen = 8;
att->attbyval = true;
- att->attalign = TYPALIGN_DOUBLE;
+ att->attalign = TYPALIGN_INT64;
att->attstorage = TYPSTORAGE_PLAIN;
att->attcompression = InvalidCompressionMethod;
att->attcollation = InvalidOid;
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index dd57624b4f9..7a3a13a6ec7 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -115,7 +115,7 @@ static const struct typinfo TypInfo[] = {
F_TEXTIN, F_TEXTOUT},
{"oid", OIDOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_OIDIN, F_OIDOUT},
- {"oid8", OID8OID, 0, 8, true, TYPALIGN_DOUBLE, TYPSTORAGE_PLAIN, InvalidOid,
+ {"oid8", OID8OID, 0, 8, true, TYPALIGN_INT64, TYPSTORAGE_PLAIN, InvalidOid,
F_OID8IN, F_OID8OUT},
{"tid", TIDOID, 0, 6, false, TYPALIGN_SHORT, TYPSTORAGE_PLAIN, InvalidOid,
F_TIDIN, F_TIDOUT},
@@ -137,7 +137,7 @@ static const struct typinfo TypInfo[] = {
F_ARRAY_IN, F_ARRAY_OUT},
{"_char", 1002, CHAROID, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
F_ARRAY_IN, F_ARRAY_OUT},
- {"_aclitem", 1034, ACLITEMOID, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
+ {"_aclitem", 1034, ACLITEMOID, -1, false, TYPALIGN_INT64, TYPSTORAGE_EXTENDED, InvalidOid,
F_ARRAY_IN, F_ARRAY_OUT}
};
diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm
index 219af5884d9..20884f45bd8 100644
--- a/src/backend/catalog/Catalog.pm
+++ b/src/backend/catalog/Catalog.pm
@@ -464,9 +464,13 @@ sub GenerateArrayTypes
$array_type{typname} = '_' . $elem_type->{typname};
$array_type{typelem} = $elem_type->{typname};
- # Arrays require INT alignment, unless the element type requires
- # DOUBLE alignment.
- $array_type{typalign} = $elem_type->{typalign} eq 'd' ? 'd' : 'i';
+ # Arrays require INT alignment, unless the element type requires more.
+ $array_type{typalign} =
+ $elem_type->{typalign} eq 'l' ? 'l'
+ : (
+ $elem_type->{typalign} eq 'd' ? 'd'
+ : ( $elem_type->{typalign} eq 'm' ? 'm'
+ : 'i'));
# Fill in the rest of the array entry's fields.
foreach my $column (@$pgtype_schema)
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 606434823cf..27cc09a7680 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1075,7 +1075,7 @@ AddNewRelationType(const char *typeName,
NULL, /* default value - none */
NULL, /* default binary representation */
false, /* passed by reference */
- TYPALIGN_DOUBLE, /* alignment - must be the largest! */
+ TYPALIGN_MAX, /* alignment - must be the largest! */
TYPSTORAGE_EXTENDED, /* fully TOASTable */
-1, /* typmod */
0, /* array dimensions for typBaseType */
@@ -1399,7 +1399,7 @@ heap_create_with_catalog(const char *relname,
NULL, /* default value - none */
NULL, /* default binary representation */
false, /* passed by reference */
- TYPALIGN_DOUBLE, /* alignment - must be the largest! */
+ TYPALIGN_MAX, /* alignment - must be the largest! */
TYPSTORAGE_EXTENDED, /* fully TOASTable */
-1, /* typmod */
0, /* array dimensions for typBaseType */
diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c
index fc369c35aa6..f079fa32b40 100644
--- a/src/backend/catalog/pg_type.c
+++ b/src/backend/catalog/pg_type.c
@@ -287,7 +287,9 @@ TypeCreate(Oid newTypeOid,
}
else if (internalSize == (int16) sizeof(int64))
{
- if (alignment != TYPALIGN_DOUBLE)
+ /* We have to trust the user to get this distinction right ... */
+ if (!(alignment == TYPALIGN_INT64 ||
+ alignment == TYPALIGN_DOUBLE))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("alignment \"%c\" is invalid for passed-by-value type of size %d",
@@ -303,7 +305,10 @@ TypeCreate(Oid newTypeOid,
{
/* varlena types must have int align or better */
if (internalSize == -1 &&
- !(alignment == TYPALIGN_INT || alignment == TYPALIGN_DOUBLE))
+ !(alignment == TYPALIGN_INT ||
+ alignment == TYPALIGN_INT64 ||
+ alignment == TYPALIGN_DOUBLE ||
+ alignment == TYPALIGN_MAX))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("alignment \"%c\" is invalid for variable-length type",
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 288edb25f2f..2f919f764aa 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -117,6 +117,7 @@ static void makeMultirangeConstructors(const char *name, Oid namespace,
Oid multirangeOid, Oid rangeOid,
Oid rangeArrayOid,
Oid *mltrngConstruct0_p, Oid *mltrngConstruct1_p, Oid *mltrngConstruct2_p);
+static char containerAlignment(char elemalign);
static Oid findTypeInputFunction(List *procname, Oid typeOid);
static Oid findTypeOutputFunction(List *procname, Oid typeOid);
static Oid findTypeReceiveFunction(List *procname, Oid typeOid);
@@ -424,6 +425,9 @@ DefineType(ParseState *pstate, List *names, List *parameters)
pg_strcasecmp(a, "float8") == 0 ||
pg_strcasecmp(a, "pg_catalog.float8") == 0)
alignment = TYPALIGN_DOUBLE;
+ else if (pg_strcasecmp(a, "int8") == 0 ||
+ pg_strcasecmp(a, "pg_catalog.int8") == 0)
+ alignment = TYPALIGN_INT64;
else if (pg_strcasecmp(a, "int4") == 0 ||
pg_strcasecmp(a, "pg_catalog.int4") == 0)
alignment = TYPALIGN_INT;
@@ -433,6 +437,9 @@ DefineType(ParseState *pstate, List *names, List *parameters)
else if (pg_strcasecmp(a, "char") == 0 ||
pg_strcasecmp(a, "pg_catalog.bpchar") == 0)
alignment = TYPALIGN_CHAR;
+ else if (pg_strcasecmp(a, "max") == 0 ||
+ pg_strcasecmp(a, "pg_catalog.max") == 0)
+ alignment = TYPALIGN_MAX;
else
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -611,8 +618,8 @@ DefineType(ParseState *pstate, List *names, List *parameters)
*/
array_type = makeArrayTypeName(typeName, typeNamespace);
- /* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for arrays */
- alignment = (alignment == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
+ /* alignment must be TYPALIGN_INT or more for arrays */
+ alignment = containerAlignment(alignment);
TypeCreate(array_oid, /* force assignment of this type OID */
array_type, /* type name */
@@ -1095,8 +1102,8 @@ DefineDomain(ParseState *pstate, CreateDomainStmt *stmt)
*/
domainArrayName = makeArrayTypeName(domainName, domainNamespace);
- /* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for arrays */
- alignment = (alignment == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
+ /* alignment must be TYPALIGN_INT or more for arrays */
+ alignment = containerAlignment(alignment);
TypeCreate(domainArrayOid, /* force assignment of this type OID */
domainArrayName, /* type name */
@@ -1557,8 +1564,8 @@ DefineRange(ParseState *pstate, CreateRangeStmt *stmt)
get_typlenbyvalalign(rangeSubtype,
&subtyplen, &subtypbyval, &subtypalign);
- /* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for ranges */
- alignment = (subtypalign == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
+ /* alignment must be TYPALIGN_INT or more for ranges */
+ alignment = containerAlignment(subtypalign);
/* Allocate OID for array type, its multirange, and its multirange array */
rangeArrayOid = AssignTypeArrayOid();
@@ -2005,6 +2012,25 @@ makeMultirangeConstructors(const char *name, Oid namespace,
pfree(parameterModes);
}
+/*
+ * Compute the appropriate typalign for a container (array or range)
+ * given the typalign of its members. The container type requires at
+ * least int alignment, but more if the members need more.
+ */
+static char
+containerAlignment(char elemalign)
+{
+ switch (elemalign)
+ {
+ case TYPALIGN_INT64:
+ case TYPALIGN_DOUBLE:
+ case TYPALIGN_MAX:
+ return elemalign;
+ default:
+ return TYPALIGN_INT;
+ }
+}
+
/*
* Find suitable I/O and other support functions for a type.
*
diff --git a/src/backend/tsearch/ts_typanalyze.c b/src/backend/tsearch/ts_typanalyze.c
index 0c513d694e7..48ee050e37f 100644
--- a/src/backend/tsearch/ts_typanalyze.c
+++ b/src/backend/tsearch/ts_typanalyze.c
@@ -444,7 +444,7 @@ compute_tsvector_stats(VacAttrStats *stats,
stats->statypid[0] = TEXTOID;
stats->statyplen[0] = -1; /* typlen, -1 for varlena */
stats->statypbyval[0] = false;
- stats->statypalign[0] = 'i';
+ stats->statypalign[0] = TYPALIGN_INT;
}
}
else
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index da68915ee20..08e26335a95 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -3431,7 +3431,7 @@ construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
case INT8OID:
elmlen = sizeof(int64);
elmbyval = true;
- elmalign = TYPALIGN_DOUBLE;
+ elmalign = TYPALIGN_INT64;
break;
case NAMEOID:
diff --git a/src/backend/utils/adt/orderedsetaggs.c b/src/backend/utils/adt/orderedsetaggs.c
index 3b6da8e36ac..27b8cfa7064 100644
--- a/src/backend/utils/adt/orderedsetaggs.c
+++ b/src/backend/utils/adt/orderedsetaggs.c
@@ -1021,7 +1021,7 @@ percentile_cont_interval_multi_final(PG_FUNCTION_ARGS)
return percentile_cont_multi_final_common(fcinfo,
INTERVALOID,
/* hard-wired info on type interval */
- 16, false, TYPALIGN_DOUBLE,
+ 16, false, TYPALIGN_INT64,
interval_lerp);
}
diff --git a/src/backend/utils/adt/rangetypes_typanalyze.c b/src/backend/utils/adt/rangetypes_typanalyze.c
index 38d12dedbc5..278d4e6941a 100644
--- a/src/backend/utils/adt/rangetypes_typanalyze.c
+++ b/src/backend/utils/adt/rangetypes_typanalyze.c
@@ -398,7 +398,7 @@ compute_range_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
stats->statypid[slot_idx] = FLOAT8OID;
stats->statyplen[slot_idx] = sizeof(float8);
stats->statypbyval[slot_idx] = true;
- stats->statypalign[slot_idx] = 'd';
+ stats->statypalign[slot_idx] = TYPALIGN_DOUBLE;
/* Store the fraction of empty ranges */
emptyfrac = palloc_object(float4);
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index a3980e5535f..e550e9cf0a3 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -1580,7 +1580,7 @@ bootstrap_template1(void)
bki_lines = replace_token(bki_lines, "SIZEOF_POINTER", buf);
bki_lines = replace_token(bki_lines, "ALIGNOF_POINTER",
- (sizeof(Pointer) == 4) ? "i" : "d");
+ (sizeof(Pointer) == 4) ? "i" : "l");
bki_lines = replace_token(bki_lines, "POSTGRES",
escape_quotes_bki(username));
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 2bebefd0ba2..1b44c03170f 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -12652,8 +12652,12 @@ dumpBaseType(Archive *fout, const TypeInfo *tyinfo)
appendPQExpBufferStr(q, ",\n ALIGNMENT = int2");
else if (*typalign == TYPALIGN_INT)
appendPQExpBufferStr(q, ",\n ALIGNMENT = int4");
+ else if (*typalign == TYPALIGN_INT64)
+ appendPQExpBufferStr(q, ",\n ALIGNMENT = int8");
else if (*typalign == TYPALIGN_DOUBLE)
appendPQExpBufferStr(q, ",\n ALIGNMENT = double");
+ else if (*typalign == TYPALIGN_MAX)
+ appendPQExpBufferStr(q, ",\n ALIGNMENT = max");
if (*typstorage == TYPSTORAGE_PLAIN)
appendPQExpBufferStr(q, ",\n STORAGE = plain");
diff --git a/src/include/access/tupmacs.h b/src/include/access/tupmacs.h
index d64c18b950b..e7db125f627 100644
--- a/src/include/access/tupmacs.h
+++ b/src/include/access/tupmacs.h
@@ -92,9 +92,15 @@ typalign_to_alignby(char typalign)
case TYPALIGN_INT:
alignby = ALIGNOF_INT;
break;
+ case TYPALIGN_INT64:
+ alignby = ALIGNOF_INT64_T;
+ break;
case TYPALIGN_DOUBLE:
alignby = ALIGNOF_DOUBLE;
break;
+ case TYPALIGN_MAX:
+ alignby = MAXIMUM_ALIGNOF;
+ break;
default:
#ifndef FRONTEND
elog(ERROR, "invalid typalign value: %c", typalign);
diff --git a/src/include/c.h b/src/include/c.h
index c443e75b89f..c7956ce91bc 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -821,7 +821,7 @@ typedef NameData *Name;
#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
-#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
+#define INT64ALIGN(LEN) TYPEALIGN(ALIGNOF_INT64_T, (LEN))
#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
/* MAXALIGN covers only built-in types, not buffers */
@@ -833,7 +833,7 @@ typedef NameData *Name;
#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
-#define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN))
+#define INT64ALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT64_T, (LEN))
#define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
#define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
#define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_BUFFER, (LEN))
diff --git a/src/include/catalog/pg_type.dat b/src/include/catalog/pg_type.dat
index a1a753d1797..d511493f761 100644
--- a/src/include/catalog/pg_type.dat
+++ b/src/include/catalog/pg_type.dat
@@ -56,7 +56,7 @@
descr => '~18 digit integer, 8-byte storage',
typname => 'int8', typlen => '8', typbyval => 't',
typcategory => 'N', typinput => 'int8in', typoutput => 'int8out',
- typreceive => 'int8recv', typsend => 'int8send', typalign => 'd' },
+ typreceive => 'int8recv', typsend => 'int8send', typalign => 'l' },
{ oid => '21', array_type_oid => '1005',
descr => '-32 thousand to 32 thousand, 2-byte storage',
typname => 'int2', typlen => '2', typbyval => 't', typcategory => 'N',
@@ -116,22 +116,22 @@
typname => 'pg_type', typlen => '-1', typbyval => 'f', typtype => 'c',
typcategory => 'C', typrelid => 'pg_type', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
{ oid => '75', array_type_oid => '270',
typname => 'pg_attribute', typlen => '-1', typbyval => 'f', typtype => 'c',
typcategory => 'C', typrelid => 'pg_attribute', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
{ oid => '81', array_type_oid => '272',
typname => 'pg_proc', typlen => '-1', typbyval => 'f', typtype => 'c',
typcategory => 'C', typrelid => 'pg_proc', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
{ oid => '83', array_type_oid => '273',
typname => 'pg_class', typlen => '-1', typbyval => 'f', typtype => 'c',
typcategory => 'C', typrelid => 'pg_class', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
# OIDS 100 - 199
@@ -174,7 +174,7 @@
{ oid => '5069', array_type_oid => '271', descr => 'full transaction id',
typname => 'xid8', typlen => '8', typbyval => 't',
typcategory => 'U', typinput => 'xid8in', typoutput => 'xid8out',
- typreceive => 'xid8recv', typsend => 'xid8send', typalign => 'd' },
+ typreceive => 'xid8recv', typsend => 'xid8send', typalign => 'l' },
# OIDS 600 - 699
@@ -239,7 +239,7 @@
descr => 'monetary amounts, $d,ddd.cc',
typname => 'money', typlen => '8', typbyval => 't',
typcategory => 'N', typinput => 'cash_in', typoutput => 'cash_out',
- typreceive => 'cash_recv', typsend => 'cash_send', typalign => 'd' },
+ typreceive => 'cash_recv', typsend => 'cash_send', typalign => 'l' },
# OIDS 800 - 899
@@ -270,7 +270,7 @@
{ oid => '1033', array_type_oid => '1034', descr => 'access control list',
typname => 'aclitem', typlen => '16', typbyval => 'f', typcategory => 'U',
typinput => 'aclitemin', typoutput => 'aclitemout', typreceive => '-',
- typsend => '-', typalign => 'd' },
+ typsend => '-', typalign => 'l' },
{ oid => '1042', array_type_oid => '1014',
descr => '\'char(length)\' blank-padded string, fixed storage length',
typname => 'bpchar', typlen => '-1', typbyval => 'f', typcategory => 'S',
@@ -293,7 +293,7 @@
typname => 'time', typlen => '8', typbyval => 't',
typcategory => 'D', typinput => 'time_in', typoutput => 'time_out',
typreceive => 'time_recv', typsend => 'time_send', typmodin => 'timetypmodin',
- typmodout => 'timetypmodout', typalign => 'd' },
+ typmodout => 'timetypmodout', typalign => 'l' },
# OIDS 1100 - 1199
@@ -302,21 +302,21 @@
typcategory => 'D', typinput => 'timestamp_in', typoutput => 'timestamp_out',
typreceive => 'timestamp_recv', typsend => 'timestamp_send',
typmodin => 'timestamptypmodin', typmodout => 'timestamptypmodout',
- typalign => 'd' },
+ typalign => 'l' },
{ oid => '1184', array_type_oid => '1185',
descr => 'date and time with time zone',
typname => 'timestamptz', typlen => '8', typbyval => 't',
typcategory => 'D', typispreferred => 't', typinput => 'timestamptz_in',
typoutput => 'timestamptz_out', typreceive => 'timestamptz_recv',
typsend => 'timestamptz_send', typmodin => 'timestamptztypmodin',
- typmodout => 'timestamptztypmodout', typalign => 'd' },
+ typmodout => 'timestamptztypmodout', typalign => 'l' },
{ oid => '1186', array_type_oid => '1187',
descr => 'time interval, format \'number units ...\'',
typname => 'interval', typlen => '16', typbyval => 'f', typcategory => 'T',
typispreferred => 't', typinput => 'interval_in', typoutput => 'interval_out',
typreceive => 'interval_recv', typsend => 'interval_send',
typmodin => 'intervaltypmodin', typmodout => 'intervaltypmodout',
- typalign => 'd' },
+ typalign => 'l' },
# OIDS 1200 - 1299
@@ -326,7 +326,7 @@
typinput => 'timetz_in', typoutput => 'timetz_out',
typreceive => 'timetz_recv', typsend => 'timetz_send',
typmodin => 'timetztypmodin', typmodout => 'timetztypmodout',
- typalign => 'd' },
+ typalign => 'l' },
# OIDS 1500 - 1599
@@ -415,7 +415,7 @@
{ oid => '3220', array_type_oid => '3221', descr => 'PostgreSQL LSN',
typname => 'pg_lsn', typlen => '8', typbyval => 't',
typcategory => 'U', typinput => 'pg_lsn_in', typoutput => 'pg_lsn_out',
- typreceive => 'pg_lsn_recv', typsend => 'pg_lsn_send', typalign => 'd' },
+ typreceive => 'pg_lsn_recv', typsend => 'pg_lsn_send', typalign => 'l' },
# text search
{ oid => '3614', array_type_oid => '3643',
@@ -462,12 +462,12 @@
typname => 'txid_snapshot', typlen => '-1', typbyval => 'f',
typcategory => 'U', typinput => 'txid_snapshot_in',
typoutput => 'txid_snapshot_out', typreceive => 'txid_snapshot_recv',
- typsend => 'txid_snapshot_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'txid_snapshot_send', typalign => 'l', typstorage => 'x' },
{ oid => '5038', array_type_oid => '5039', descr => 'transaction snapshot',
typname => 'pg_snapshot', typlen => '-1', typbyval => 'f', typcategory => 'U',
typinput => 'pg_snapshot_in', typoutput => 'pg_snapshot_out',
typreceive => 'pg_snapshot_recv', typsend => 'pg_snapshot_send',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'l', typstorage => 'x' },
# range types
{ oid => '3904', array_type_oid => '3905', descr => 'range of integers',
@@ -485,13 +485,13 @@
typname => 'tsrange', typlen => '-1', typbyval => 'f', typtype => 'r',
typcategory => 'R', typinput => 'range_in', typoutput => 'range_out',
typreceive => 'range_recv', typsend => 'range_send',
- typanalyze => 'range_typanalyze', typalign => 'd', typstorage => 'x' },
+ typanalyze => 'range_typanalyze', typalign => 'l', typstorage => 'x' },
{ oid => '3910', array_type_oid => '3911',
descr => 'range of timestamps with time zone',
typname => 'tstzrange', typlen => '-1', typbyval => 'f', typtype => 'r',
typcategory => 'R', typinput => 'range_in', typoutput => 'range_out',
typreceive => 'range_recv', typsend => 'range_send',
- typanalyze => 'range_typanalyze', typalign => 'd', typstorage => 'x' },
+ typanalyze => 'range_typanalyze', typalign => 'l', typstorage => 'x' },
{ oid => '3912', array_type_oid => '3913', descr => 'range of dates',
typname => 'daterange', typlen => '-1', typbyval => 'f', typtype => 'r',
typcategory => 'R', typinput => 'range_in', typoutput => 'range_out',
@@ -501,7 +501,7 @@
typname => 'int8range', typlen => '-1', typbyval => 'f', typtype => 'r',
typcategory => 'R', typinput => 'range_in', typoutput => 'range_out',
typreceive => 'range_recv', typsend => 'range_send',
- typanalyze => 'range_typanalyze', typalign => 'd', typstorage => 'x' },
+ typanalyze => 'range_typanalyze', typalign => 'l', typstorage => 'x' },
# multirange types
{ oid => '4451', array_type_oid => '6150', descr => 'multirange of integers',
@@ -522,14 +522,14 @@
typcategory => 'R', typinput => 'multirange_in',
typoutput => 'multirange_out', typreceive => 'multirange_recv',
typsend => 'multirange_send', typanalyze => 'multirange_typanalyze',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'l', typstorage => 'x' },
{ oid => '4534', array_type_oid => '6153',
descr => 'multirange of timestamps with time zone',
typname => 'tstzmultirange', typlen => '-1', typbyval => 'f', typtype => 'm',
typcategory => 'R', typinput => 'multirange_in',
typoutput => 'multirange_out', typreceive => 'multirange_recv',
typsend => 'multirange_send', typanalyze => 'multirange_typanalyze',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'l', typstorage => 'x' },
{ oid => '4535', array_type_oid => '6155', descr => 'multirange of dates',
typname => 'datemultirange', typlen => '-1', typbyval => 'f', typtype => 'm',
typcategory => 'R', typinput => 'multirange_in',
@@ -541,7 +541,7 @@
typcategory => 'R', typinput => 'multirange_in',
typoutput => 'multirange_out', typreceive => 'multirange_recv',
typsend => 'multirange_send', typanalyze => 'multirange_typanalyze',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'l', typstorage => 'x' },
# pseudo-types
# types with typtype='p' represent various special cases in the type system.
@@ -556,14 +556,14 @@
typname => 'record', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typarray => '_record', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
# Arrays of records have typcategory P, so they can't be autogenerated.
{ oid => '2287',
typname => '_record', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typsubscript => 'array_subscript_handler',
typelem => 'record', typinput => 'array_in', typoutput => 'array_out',
typreceive => 'array_recv', typsend => 'array_send',
- typanalyze => 'array_typanalyze', typalign => 'd', typstorage => 'x' },
+ typanalyze => 'array_typanalyze', typalign => 'm', typstorage => 'x' },
{ oid => '2275', array_type_oid => '1263', descr => 'C-style string',
typname => 'cstring', typlen => '-2', typbyval => 'f', typtype => 'p',
typcategory => 'P', typinput => 'cstring_in', typoutput => 'cstring_out',
@@ -575,7 +575,7 @@
{ oid => '2277', descr => 'pseudo-type representing a polymorphic array type',
typname => 'anyarray', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typinput => 'anyarray_in', typoutput => 'anyarray_out',
- typreceive => 'anyarray_recv', typsend => 'anyarray_send', typalign => 'd',
+ typreceive => 'anyarray_recv', typsend => 'anyarray_send', typalign => 'm',
typstorage => 'x' },
{ oid => '2278',
descr => 'pseudo-type for the result of a function with no real result',
@@ -648,7 +648,7 @@
descr => 'pseudo-type representing a range over a polymorphic base type',
typname => 'anyrange', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typinput => 'anyrange_in', typoutput => 'anyrange_out',
- typreceive => '-', typsend => '-', typalign => 'd', typstorage => 'x' },
+ typreceive => '-', typsend => '-', typalign => 'm', typstorage => 'x' },
{ oid => '5077',
descr => 'pseudo-type representing a polymorphic common type',
typname => 'anycompatible', typlen => '4', typbyval => 't', typtype => 'p',
@@ -661,7 +661,7 @@
typtype => 'p', typcategory => 'P', typinput => 'anycompatiblearray_in',
typoutput => 'anycompatiblearray_out',
typreceive => 'anycompatiblearray_recv', typsend => 'anycompatiblearray_send',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'm', typstorage => 'x' },
{ oid => '5079',
descr => 'pseudo-type representing a polymorphic common type that is not an array',
typname => 'anycompatiblenonarray', typlen => '4', typbyval => 't',
@@ -673,19 +673,19 @@
typname => 'anycompatiblerange', typlen => '-1', typbyval => 'f',
typtype => 'p', typcategory => 'P', typinput => 'anycompatiblerange_in',
typoutput => 'anycompatiblerange_out', typreceive => '-', typsend => '-',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'm', typstorage => 'x' },
{ oid => '4537',
descr => 'pseudo-type representing a polymorphic base type that is a multirange',
typname => 'anymultirange', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typinput => 'anymultirange_in',
typoutput => 'anymultirange_out', typreceive => '-', typsend => '-',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'm', typstorage => 'x' },
{ oid => '4538',
descr => 'pseudo-type representing a multirange over a polymorphic common type',
typname => 'anycompatiblemultirange', typlen => '-1', typbyval => 'f',
typtype => 'p', typcategory => 'P', typinput => 'anycompatiblemultirange_in',
typoutput => 'anycompatiblemultirange_out', typreceive => '-', typsend => '-',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'm', typstorage => 'x' },
{ oid => '4600', descr => 'pseudo-type representing BRIN bloom summary',
typname => 'pg_brin_bloom_summary', typlen => '-1', typbyval => 'f',
typcategory => 'Z', typinput => 'brin_bloom_summary_in',
@@ -704,5 +704,5 @@
descr => 'object identifier(oid8), 8 bytes',
typname => 'oid8', typlen => '8', typbyval => 't', typcategory => 'N',
typinput => 'oid8in', typoutput => 'oid8out', typreceive => 'oid8recv',
- typsend => 'oid8send', typalign => 'd' },
+ typsend => 'oid8send', typalign => 'l' },
]
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 70d4a20c02b..b749a47d651 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -302,7 +302,9 @@ MAKE_SYSCACHE(TYPENAMENSP, pg_type_typname_nsp_index, 64);
#define TYPALIGN_CHAR 'c' /* char alignment (i.e. unaligned) */
#define TYPALIGN_SHORT 's' /* short alignment (typically 2 bytes) */
#define TYPALIGN_INT 'i' /* int alignment (typically 4 bytes) */
+#define TYPALIGN_INT64 'l' /* int64 alignment (often 8 bytes) */
#define TYPALIGN_DOUBLE 'd' /* double alignment (often 8 bytes) */
+#define TYPALIGN_MAX 'm' /* maximum alignment (usually 8 bytes) */
#define TYPSTORAGE_PLAIN 'p' /* type not prepared for toasting */
#define TYPSTORAGE_EXTERNAL 'e' /* toastable, don't try to compress */
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 339268dc8ef..5699c033ade 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -12,9 +12,6 @@
/* The normal alignment of `int64_t', in bytes. */
#undef ALIGNOF_INT64_T
-/* The normal alignment of `long', in bytes. */
-#undef ALIGNOF_LONG
-
/* The normal alignment of `PG_INT128_TYPE', in bytes. */
#undef ALIGNOF_PG_INT128_TYPE
diff --git a/src/pl/plpython/plpy_typeio.c b/src/pl/plpython/plpy_typeio.c
index 44055de6aeb..d4dbb6b5b85 100644
--- a/src/pl/plpython/plpy_typeio.c
+++ b/src/pl/plpython/plpy_typeio.c
@@ -329,7 +329,7 @@ PLy_output_setup_func(PLyObToDatum *arg, MemoryContext arg_mcxt,
/* hard-wired knowledge about type RECORD: */
arg->typbyval = false;
arg->typlen = -1;
- arg->typalign = TYPALIGN_DOUBLE;
+ arg->typalign = TYPALIGN_MAX;
}
/*
@@ -452,7 +452,7 @@ PLy_input_setup_func(PLyDatumToOb *arg, MemoryContext arg_mcxt,
/* hard-wired knowledge about type RECORD: */
arg->typbyval = false;
arg->typlen = -1;
- arg->typalign = TYPALIGN_DOUBLE;
+ arg->typalign = TYPALIGN_MAX;
}
/*
diff --git a/src/test/regress/expected/create_type.out b/src/test/regress/expected/create_type.out
index 5181c4290b4..07919b4fe0e 100644
--- a/src/test/regress/expected/create_type.out
+++ b/src/test/regress/expected/create_type.out
@@ -49,6 +49,7 @@ CREATE TYPE city_budget (
output = int44out,
element = int4,
category = 'x', -- just to verify the system will take it
+ alignment = max, -- ditto (overspecifying alignment is safe)
preferred = true -- ditto
);
-- Test creation and destruction of shell types
diff --git a/src/test/regress/expected/float8.out b/src/test/regress/expected/float8.out
index 9c519f1a1a1..a688cbc3c83 100644
--- a/src/test/regress/expected/float8.out
+++ b/src/test/regress/expected/float8.out
@@ -1088,8 +1088,10 @@ LINE 1: ...8 (input = xfloat8in, output = xfloat8out, like = no_such_ty...
create type xfloat8 (input = xfloat8in, output = xfloat8out, like = float8);
create cast (xfloat8 as float8) without function;
create cast (float8 as xfloat8) without function;
-create cast (xfloat8 as bigint) without function;
-create cast (bigint as xfloat8) without function;
+-- this hack depends on bigint and float8 having the same pass-by-value-ness:
+create function bigint_xfloat8(bigint) returns xfloat8 immutable strict
+ language internal as 'int8up';
+create cast (bigint as xfloat8) with function bigint_xfloat8(bigint);
-- float8: seeeeeee eeeeeeee eeeeeeee mmmmmmmm mmmmmmmm(x4)
-- we don't care to assume the platform's strtod() handles subnormals
-- correctly; those are "use at your own risk". However we do test
@@ -1503,5 +1505,5 @@ DETAIL: drop cascades to function xfloat8in(cstring)
drop cascades to function xfloat8out(xfloat8)
drop cascades to cast from xfloat8 to double precision
drop cascades to cast from double precision to xfloat8
-drop cascades to cast from xfloat8 to bigint
+drop cascades to function bigint_xfloat8(bigint)
drop cascades to cast from bigint to xfloat8
diff --git a/src/test/regress/expected/type_sanity.out b/src/test/regress/expected/type_sanity.out
index 1d21d3eb446..936fa36a600 100644
--- a/src/test/regress/expected/type_sanity.out
+++ b/src/test/regress/expected/type_sanity.out
@@ -23,7 +23,7 @@ WHERE t1.typnamespace = 0 OR
(t1.typlen <= 0 AND t1.typlen != -1 AND t1.typlen != -2) OR
(t1.typtype not in ('b', 'c', 'd', 'e', 'm', 'p', 'r')) OR
NOT t1.typisdefined OR
- (t1.typalign not in ('c', 's', 'i', 'd')) OR
+ (t1.typalign not in ('c', 's', 'i', 'l', 'd', 'm')) OR
(t1.typstorage not in ('p', 'x', 'e', 'm'));
oid | typname
-----+---------
@@ -36,7 +36,7 @@ WHERE t1.typbyval AND
(t1.typlen != 1 OR t1.typalign != 'c') AND
(t1.typlen != 2 OR t1.typalign != 's') AND
(t1.typlen != 4 OR t1.typalign != 'i') AND
- (t1.typlen != 8 OR t1.typalign != 'd');
+ (t1.typlen != 8 OR (t1.typalign != 'l' AND t1.typalign != 'd'));
oid | typname
-----+---------
(0 rows)
@@ -108,6 +108,8 @@ FROM pg_type as t1
LEFT JOIN pg_type as t2 ON rngsubtype = t2.oid
WHERE t1.typtype = 'r' AND
(t1.typalign != (CASE WHEN t2.typalign = 'd' THEN 'd'::"char"
+ WHEN t2.typalign = 'l' THEN 'l'::"char"
+ WHEN t2.typalign = 'm' THEN 'm'::"char"
ELSE 'i'::"char" END)
OR t2.oid IS NULL);
oid | typname | typalign | typname | typalign
@@ -423,6 +425,8 @@ SELECT t1.oid, t1.typname, t1.typalign, t2.typname, t2.typalign
FROM pg_type AS t1, pg_type AS t2
WHERE t1.typarray = t2.oid AND
t2.typalign != (CASE WHEN t1.typalign = 'd' THEN 'd'::"char"
+ WHEN t1.typalign = 'l' THEN 'l'::"char"
+ WHEN t1.typalign = 'm' THEN 'm'::"char"
ELSE 'i'::"char" END);
oid | typname | typalign | typname | typalign
-----+---------+----------+---------+----------
diff --git a/src/test/regress/sql/create_type.sql b/src/test/regress/sql/create_type.sql
index c25018029c2..94c5b949c25 100644
--- a/src/test/regress/sql/create_type.sql
+++ b/src/test/regress/sql/create_type.sql
@@ -47,6 +47,7 @@ CREATE TYPE city_budget (
output = int44out,
element = int4,
category = 'x', -- just to verify the system will take it
+ alignment = max, -- ditto (overspecifying alignment is safe)
preferred = true -- ditto
);
diff --git a/src/test/regress/sql/float8.sql b/src/test/regress/sql/float8.sql
index 0ef271f2702..c6b59a322ab 100644
--- a/src/test/regress/sql/float8.sql
+++ b/src/test/regress/sql/float8.sql
@@ -355,8 +355,10 @@ create type xfloat8 (input = xfloat8in, output = xfloat8out, like = no_such_type
create type xfloat8 (input = xfloat8in, output = xfloat8out, like = float8);
create cast (xfloat8 as float8) without function;
create cast (float8 as xfloat8) without function;
-create cast (xfloat8 as bigint) without function;
-create cast (bigint as xfloat8) without function;
+-- this hack depends on bigint and float8 having the same pass-by-value-ness:
+create function bigint_xfloat8(bigint) returns xfloat8 immutable strict
+ language internal as 'int8up';
+create cast (bigint as xfloat8) with function bigint_xfloat8(bigint);
-- float8: seeeeeee eeeeeeee eeeeeeee mmmmmmmm mmmmmmmm(x4)
diff --git a/src/test/regress/sql/type_sanity.sql b/src/test/regress/sql/type_sanity.sql
index 95d5b6e0915..625305c42bc 100644
--- a/src/test/regress/sql/type_sanity.sql
+++ b/src/test/regress/sql/type_sanity.sql
@@ -28,7 +28,7 @@ WHERE t1.typnamespace = 0 OR
(t1.typlen <= 0 AND t1.typlen != -1 AND t1.typlen != -2) OR
(t1.typtype not in ('b', 'c', 'd', 'e', 'm', 'p', 'r')) OR
NOT t1.typisdefined OR
- (t1.typalign not in ('c', 's', 'i', 'd')) OR
+ (t1.typalign not in ('c', 's', 'i', 'l', 'd', 'm')) OR
(t1.typstorage not in ('p', 'x', 'e', 'm'));
-- Look for "pass by value" types that can't be passed by value.
@@ -39,7 +39,7 @@ WHERE t1.typbyval AND
(t1.typlen != 1 OR t1.typalign != 'c') AND
(t1.typlen != 2 OR t1.typalign != 's') AND
(t1.typlen != 4 OR t1.typalign != 'i') AND
- (t1.typlen != 8 OR t1.typalign != 'd');
+ (t1.typlen != 8 OR (t1.typalign != 'l' AND t1.typalign != 'd'));
-- Look for "toastable" types that aren't varlena.
@@ -90,6 +90,8 @@ FROM pg_type as t1
LEFT JOIN pg_type as t2 ON rngsubtype = t2.oid
WHERE t1.typtype = 'r' AND
(t1.typalign != (CASE WHEN t2.typalign = 'd' THEN 'd'::"char"
+ WHEN t2.typalign = 'l' THEN 'l'::"char"
+ WHEN t2.typalign = 'm' THEN 'm'::"char"
ELSE 'i'::"char" END)
OR t2.oid IS NULL);
@@ -302,6 +304,8 @@ SELECT t1.oid, t1.typname, t1.typalign, t2.typname, t2.typalign
FROM pg_type AS t1, pg_type AS t2
WHERE t1.typarray = t2.oid AND
t2.typalign != (CASE WHEN t1.typalign = 'd' THEN 'd'::"char"
+ WHEN t1.typalign = 'l' THEN 'l'::"char"
+ WHEN t1.typalign = 'm' THEN 'm'::"char"
ELSE 'i'::"char" END);
-- Check for typelem set without a handler
--
2.43.7
Re: Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
I wrote:
> I think this might be about ready to go, unless somebody has
> a better idea than 'l' for the catalog representation of
> TYPALIGN_INT64.
I realized that there is more to consider here than we'd thought.
In particular, while we've mainly worried about what happens with
system catalog row layout, the change I've proposed here very
likely changes row layout in user tables, if we are on a platform
where TYPALIGN_INT64 != TYPALIGN_DOUBLE. So this is a pg_upgrade
breaking change for such platforms.
Maybe this is another reason to decide that AIX isn't worth
re-supporting: if there are any AIX users out there who still care,
the prospect of a forced dump-and-reload might be enough to convince
them that they might as well migrate to a more modern platform while
they are at it. Not sure.
If we do want to go forward with this, it would make sense to
adjust pg_control to store MAXALIGN, TYPALIGN_DOUBLE, and
TYPALIGN_INT64 separately, instead of
/*
* This data is used to check for hardware-architecture compatibility of
* the database and the backend executable. We need not check endianness
* explicitly, since the pg_control version will surely look wrong to a
* machine of different endianness, but we do need to worry about MAXALIGN
* and floating-point format. (Note: storage layout nominally also
* depends on SHORTALIGN and INTALIGN, but in practice these are the same
* on all architectures of interest.)
*
* Testing just one double value is not a very bulletproof test for
* floating-point compatibility, but it will catch most cases.
*/
uint32 maxAlign; /* alignment requirement for tuples */
double floatFormat; /* constant 1234567.0 */
#define FLOATFORMAT_VALUE 1234567.0
(Given that we've now pretty much locked in on IEEE float format,
I suspect floatFormat isn't pulling its weight anymore, but
perhaps that's a separate discussion.)
regards, tom lane
Re: Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
I wrote:
> Here's a v2 responding to your suggestions. 0001 refactors
> att_align_nominal(), and then 0002 is nearly the same as the
> prior patch except for rebasing over that change.
I did some simple benchmarking and convinced myself that v2-0001
is a measurable win performance-wise even as things stand.
This test case spends nearly all its time in ExecEvalScalarArrayOp,
which has one of the loops improved by v2-0001:
\timing on
do $$
declare a int8[]; i int8 := 1; b bool;
begin
while i < 10000 loop
a[i] := i;
i := i+1;
end loop;
for j in 1..10 loop
for k in 1..10000 loop
b := (k = any(a));
end loop;
end loop;
end $$;
I see about 10% improvement in runtime with 0001 compared to HEAD.
So I'm inclined to go ahead and push that patch, and then return
to considering what we're going to do about int8 vs. double
alignment.
regards, tom lane
Re: Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
I pushed the att_align_nominal() refactoring, since that seems
to be a win whether we go forward with the rest of this or not.
Attached a v3 of the main patch (now again numbered 0001), plus
new work in 0002 that adds the two new alignment values to
pg_control and insists on a match before pg_upgrade'ing.
As I mentioned, this'd result in not being able to pg_upgrade
from old versions to v19 on AIX, though everywhere else it
should be fine.
0001 is the same as before except for one change: I modified the
test in CreateCast that checks whether a binary-compatible cast
is allowable. I did that because I hit errors in cross-version
upgrade testing. The regression tests do this:
create type int8alias1 (..., like int8);
create cast (int8 as int8alias1) without function;
which seems perfectly legit, but the cast fails dump/reload.
That's because we don't remember the "like" clause as such,
so the dump of int8alias1 from an existing branch will say
alignment = double, and then that doesn't match int8's new
alignment = int64.
Of course we could fix the cross-version tests by teaching
AdjustUpgrade.pm to drop these casts, but I think this is
telling us about a real usability gotcha that is likely
to bite users. A closely related issue is the change I'd
already had to make in regression/sql/float8.sql to not
try to cast bigint to float8 without function; that used
to work but doesn't with the new typalign values.
What I did below is to instead insist on a match of the represented
alignment requirement:
- typ1align != typ2align)
+ typalign_to_alignby(typ1align) != typalign_to_alignby(typ2align))
I'm not totally sold on that particular formulation, however.
For one thing it feels a bit too loose: on most machines it'd
allow alignment = max to match int64 or double, and I'm not
sure we want that. For another, it makes the allowable casts
platform-dependent. With the v3 code, we could skip changing
float8.sql on most platforms, but it'd still fail on AIX.
An alternative I've been thinking about, but haven't quite
convinced myself about, is: for pass-by-value types, why do
we need to insist on alignment match at all? Once the value
is in Datum format it doesn't matter, and for purposes of
a binary-compatible cast the input and output are always in
Datum format. So I was thinking about
- typ1align != typ2align)
+ (typ1align != typ2align && !typ1byval))
which'd allow all these cases to pass without SQL-code changes.
Is there a hole in that?
An even weaker restriction would be "allow if alignby matches
or if !byval", but I'm not sure we need to go there in practice.
It'd re-introduce the problem of the test being platform dependent,
which doesn't seem great.
I'd expect to squash these into one commit in the end, but I kept
0002 separate for ease of review, since 0001 is the same as before
except for the CreateCast diff.
Thoughts?
regards, tom lane
From a9ac1f40cf0dbdb68178ff306a80e76161ba088c Mon Sep 17 00:00:00 2001
From: Tom Lane
Date: Mon, 2 Feb 2026 15:22:07 -0500
Subject: [PATCH v3 1/2] Decouple our alignment assumptions about int64 and
double.
Up to now we have assumed that int64 and double have the same
alignment requirement, but there are platforms on which that's
not true (notably AIX). This assumption is a bit of a wart anyway,
since it leads to confusion about which alignment setting to use.
Let's break that apart.
We actually need to split TYPALIGN_DOUBLE into three values not
two, because we need a representation for "the maximum alignment
on this platform"; composite types need to use that setting.
So this patch invents TYPALIGN_INT64 and TYPALIGN_MAX, and
propagates those into all the necessary places. It's pretty
straightforward really, though it's certainly possible I missed
a few places to change.
One of the concerns that prevented this from being done long
ago was not wanting to add overhead to tuple forming/deforming.
However that concern seems gone now, because we map TYPALIGN_xxx
values to numeric alignments in typalign_to_alignby() which
we can usually avoid using within performance-critical loops.
I weakened CreateCast's criteria for whether a CAST WITHOUT FUNCTION
is okay so that it no longer demands an exact typalign match,
but rather a match of the represented alignby constraint.
Without this, we'd get odd dump/reload failures: for example,
a type created "LIKE int8" would have typalign 'd' when being
brought forward from an older release, and then we would reject
a binary cast between it and int8 (which now has typalign 'l').
So we need to weaken that check somehow, although perhaps this
formulation isn't the best possible.
An issue not resolved here is that we are not consistent
about the pg_type typlen/typalign values for polymorphic
types (the "any*" types). Those shouldn't actually matter,
but why aren't they all alike?
Side notes:
I got rid of LONGALIGN[_DOWN] along with the configure probes
for ALIGNOF_LONG. We were not using those anywhere and it
seems highly unlikely that we'd do so in future.
bootstrap.c turns out to have had the wrong alignment value
for _aclitem; seems that was missed when we widened AclMode
to 64 bits. AFAICT the value wasn't used so there were no
ill effects.
I fixed a couple of places that were using hard-coded values
when they could have used TYPALIGN_xxx macros.
This will require a catversion bump.
Author: Tom Lane
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/1127261.1769649624@sss.pgh.pa.us
---
configure | 64 +++----------------
configure.ac | 30 +++------
doc/src/sgml/catalogs.sgml | 8 ++-
doc/src/sgml/ref/create_type.sgml | 9 ++-
meson.build | 31 ++++-----
src/backend/access/common/tupdesc.c | 2 +-
src/backend/bootstrap/bootstrap.c | 4 +-
src/backend/catalog/Catalog.pm | 10 ++-
src/backend/catalog/heap.c | 4 +-
src/backend/catalog/pg_type.c | 9 ++-
src/backend/commands/functioncmds.c | 14 +++-
src/backend/commands/typecmds.c | 38 +++++++++--
src/backend/tsearch/ts_typanalyze.c | 2 +-
src/backend/utils/adt/arrayfuncs.c | 2 +-
src/backend/utils/adt/orderedsetaggs.c | 2 +-
src/backend/utils/adt/rangetypes_typanalyze.c | 2 +-
src/bin/initdb/initdb.c | 2 +-
src/bin/pg_dump/pg_dump.c | 4 ++
src/include/access/tupmacs.h | 6 ++
src/include/c.h | 4 +-
src/include/catalog/pg_type.dat | 62 +++++++++---------
src/include/catalog/pg_type.h | 2 +
src/include/pg_config.h.in | 3 -
src/pl/plpython/plpy_typeio.c | 4 +-
src/test/regress/expected/create_type.out | 1 +
src/test/regress/expected/float8.out | 8 ++-
src/test/regress/expected/type_sanity.out | 8 ++-
src/test/regress/sql/create_type.sql | 1 +
src/test/regress/sql/float8.sql | 6 +-
src/test/regress/sql/type_sanity.sql | 8 ++-
30 files changed, 183 insertions(+), 167 deletions(-)
diff --git a/configure b/configure
index a10a2c85c6a..5adfb3eba45 100755
--- a/configure
+++ b/configure
@@ -17095,41 +17095,6 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
-# The cast to long int works around a bug in the HP C Compiler,
-# see AC_CHECK_SIZEOF for more information.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of long" >&5
-$as_echo_n "checking alignment of long... " >&6; }
-if ${ac_cv_alignof_long+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- if ac_fn_c_compute_int "$LINENO" "(long int) offsetof (ac__type_alignof_, y)" "ac_cv_alignof_long" "$ac_includes_default
-#ifndef offsetof
-# define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
-#endif
-typedef struct { char x; long y; } ac__type_alignof_;"; then :
-
-else
- if test "$ac_cv_type_long" = yes; then
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error 77 "cannot compute alignment of long
-See \`config.log' for more details" "$LINENO" 5; }
- else
- ac_cv_alignof_long=0
- fi
-fi
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_alignof_long" >&5
-$as_echo "$ac_cv_alignof_long" >&6; }
-
-
-
-cat >>confdefs.h <<_ACEOF
-#define ALIGNOF_LONG $ac_cv_alignof_long
-_ACEOF
-
-
# The cast to long int works around a bug in the HP C Compiler,
# see AC_CHECK_SIZEOF for more information.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of int64_t" >&5
@@ -17203,27 +17168,16 @@ _ACEOF
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that long's alignment is at least as strong as
-# char, short, or int. Note that we intentionally do not consider any types
-# wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
-# much of a penalty for disk and memory space.
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) Note that we intentionally do not consider any types wider
+# than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much
+# of a penalty for disk and memory space.
-MAX_ALIGNOF=$ac_cv_alignof_double
-
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
- as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
- as_fn_error $? "alignment of 'int64_t' is greater than the alignment of 'double'" "$LINENO" 5
+if test $ac_cv_alignof_int64_t -gt $ac_cv_alignof_double ; then
+ MAX_ALIGNOF=$ac_cv_alignof_int64_t
+else
+ MAX_ALIGNOF=$ac_cv_alignof_double
fi
cat >>confdefs.h <<_ACEOF
diff --git a/configure.ac b/configure.ac
index 814e64a967e..a5eab2e5fff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2031,33 +2031,21 @@ AC_CHECK_SIZEOF([intmax_t])
AC_CHECK_ALIGNOF(short)
AC_CHECK_ALIGNOF(int)
-AC_CHECK_ALIGNOF(long)
AC_CHECK_ALIGNOF(int64_t)
AC_CHECK_ALIGNOF(double)
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that long's alignment is at least as strong as
-# char, short, or int. Note that we intentionally do not consider any types
-# wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
-# much of a penalty for disk and memory space.
-
-MAX_ALIGNOF=$ac_cv_alignof_double
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) Note that we intentionally do not consider any types wider
+# than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much
+# of a penalty for disk and memory space.
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
- AC_MSG_ERROR([alignment of 'long' is greater than the alignment of 'double'])
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
- AC_MSG_ERROR([alignment of 'int64_t' is greater than the alignment of 'double'])
+if test $ac_cv_alignof_int64_t -gt $ac_cv_alignof_double ; then
+ MAX_ALIGNOF=$ac_cv_alignof_int64_t
+else
+ MAX_ALIGNOF=$ac_cv_alignof_double
fi
AC_DEFINE_UNQUOTED(MAXIMUM_ALIGNOF, $MAX_ALIGNOF, [Define as the maximum alignment requirement of any C data type.])
diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index 332193565e2..12608d00a18 100644
--- a/doc/src/sgml/catalogs.sgml
+++ b/doc/src/sgml/catalogs.sgml
@@ -9567,7 +9567,13 @@ SCRAM-SHA-256$<iteration count>:&l
i = int alignment (4 bytes on most machines).
- d = double alignment (8 bytes on many machines, but by no means all).
+ l = int64 alignment (8 bytes on most machines, but by no means all).
+
+
+ d = double alignment (8 bytes on most machines, but by no means all).
+
+
+ m = maximum alignment (8 bytes on most machines).
diff --git a/doc/src/sgml/ref/create_type.sgml b/doc/src/sgml/ref/create_type.sgml
index 994dfc65268..006db624094 100644
--- a/doc/src/sgml/ref/create_type.sgml
+++ b/doc/src/sgml/ref/create_type.sgml
@@ -748,8 +748,15 @@ CREATE TYPE name
The storage alignment requirement of the data type. If specified,
it must be char, int2,
- int4, or double; the
+ int4, int8,
+ double, or max; the
default is int4.
+ int8 and double usually
+ have the same behavior, but there are platforms on which they are
+ different because integer and floating-point values have different
+ requirements. max means the maximum alignment
+ requirement for any of these types; it is often used for container
+ types such as records.
diff --git a/meson.build b/meson.build
index df907b62da3..bb17859fee4 100644
--- a/meson.build
+++ b/meson.build
@@ -1798,32 +1798,27 @@ endif
# Determine memory alignment requirements for the basic C data types.
-alignof_types = ['short', 'int', 'long', 'double']
+alignof_types = ['short', 'int', 'int64_t', 'double']
foreach t : alignof_types
- align = cc.alignment(t, args: test_c_args)
+ align = cc.alignment(t, args: test_c_args, prefix: '#include ')
cdata.set('ALIGNOF_@0@'.format(t.to_upper()), align)
endforeach
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that int64_t's alignment is at least as strong
-# as long, char, short, or int. Note that we intentionally do not consider
-# any types wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8
-# would be too much of a penalty for disk and memory space.
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) Note that we intentionally do not consider any types wider
+# than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much
+# of a penalty for disk and memory space.
+
+alignof_int64_t = cdata.get('ALIGNOF_INT64_T')
alignof_double = cdata.get('ALIGNOF_DOUBLE')
-if cc.alignment('int64_t', args: test_c_args, prefix: '#include ') > alignof_double
- error('alignment of int64_t is greater than the alignment of double')
+if alignof_int64_t > alignof_double
+ cdata.set('MAXIMUM_ALIGNOF', alignof_int64_t)
+else
+ cdata.set('MAXIMUM_ALIGNOF', alignof_double)
endif
-cdata.set('MAXIMUM_ALIGNOF', alignof_double)
cdata.set('SIZEOF_LONG', cc.sizeof('long', args: test_c_args))
cdata.set('SIZEOF_LONG_LONG', cc.sizeof('long long', args: test_c_args))
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index b69d10f0a45..47b9f8b5459 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -977,7 +977,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
case INT8OID:
att->attlen = 8;
att->attbyval = true;
- att->attalign = TYPALIGN_DOUBLE;
+ att->attalign = TYPALIGN_INT64;
att->attstorage = TYPSTORAGE_PLAIN;
att->attcompression = InvalidCompressionMethod;
att->attcollation = InvalidOid;
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index dd57624b4f9..7a3a13a6ec7 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -115,7 +115,7 @@ static const struct typinfo TypInfo[] = {
F_TEXTIN, F_TEXTOUT},
{"oid", OIDOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_OIDIN, F_OIDOUT},
- {"oid8", OID8OID, 0, 8, true, TYPALIGN_DOUBLE, TYPSTORAGE_PLAIN, InvalidOid,
+ {"oid8", OID8OID, 0, 8, true, TYPALIGN_INT64, TYPSTORAGE_PLAIN, InvalidOid,
F_OID8IN, F_OID8OUT},
{"tid", TIDOID, 0, 6, false, TYPALIGN_SHORT, TYPSTORAGE_PLAIN, InvalidOid,
F_TIDIN, F_TIDOUT},
@@ -137,7 +137,7 @@ static const struct typinfo TypInfo[] = {
F_ARRAY_IN, F_ARRAY_OUT},
{"_char", 1002, CHAROID, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
F_ARRAY_IN, F_ARRAY_OUT},
- {"_aclitem", 1034, ACLITEMOID, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
+ {"_aclitem", 1034, ACLITEMOID, -1, false, TYPALIGN_INT64, TYPSTORAGE_EXTENDED, InvalidOid,
F_ARRAY_IN, F_ARRAY_OUT}
};
diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm
index 219af5884d9..20884f45bd8 100644
--- a/src/backend/catalog/Catalog.pm
+++ b/src/backend/catalog/Catalog.pm
@@ -464,9 +464,13 @@ sub GenerateArrayTypes
$array_type{typname} = '_' . $elem_type->{typname};
$array_type{typelem} = $elem_type->{typname};
- # Arrays require INT alignment, unless the element type requires
- # DOUBLE alignment.
- $array_type{typalign} = $elem_type->{typalign} eq 'd' ? 'd' : 'i';
+ # Arrays require INT alignment, unless the element type requires more.
+ $array_type{typalign} =
+ $elem_type->{typalign} eq 'l' ? 'l'
+ : (
+ $elem_type->{typalign} eq 'd' ? 'd'
+ : ( $elem_type->{typalign} eq 'm' ? 'm'
+ : 'i'));
# Fill in the rest of the array entry's fields.
foreach my $column (@$pgtype_schema)
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 606434823cf..27cc09a7680 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1075,7 +1075,7 @@ AddNewRelationType(const char *typeName,
NULL, /* default value - none */
NULL, /* default binary representation */
false, /* passed by reference */
- TYPALIGN_DOUBLE, /* alignment - must be the largest! */
+ TYPALIGN_MAX, /* alignment - must be the largest! */
TYPSTORAGE_EXTENDED, /* fully TOASTable */
-1, /* typmod */
0, /* array dimensions for typBaseType */
@@ -1399,7 +1399,7 @@ heap_create_with_catalog(const char *relname,
NULL, /* default value - none */
NULL, /* default binary representation */
false, /* passed by reference */
- TYPALIGN_DOUBLE, /* alignment - must be the largest! */
+ TYPALIGN_MAX, /* alignment - must be the largest! */
TYPSTORAGE_EXTENDED, /* fully TOASTable */
-1, /* typmod */
0, /* array dimensions for typBaseType */
diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c
index fc369c35aa6..f079fa32b40 100644
--- a/src/backend/catalog/pg_type.c
+++ b/src/backend/catalog/pg_type.c
@@ -287,7 +287,9 @@ TypeCreate(Oid newTypeOid,
}
else if (internalSize == (int16) sizeof(int64))
{
- if (alignment != TYPALIGN_DOUBLE)
+ /* We have to trust the user to get this distinction right ... */
+ if (!(alignment == TYPALIGN_INT64 ||
+ alignment == TYPALIGN_DOUBLE))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("alignment \"%c\" is invalid for passed-by-value type of size %d",
@@ -303,7 +305,10 @@ TypeCreate(Oid newTypeOid,
{
/* varlena types must have int align or better */
if (internalSize == -1 &&
- !(alignment == TYPALIGN_INT || alignment == TYPALIGN_DOUBLE))
+ !(alignment == TYPALIGN_INT ||
+ alignment == TYPALIGN_INT64 ||
+ alignment == TYPALIGN_DOUBLE ||
+ alignment == TYPALIGN_MAX))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("alignment \"%c\" is invalid for variable-length type",
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index a516b037dea..0945a05f7ad 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1696,14 +1696,22 @@ CreateCast(CreateCastStmt *stmt)
/*
* Also, insist that the types match as to size, alignment, and
* pass-by-value attributes; this provides at least a crude check that
- * they have similar representations. A pair of types that fail this
- * test should certainly not be equated.
+ * they have similar representations. A pair of types that don't
+ * match on typlen or typbyval should certainly not be equated. It's
+ * a little trickier for typalign, because with the introduction of
+ * TYPALIGN_INT64 (which usually represents the same alignment
+ * requirement as TYPALIGN_DOUBLE) we don't want to reject a cast
+ * between two types that have the same physical alignment requirement
+ * even if it's spelled differently. So compare their alignby values.
+ * (This means that two types might be considered binary-compatible on
+ * some platforms but not others, which is not great; but stricter
+ * enforcement would lead to unnecessary dump/reload failures.)
*/
get_typlenbyvalalign(sourcetypeid, &typ1len, &typ1byval, &typ1align);
get_typlenbyvalalign(targettypeid, &typ2len, &typ2byval, &typ2align);
if (typ1len != typ2len ||
typ1byval != typ2byval ||
- typ1align != typ2align)
+ typalign_to_alignby(typ1align) != typalign_to_alignby(typ2align))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("source and target data types are not physically compatible")));
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 288edb25f2f..2f919f764aa 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -117,6 +117,7 @@ static void makeMultirangeConstructors(const char *name, Oid namespace,
Oid multirangeOid, Oid rangeOid,
Oid rangeArrayOid,
Oid *mltrngConstruct0_p, Oid *mltrngConstruct1_p, Oid *mltrngConstruct2_p);
+static char containerAlignment(char elemalign);
static Oid findTypeInputFunction(List *procname, Oid typeOid);
static Oid findTypeOutputFunction(List *procname, Oid typeOid);
static Oid findTypeReceiveFunction(List *procname, Oid typeOid);
@@ -424,6 +425,9 @@ DefineType(ParseState *pstate, List *names, List *parameters)
pg_strcasecmp(a, "float8") == 0 ||
pg_strcasecmp(a, "pg_catalog.float8") == 0)
alignment = TYPALIGN_DOUBLE;
+ else if (pg_strcasecmp(a, "int8") == 0 ||
+ pg_strcasecmp(a, "pg_catalog.int8") == 0)
+ alignment = TYPALIGN_INT64;
else if (pg_strcasecmp(a, "int4") == 0 ||
pg_strcasecmp(a, "pg_catalog.int4") == 0)
alignment = TYPALIGN_INT;
@@ -433,6 +437,9 @@ DefineType(ParseState *pstate, List *names, List *parameters)
else if (pg_strcasecmp(a, "char") == 0 ||
pg_strcasecmp(a, "pg_catalog.bpchar") == 0)
alignment = TYPALIGN_CHAR;
+ else if (pg_strcasecmp(a, "max") == 0 ||
+ pg_strcasecmp(a, "pg_catalog.max") == 0)
+ alignment = TYPALIGN_MAX;
else
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -611,8 +618,8 @@ DefineType(ParseState *pstate, List *names, List *parameters)
*/
array_type = makeArrayTypeName(typeName, typeNamespace);
- /* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for arrays */
- alignment = (alignment == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
+ /* alignment must be TYPALIGN_INT or more for arrays */
+ alignment = containerAlignment(alignment);
TypeCreate(array_oid, /* force assignment of this type OID */
array_type, /* type name */
@@ -1095,8 +1102,8 @@ DefineDomain(ParseState *pstate, CreateDomainStmt *stmt)
*/
domainArrayName = makeArrayTypeName(domainName, domainNamespace);
- /* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for arrays */
- alignment = (alignment == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
+ /* alignment must be TYPALIGN_INT or more for arrays */
+ alignment = containerAlignment(alignment);
TypeCreate(domainArrayOid, /* force assignment of this type OID */
domainArrayName, /* type name */
@@ -1557,8 +1564,8 @@ DefineRange(ParseState *pstate, CreateRangeStmt *stmt)
get_typlenbyvalalign(rangeSubtype,
&subtyplen, &subtypbyval, &subtypalign);
- /* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for ranges */
- alignment = (subtypalign == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
+ /* alignment must be TYPALIGN_INT or more for ranges */
+ alignment = containerAlignment(subtypalign);
/* Allocate OID for array type, its multirange, and its multirange array */
rangeArrayOid = AssignTypeArrayOid();
@@ -2005,6 +2012,25 @@ makeMultirangeConstructors(const char *name, Oid namespace,
pfree(parameterModes);
}
+/*
+ * Compute the appropriate typalign for a container (array or range)
+ * given the typalign of its members. The container type requires at
+ * least int alignment, but more if the members need more.
+ */
+static char
+containerAlignment(char elemalign)
+{
+ switch (elemalign)
+ {
+ case TYPALIGN_INT64:
+ case TYPALIGN_DOUBLE:
+ case TYPALIGN_MAX:
+ return elemalign;
+ default:
+ return TYPALIGN_INT;
+ }
+}
+
/*
* Find suitable I/O and other support functions for a type.
*
diff --git a/src/backend/tsearch/ts_typanalyze.c b/src/backend/tsearch/ts_typanalyze.c
index 0c513d694e7..48ee050e37f 100644
--- a/src/backend/tsearch/ts_typanalyze.c
+++ b/src/backend/tsearch/ts_typanalyze.c
@@ -444,7 +444,7 @@ compute_tsvector_stats(VacAttrStats *stats,
stats->statypid[0] = TEXTOID;
stats->statyplen[0] = -1; /* typlen, -1 for varlena */
stats->statypbyval[0] = false;
- stats->statypalign[0] = 'i';
+ stats->statypalign[0] = TYPALIGN_INT;
}
}
else
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index da68915ee20..08e26335a95 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -3431,7 +3431,7 @@ construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
case INT8OID:
elmlen = sizeof(int64);
elmbyval = true;
- elmalign = TYPALIGN_DOUBLE;
+ elmalign = TYPALIGN_INT64;
break;
case NAMEOID:
diff --git a/src/backend/utils/adt/orderedsetaggs.c b/src/backend/utils/adt/orderedsetaggs.c
index 3b6da8e36ac..27b8cfa7064 100644
--- a/src/backend/utils/adt/orderedsetaggs.c
+++ b/src/backend/utils/adt/orderedsetaggs.c
@@ -1021,7 +1021,7 @@ percentile_cont_interval_multi_final(PG_FUNCTION_ARGS)
return percentile_cont_multi_final_common(fcinfo,
INTERVALOID,
/* hard-wired info on type interval */
- 16, false, TYPALIGN_DOUBLE,
+ 16, false, TYPALIGN_INT64,
interval_lerp);
}
diff --git a/src/backend/utils/adt/rangetypes_typanalyze.c b/src/backend/utils/adt/rangetypes_typanalyze.c
index 38d12dedbc5..278d4e6941a 100644
--- a/src/backend/utils/adt/rangetypes_typanalyze.c
+++ b/src/backend/utils/adt/rangetypes_typanalyze.c
@@ -398,7 +398,7 @@ compute_range_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
stats->statypid[slot_idx] = FLOAT8OID;
stats->statyplen[slot_idx] = sizeof(float8);
stats->statypbyval[slot_idx] = true;
- stats->statypalign[slot_idx] = 'd';
+ stats->statypalign[slot_idx] = TYPALIGN_DOUBLE;
/* Store the fraction of empty ranges */
emptyfrac = palloc_object(float4);
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index a3980e5535f..e550e9cf0a3 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -1580,7 +1580,7 @@ bootstrap_template1(void)
bki_lines = replace_token(bki_lines, "SIZEOF_POINTER", buf);
bki_lines = replace_token(bki_lines, "ALIGNOF_POINTER",
- (sizeof(Pointer) == 4) ? "i" : "d");
+ (sizeof(Pointer) == 4) ? "i" : "l");
bki_lines = replace_token(bki_lines, "POSTGRES",
escape_quotes_bki(username));
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 2bebefd0ba2..1b44c03170f 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -12652,8 +12652,12 @@ dumpBaseType(Archive *fout, const TypeInfo *tyinfo)
appendPQExpBufferStr(q, ",\n ALIGNMENT = int2");
else if (*typalign == TYPALIGN_INT)
appendPQExpBufferStr(q, ",\n ALIGNMENT = int4");
+ else if (*typalign == TYPALIGN_INT64)
+ appendPQExpBufferStr(q, ",\n ALIGNMENT = int8");
else if (*typalign == TYPALIGN_DOUBLE)
appendPQExpBufferStr(q, ",\n ALIGNMENT = double");
+ else if (*typalign == TYPALIGN_MAX)
+ appendPQExpBufferStr(q, ",\n ALIGNMENT = max");
if (*typstorage == TYPSTORAGE_PLAIN)
appendPQExpBufferStr(q, ",\n STORAGE = plain");
diff --git a/src/include/access/tupmacs.h b/src/include/access/tupmacs.h
index d64c18b950b..e7db125f627 100644
--- a/src/include/access/tupmacs.h
+++ b/src/include/access/tupmacs.h
@@ -92,9 +92,15 @@ typalign_to_alignby(char typalign)
case TYPALIGN_INT:
alignby = ALIGNOF_INT;
break;
+ case TYPALIGN_INT64:
+ alignby = ALIGNOF_INT64_T;
+ break;
case TYPALIGN_DOUBLE:
alignby = ALIGNOF_DOUBLE;
break;
+ case TYPALIGN_MAX:
+ alignby = MAXIMUM_ALIGNOF;
+ break;
default:
#ifndef FRONTEND
elog(ERROR, "invalid typalign value: %c", typalign);
diff --git a/src/include/c.h b/src/include/c.h
index c443e75b89f..c7956ce91bc 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -821,7 +821,7 @@ typedef NameData *Name;
#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
-#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
+#define INT64ALIGN(LEN) TYPEALIGN(ALIGNOF_INT64_T, (LEN))
#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
/* MAXALIGN covers only built-in types, not buffers */
@@ -833,7 +833,7 @@ typedef NameData *Name;
#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
-#define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN))
+#define INT64ALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT64_T, (LEN))
#define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
#define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
#define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_BUFFER, (LEN))
diff --git a/src/include/catalog/pg_type.dat b/src/include/catalog/pg_type.dat
index a1a753d1797..d511493f761 100644
--- a/src/include/catalog/pg_type.dat
+++ b/src/include/catalog/pg_type.dat
@@ -56,7 +56,7 @@
descr => '~18 digit integer, 8-byte storage',
typname => 'int8', typlen => '8', typbyval => 't',
typcategory => 'N', typinput => 'int8in', typoutput => 'int8out',
- typreceive => 'int8recv', typsend => 'int8send', typalign => 'd' },
+ typreceive => 'int8recv', typsend => 'int8send', typalign => 'l' },
{ oid => '21', array_type_oid => '1005',
descr => '-32 thousand to 32 thousand, 2-byte storage',
typname => 'int2', typlen => '2', typbyval => 't', typcategory => 'N',
@@ -116,22 +116,22 @@
typname => 'pg_type', typlen => '-1', typbyval => 'f', typtype => 'c',
typcategory => 'C', typrelid => 'pg_type', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
{ oid => '75', array_type_oid => '270',
typname => 'pg_attribute', typlen => '-1', typbyval => 'f', typtype => 'c',
typcategory => 'C', typrelid => 'pg_attribute', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
{ oid => '81', array_type_oid => '272',
typname => 'pg_proc', typlen => '-1', typbyval => 'f', typtype => 'c',
typcategory => 'C', typrelid => 'pg_proc', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
{ oid => '83', array_type_oid => '273',
typname => 'pg_class', typlen => '-1', typbyval => 'f', typtype => 'c',
typcategory => 'C', typrelid => 'pg_class', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
# OIDS 100 - 199
@@ -174,7 +174,7 @@
{ oid => '5069', array_type_oid => '271', descr => 'full transaction id',
typname => 'xid8', typlen => '8', typbyval => 't',
typcategory => 'U', typinput => 'xid8in', typoutput => 'xid8out',
- typreceive => 'xid8recv', typsend => 'xid8send', typalign => 'd' },
+ typreceive => 'xid8recv', typsend => 'xid8send', typalign => 'l' },
# OIDS 600 - 699
@@ -239,7 +239,7 @@
descr => 'monetary amounts, $d,ddd.cc',
typname => 'money', typlen => '8', typbyval => 't',
typcategory => 'N', typinput => 'cash_in', typoutput => 'cash_out',
- typreceive => 'cash_recv', typsend => 'cash_send', typalign => 'd' },
+ typreceive => 'cash_recv', typsend => 'cash_send', typalign => 'l' },
# OIDS 800 - 899
@@ -270,7 +270,7 @@
{ oid => '1033', array_type_oid => '1034', descr => 'access control list',
typname => 'aclitem', typlen => '16', typbyval => 'f', typcategory => 'U',
typinput => 'aclitemin', typoutput => 'aclitemout', typreceive => '-',
- typsend => '-', typalign => 'd' },
+ typsend => '-', typalign => 'l' },
{ oid => '1042', array_type_oid => '1014',
descr => '\'char(length)\' blank-padded string, fixed storage length',
typname => 'bpchar', typlen => '-1', typbyval => 'f', typcategory => 'S',
@@ -293,7 +293,7 @@
typname => 'time', typlen => '8', typbyval => 't',
typcategory => 'D', typinput => 'time_in', typoutput => 'time_out',
typreceive => 'time_recv', typsend => 'time_send', typmodin => 'timetypmodin',
- typmodout => 'timetypmodout', typalign => 'd' },
+ typmodout => 'timetypmodout', typalign => 'l' },
# OIDS 1100 - 1199
@@ -302,21 +302,21 @@
typcategory => 'D', typinput => 'timestamp_in', typoutput => 'timestamp_out',
typreceive => 'timestamp_recv', typsend => 'timestamp_send',
typmodin => 'timestamptypmodin', typmodout => 'timestamptypmodout',
- typalign => 'd' },
+ typalign => 'l' },
{ oid => '1184', array_type_oid => '1185',
descr => 'date and time with time zone',
typname => 'timestamptz', typlen => '8', typbyval => 't',
typcategory => 'D', typispreferred => 't', typinput => 'timestamptz_in',
typoutput => 'timestamptz_out', typreceive => 'timestamptz_recv',
typsend => 'timestamptz_send', typmodin => 'timestamptztypmodin',
- typmodout => 'timestamptztypmodout', typalign => 'd' },
+ typmodout => 'timestamptztypmodout', typalign => 'l' },
{ oid => '1186', array_type_oid => '1187',
descr => 'time interval, format \'number units ...\'',
typname => 'interval', typlen => '16', typbyval => 'f', typcategory => 'T',
typispreferred => 't', typinput => 'interval_in', typoutput => 'interval_out',
typreceive => 'interval_recv', typsend => 'interval_send',
typmodin => 'intervaltypmodin', typmodout => 'intervaltypmodout',
- typalign => 'd' },
+ typalign => 'l' },
# OIDS 1200 - 1299
@@ -326,7 +326,7 @@
typinput => 'timetz_in', typoutput => 'timetz_out',
typreceive => 'timetz_recv', typsend => 'timetz_send',
typmodin => 'timetztypmodin', typmodout => 'timetztypmodout',
- typalign => 'd' },
+ typalign => 'l' },
# OIDS 1500 - 1599
@@ -415,7 +415,7 @@
{ oid => '3220', array_type_oid => '3221', descr => 'PostgreSQL LSN',
typname => 'pg_lsn', typlen => '8', typbyval => 't',
typcategory => 'U', typinput => 'pg_lsn_in', typoutput => 'pg_lsn_out',
- typreceive => 'pg_lsn_recv', typsend => 'pg_lsn_send', typalign => 'd' },
+ typreceive => 'pg_lsn_recv', typsend => 'pg_lsn_send', typalign => 'l' },
# text search
{ oid => '3614', array_type_oid => '3643',
@@ -462,12 +462,12 @@
typname => 'txid_snapshot', typlen => '-1', typbyval => 'f',
typcategory => 'U', typinput => 'txid_snapshot_in',
typoutput => 'txid_snapshot_out', typreceive => 'txid_snapshot_recv',
- typsend => 'txid_snapshot_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'txid_snapshot_send', typalign => 'l', typstorage => 'x' },
{ oid => '5038', array_type_oid => '5039', descr => 'transaction snapshot',
typname => 'pg_snapshot', typlen => '-1', typbyval => 'f', typcategory => 'U',
typinput => 'pg_snapshot_in', typoutput => 'pg_snapshot_out',
typreceive => 'pg_snapshot_recv', typsend => 'pg_snapshot_send',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'l', typstorage => 'x' },
# range types
{ oid => '3904', array_type_oid => '3905', descr => 'range of integers',
@@ -485,13 +485,13 @@
typname => 'tsrange', typlen => '-1', typbyval => 'f', typtype => 'r',
typcategory => 'R', typinput => 'range_in', typoutput => 'range_out',
typreceive => 'range_recv', typsend => 'range_send',
- typanalyze => 'range_typanalyze', typalign => 'd', typstorage => 'x' },
+ typanalyze => 'range_typanalyze', typalign => 'l', typstorage => 'x' },
{ oid => '3910', array_type_oid => '3911',
descr => 'range of timestamps with time zone',
typname => 'tstzrange', typlen => '-1', typbyval => 'f', typtype => 'r',
typcategory => 'R', typinput => 'range_in', typoutput => 'range_out',
typreceive => 'range_recv', typsend => 'range_send',
- typanalyze => 'range_typanalyze', typalign => 'd', typstorage => 'x' },
+ typanalyze => 'range_typanalyze', typalign => 'l', typstorage => 'x' },
{ oid => '3912', array_type_oid => '3913', descr => 'range of dates',
typname => 'daterange', typlen => '-1', typbyval => 'f', typtype => 'r',
typcategory => 'R', typinput => 'range_in', typoutput => 'range_out',
@@ -501,7 +501,7 @@
typname => 'int8range', typlen => '-1', typbyval => 'f', typtype => 'r',
typcategory => 'R', typinput => 'range_in', typoutput => 'range_out',
typreceive => 'range_recv', typsend => 'range_send',
- typanalyze => 'range_typanalyze', typalign => 'd', typstorage => 'x' },
+ typanalyze => 'range_typanalyze', typalign => 'l', typstorage => 'x' },
# multirange types
{ oid => '4451', array_type_oid => '6150', descr => 'multirange of integers',
@@ -522,14 +522,14 @@
typcategory => 'R', typinput => 'multirange_in',
typoutput => 'multirange_out', typreceive => 'multirange_recv',
typsend => 'multirange_send', typanalyze => 'multirange_typanalyze',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'l', typstorage => 'x' },
{ oid => '4534', array_type_oid => '6153',
descr => 'multirange of timestamps with time zone',
typname => 'tstzmultirange', typlen => '-1', typbyval => 'f', typtype => 'm',
typcategory => 'R', typinput => 'multirange_in',
typoutput => 'multirange_out', typreceive => 'multirange_recv',
typsend => 'multirange_send', typanalyze => 'multirange_typanalyze',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'l', typstorage => 'x' },
{ oid => '4535', array_type_oid => '6155', descr => 'multirange of dates',
typname => 'datemultirange', typlen => '-1', typbyval => 'f', typtype => 'm',
typcategory => 'R', typinput => 'multirange_in',
@@ -541,7 +541,7 @@
typcategory => 'R', typinput => 'multirange_in',
typoutput => 'multirange_out', typreceive => 'multirange_recv',
typsend => 'multirange_send', typanalyze => 'multirange_typanalyze',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'l', typstorage => 'x' },
# pseudo-types
# types with typtype='p' represent various special cases in the type system.
@@ -556,14 +556,14 @@
typname => 'record', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typarray => '_record', typinput => 'record_in',
typoutput => 'record_out', typreceive => 'record_recv',
- typsend => 'record_send', typalign => 'd', typstorage => 'x' },
+ typsend => 'record_send', typalign => 'm', typstorage => 'x' },
# Arrays of records have typcategory P, so they can't be autogenerated.
{ oid => '2287',
typname => '_record', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typsubscript => 'array_subscript_handler',
typelem => 'record', typinput => 'array_in', typoutput => 'array_out',
typreceive => 'array_recv', typsend => 'array_send',
- typanalyze => 'array_typanalyze', typalign => 'd', typstorage => 'x' },
+ typanalyze => 'array_typanalyze', typalign => 'm', typstorage => 'x' },
{ oid => '2275', array_type_oid => '1263', descr => 'C-style string',
typname => 'cstring', typlen => '-2', typbyval => 'f', typtype => 'p',
typcategory => 'P', typinput => 'cstring_in', typoutput => 'cstring_out',
@@ -575,7 +575,7 @@
{ oid => '2277', descr => 'pseudo-type representing a polymorphic array type',
typname => 'anyarray', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typinput => 'anyarray_in', typoutput => 'anyarray_out',
- typreceive => 'anyarray_recv', typsend => 'anyarray_send', typalign => 'd',
+ typreceive => 'anyarray_recv', typsend => 'anyarray_send', typalign => 'm',
typstorage => 'x' },
{ oid => '2278',
descr => 'pseudo-type for the result of a function with no real result',
@@ -648,7 +648,7 @@
descr => 'pseudo-type representing a range over a polymorphic base type',
typname => 'anyrange', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typinput => 'anyrange_in', typoutput => 'anyrange_out',
- typreceive => '-', typsend => '-', typalign => 'd', typstorage => 'x' },
+ typreceive => '-', typsend => '-', typalign => 'm', typstorage => 'x' },
{ oid => '5077',
descr => 'pseudo-type representing a polymorphic common type',
typname => 'anycompatible', typlen => '4', typbyval => 't', typtype => 'p',
@@ -661,7 +661,7 @@
typtype => 'p', typcategory => 'P', typinput => 'anycompatiblearray_in',
typoutput => 'anycompatiblearray_out',
typreceive => 'anycompatiblearray_recv', typsend => 'anycompatiblearray_send',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'm', typstorage => 'x' },
{ oid => '5079',
descr => 'pseudo-type representing a polymorphic common type that is not an array',
typname => 'anycompatiblenonarray', typlen => '4', typbyval => 't',
@@ -673,19 +673,19 @@
typname => 'anycompatiblerange', typlen => '-1', typbyval => 'f',
typtype => 'p', typcategory => 'P', typinput => 'anycompatiblerange_in',
typoutput => 'anycompatiblerange_out', typreceive => '-', typsend => '-',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'm', typstorage => 'x' },
{ oid => '4537',
descr => 'pseudo-type representing a polymorphic base type that is a multirange',
typname => 'anymultirange', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typinput => 'anymultirange_in',
typoutput => 'anymultirange_out', typreceive => '-', typsend => '-',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'm', typstorage => 'x' },
{ oid => '4538',
descr => 'pseudo-type representing a multirange over a polymorphic common type',
typname => 'anycompatiblemultirange', typlen => '-1', typbyval => 'f',
typtype => 'p', typcategory => 'P', typinput => 'anycompatiblemultirange_in',
typoutput => 'anycompatiblemultirange_out', typreceive => '-', typsend => '-',
- typalign => 'd', typstorage => 'x' },
+ typalign => 'm', typstorage => 'x' },
{ oid => '4600', descr => 'pseudo-type representing BRIN bloom summary',
typname => 'pg_brin_bloom_summary', typlen => '-1', typbyval => 'f',
typcategory => 'Z', typinput => 'brin_bloom_summary_in',
@@ -704,5 +704,5 @@
descr => 'object identifier(oid8), 8 bytes',
typname => 'oid8', typlen => '8', typbyval => 't', typcategory => 'N',
typinput => 'oid8in', typoutput => 'oid8out', typreceive => 'oid8recv',
- typsend => 'oid8send', typalign => 'd' },
+ typsend => 'oid8send', typalign => 'l' },
]
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 70d4a20c02b..b749a47d651 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -302,7 +302,9 @@ MAKE_SYSCACHE(TYPENAMENSP, pg_type_typname_nsp_index, 64);
#define TYPALIGN_CHAR 'c' /* char alignment (i.e. unaligned) */
#define TYPALIGN_SHORT 's' /* short alignment (typically 2 bytes) */
#define TYPALIGN_INT 'i' /* int alignment (typically 4 bytes) */
+#define TYPALIGN_INT64 'l' /* int64 alignment (often 8 bytes) */
#define TYPALIGN_DOUBLE 'd' /* double alignment (often 8 bytes) */
+#define TYPALIGN_MAX 'm' /* maximum alignment (usually 8 bytes) */
#define TYPSTORAGE_PLAIN 'p' /* type not prepared for toasting */
#define TYPSTORAGE_EXTERNAL 'e' /* toastable, don't try to compress */
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 339268dc8ef..5699c033ade 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -12,9 +12,6 @@
/* The normal alignment of `int64_t', in bytes. */
#undef ALIGNOF_INT64_T
-/* The normal alignment of `long', in bytes. */
-#undef ALIGNOF_LONG
-
/* The normal alignment of `PG_INT128_TYPE', in bytes. */
#undef ALIGNOF_PG_INT128_TYPE
diff --git a/src/pl/plpython/plpy_typeio.c b/src/pl/plpython/plpy_typeio.c
index 44055de6aeb..d4dbb6b5b85 100644
--- a/src/pl/plpython/plpy_typeio.c
+++ b/src/pl/plpython/plpy_typeio.c
@@ -329,7 +329,7 @@ PLy_output_setup_func(PLyObToDatum *arg, MemoryContext arg_mcxt,
/* hard-wired knowledge about type RECORD: */
arg->typbyval = false;
arg->typlen = -1;
- arg->typalign = TYPALIGN_DOUBLE;
+ arg->typalign = TYPALIGN_MAX;
}
/*
@@ -452,7 +452,7 @@ PLy_input_setup_func(PLyDatumToOb *arg, MemoryContext arg_mcxt,
/* hard-wired knowledge about type RECORD: */
arg->typbyval = false;
arg->typlen = -1;
- arg->typalign = TYPALIGN_DOUBLE;
+ arg->typalign = TYPALIGN_MAX;
}
/*
diff --git a/src/test/regress/expected/create_type.out b/src/test/regress/expected/create_type.out
index 5181c4290b4..07919b4fe0e 100644
--- a/src/test/regress/expected/create_type.out
+++ b/src/test/regress/expected/create_type.out
@@ -49,6 +49,7 @@ CREATE TYPE city_budget (
output = int44out,
element = int4,
category = 'x', -- just to verify the system will take it
+ alignment = max, -- ditto (overspecifying alignment is safe)
preferred = true -- ditto
);
-- Test creation and destruction of shell types
diff --git a/src/test/regress/expected/float8.out b/src/test/regress/expected/float8.out
index 9c519f1a1a1..a688cbc3c83 100644
--- a/src/test/regress/expected/float8.out
+++ b/src/test/regress/expected/float8.out
@@ -1088,8 +1088,10 @@ LINE 1: ...8 (input = xfloat8in, output = xfloat8out, like = no_such_ty...
create type xfloat8 (input = xfloat8in, output = xfloat8out, like = float8);
create cast (xfloat8 as float8) without function;
create cast (float8 as xfloat8) without function;
-create cast (xfloat8 as bigint) without function;
-create cast (bigint as xfloat8) without function;
+-- this hack depends on bigint and float8 having the same pass-by-value-ness:
+create function bigint_xfloat8(bigint) returns xfloat8 immutable strict
+ language internal as 'int8up';
+create cast (bigint as xfloat8) with function bigint_xfloat8(bigint);
-- float8: seeeeeee eeeeeeee eeeeeeee mmmmmmmm mmmmmmmm(x4)
-- we don't care to assume the platform's strtod() handles subnormals
-- correctly; those are "use at your own risk". However we do test
@@ -1503,5 +1505,5 @@ DETAIL: drop cascades to function xfloat8in(cstring)
drop cascades to function xfloat8out(xfloat8)
drop cascades to cast from xfloat8 to double precision
drop cascades to cast from double precision to xfloat8
-drop cascades to cast from xfloat8 to bigint
+drop cascades to function bigint_xfloat8(bigint)
drop cascades to cast from bigint to xfloat8
diff --git a/src/test/regress/expected/type_sanity.out b/src/test/regress/expected/type_sanity.out
index 1d21d3eb446..936fa36a600 100644
--- a/src/test/regress/expected/type_sanity.out
+++ b/src/test/regress/expected/type_sanity.out
@@ -23,7 +23,7 @@ WHERE t1.typnamespace = 0 OR
(t1.typlen <= 0 AND t1.typlen != -1 AND t1.typlen != -2) OR
(t1.typtype not in ('b', 'c', 'd', 'e', 'm', 'p', 'r')) OR
NOT t1.typisdefined OR
- (t1.typalign not in ('c', 's', 'i', 'd')) OR
+ (t1.typalign not in ('c', 's', 'i', 'l', 'd', 'm')) OR
(t1.typstorage not in ('p', 'x', 'e', 'm'));
oid | typname
-----+---------
@@ -36,7 +36,7 @@ WHERE t1.typbyval AND
(t1.typlen != 1 OR t1.typalign != 'c') AND
(t1.typlen != 2 OR t1.typalign != 's') AND
(t1.typlen != 4 OR t1.typalign != 'i') AND
- (t1.typlen != 8 OR t1.typalign != 'd');
+ (t1.typlen != 8 OR (t1.typalign != 'l' AND t1.typalign != 'd'));
oid | typname
-----+---------
(0 rows)
@@ -108,6 +108,8 @@ FROM pg_type as t1
LEFT JOIN pg_type as t2 ON rngsubtype = t2.oid
WHERE t1.typtype = 'r' AND
(t1.typalign != (CASE WHEN t2.typalign = 'd' THEN 'd'::"char"
+ WHEN t2.typalign = 'l' THEN 'l'::"char"
+ WHEN t2.typalign = 'm' THEN 'm'::"char"
ELSE 'i'::"char" END)
OR t2.oid IS NULL);
oid | typname | typalign | typname | typalign
@@ -423,6 +425,8 @@ SELECT t1.oid, t1.typname, t1.typalign, t2.typname, t2.typalign
FROM pg_type AS t1, pg_type AS t2
WHERE t1.typarray = t2.oid AND
t2.typalign != (CASE WHEN t1.typalign = 'd' THEN 'd'::"char"
+ WHEN t1.typalign = 'l' THEN 'l'::"char"
+ WHEN t1.typalign = 'm' THEN 'm'::"char"
ELSE 'i'::"char" END);
oid | typname | typalign | typname | typalign
-----+---------+----------+---------+----------
diff --git a/src/test/regress/sql/create_type.sql b/src/test/regress/sql/create_type.sql
index c25018029c2..94c5b949c25 100644
--- a/src/test/regress/sql/create_type.sql
+++ b/src/test/regress/sql/create_type.sql
@@ -47,6 +47,7 @@ CREATE TYPE city_budget (
output = int44out,
element = int4,
category = 'x', -- just to verify the system will take it
+ alignment = max, -- ditto (overspecifying alignment is safe)
preferred = true -- ditto
);
diff --git a/src/test/regress/sql/float8.sql b/src/test/regress/sql/float8.sql
index 0ef271f2702..c6b59a322ab 100644
--- a/src/test/regress/sql/float8.sql
+++ b/src/test/regress/sql/float8.sql
@@ -355,8 +355,10 @@ create type xfloat8 (input = xfloat8in, output = xfloat8out, like = no_such_type
create type xfloat8 (input = xfloat8in, output = xfloat8out, like = float8);
create cast (xfloat8 as float8) without function;
create cast (float8 as xfloat8) without function;
-create cast (xfloat8 as bigint) without function;
-create cast (bigint as xfloat8) without function;
+-- this hack depends on bigint and float8 having the same pass-by-value-ness:
+create function bigint_xfloat8(bigint) returns xfloat8 immutable strict
+ language internal as 'int8up';
+create cast (bigint as xfloat8) with function bigint_xfloat8(bigint);
-- float8: seeeeeee eeeeeeee eeeeeeee mmmmmmmm mmmmmmmm(x4)
diff --git a/src/test/regress/sql/type_sanity.sql b/src/test/regress/sql/type_sanity.sql
index 95d5b6e0915..625305c42bc 100644
--- a/src/test/regress/sql/type_sanity.sql
+++ b/src/test/regress/sql/type_sanity.sql
@@ -28,7 +28,7 @@ WHERE t1.typnamespace = 0 OR
(t1.typlen <= 0 AND t1.typlen != -1 AND t1.typlen != -2) OR
(t1.typtype not in ('b', 'c', 'd', 'e', 'm', 'p', 'r')) OR
NOT t1.typisdefined OR
- (t1.typalign not in ('c', 's', 'i', 'd')) OR
+ (t1.typalign not in ('c', 's', 'i', 'l', 'd', 'm')) OR
(t1.typstorage not in ('p', 'x', 'e', 'm'));
-- Look for "pass by value" types that can't be passed by value.
@@ -39,7 +39,7 @@ WHERE t1.typbyval AND
(t1.typlen != 1 OR t1.typalign != 'c') AND
(t1.typlen != 2 OR t1.typalign != 's') AND
(t1.typlen != 4 OR t1.typalign != 'i') AND
- (t1.typlen != 8 OR t1.typalign != 'd');
+ (t1.typlen != 8 OR (t1.typalign != 'l' AND t1.typalign != 'd'));
-- Look for "toastable" types that aren't varlena.
@@ -90,6 +90,8 @@ FROM pg_type as t1
LEFT JOIN pg_type as t2 ON rngsubtype = t2.oid
WHERE t1.typtype = 'r' AND
(t1.typalign != (CASE WHEN t2.typalign = 'd' THEN 'd'::"char"
+ WHEN t2.typalign = 'l' THEN 'l'::"char"
+ WHEN t2.typalign = 'm' THEN 'm'::"char"
ELSE 'i'::"char" END)
OR t2.oid IS NULL);
@@ -302,6 +304,8 @@ SELECT t1.oid, t1.typname, t1.typalign, t2.typname, t2.typalign
FROM pg_type AS t1, pg_type AS t2
WHERE t1.typarray = t2.oid AND
t2.typalign != (CASE WHEN t1.typalign = 'd' THEN 'd'::"char"
+ WHEN t1.typalign = 'l' THEN 'l'::"char"
+ WHEN t1.typalign = 'm' THEN 'm'::"char"
ELSE 'i'::"char" END);
-- Check for typelem set without a handler
--
2.43.7
From 57382d99270442cf042bf0d481cc9233264842c5 Mon Sep 17 00:00:00 2001
From: Tom Lane
Date: Mon, 2 Feb 2026 15:23:45 -0500
Subject: [PATCH v3 2/2] Add new alignment info to pg_control, and check it
during pg_upgrade.
Having decoupled ALIGNOF_INT64_T and ALIGNOF_DOUBLE from
MAXIMUM_ALIGNOF, we had better record all three values in pg_control,
and check them to verify database compatibility.
In pg_upgrade, if the source cluster's pg_controldata doesn't report
the new fields, assume they have values equal to its MAXALIGN.
This allows safe upgrading from pre-v19 databases.
This will require a catversion bump.
Discussion: https://postgr.es/m/1127261.1769649624@sss.pgh.pa.us
---
doc/src/sgml/func/func-info.sgml | 10 ++++
src/backend/access/transam/xlog.c | 22 ++++++++
src/backend/utils/misc/pg_controldata.c | 49 +++++++++---------
src/bin/pg_controldata/pg_controldata.c | 4 ++
src/bin/pg_resetwal/pg_resetwal.c | 6 +++
src/bin/pg_upgrade/controldata.c | 67 ++++++++++++++++++++++---
src/bin/pg_upgrade/pg_upgrade.h | 9 +++-
src/include/catalog/pg_control.h | 14 +++---
src/include/catalog/pg_proc.dat | 6 +--
9 files changed, 144 insertions(+), 43 deletions(-)
diff --git a/doc/src/sgml/func/func-info.sgml b/doc/src/sgml/func/func-info.sgml
index 294f45e82a3..9c235f47611 100644
--- a/doc/src/sgml/func/func-info.sgml
+++ b/doc/src/sgml/func/func-info.sgml
@@ -3545,6 +3545,16 @@ acl | {postgres=arwdDxtm/postgres,foo=r/postgres}
+
+ int8_data_alignment
+ integer
+
+
+
+ float8_data_alignment
+ integer
+
+
max_data_alignment
integer
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 13ec6225b85..8cb5d033911 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4284,6 +4284,8 @@ WriteControlFile(void)
ControlFile->pg_control_version = PG_CONTROL_VERSION;
ControlFile->catalog_version_no = CATALOG_VERSION_NO;
+ ControlFile->int64Align = ALIGNOF_INT64_T;
+ ControlFile->doubleAlign = ALIGNOF_DOUBLE;
ControlFile->maxAlign = MAXIMUM_ALIGNOF;
ControlFile->floatFormat = FLOATFORMAT_VALUE;
@@ -4473,6 +4475,26 @@ ReadControlFile(void)
"CATALOG_VERSION_NO", ControlFile->catalog_version_no,
"CATALOG_VERSION_NO", CATALOG_VERSION_NO),
errhint("It looks like you need to initdb.")));
+ if (ControlFile->int64Align != ALIGNOF_INT64_T)
+ ereport(FATAL,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("database files are incompatible with server"),
+ /* translator: %s is a variable name and %d is its value */
+ errdetail("The database cluster was initialized with %s %d,"
+ " but the server was compiled with %s %d.",
+ "ALIGNOF_INT64_T", ControlFile->int64Align,
+ "ALIGNOF_INT64_T", ALIGNOF_INT64_T),
+ errhint("It looks like you need to initdb.")));
+ if (ControlFile->doubleAlign != ALIGNOF_DOUBLE)
+ ereport(FATAL,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("database files are incompatible with server"),
+ /* translator: %s is a variable name and %d is its value */
+ errdetail("The database cluster was initialized with %s %d,"
+ " but the server was compiled with %s %d.",
+ "ALIGNOF_DOUBLE", ControlFile->doubleAlign,
+ "ALIGNOF_DOUBLE", ALIGNOF_DOUBLE),
+ errhint("It looks like you need to initdb.")));
if (ControlFile->maxAlign != MAXIMUM_ALIGNOF)
ereport(FATAL,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
diff --git a/src/backend/utils/misc/pg_controldata.c b/src/backend/utils/misc/pg_controldata.c
index c6d9cbb1577..1f901dacc01 100644
--- a/src/backend/utils/misc/pg_controldata.c
+++ b/src/backend/utils/misc/pg_controldata.c
@@ -203,8 +203,9 @@ pg_control_recovery(PG_FUNCTION_ARGS)
Datum
pg_control_init(PG_FUNCTION_ARGS)
{
- Datum values[12];
- bool nulls[12];
+ Datum values[14];
+ bool nulls[14];
+ int j = 0;
TupleDesc tupdesc;
HeapTuple htup;
ControlFileData *ControlFile;
@@ -221,41 +222,37 @@ pg_control_init(PG_FUNCTION_ARGS)
ereport(ERROR,
(errmsg("calculated CRC checksum does not match value stored in file")));
- values[0] = Int32GetDatum(ControlFile->maxAlign);
- nulls[0] = false;
+ memset(nulls, 0, sizeof(nulls));
- values[1] = Int32GetDatum(ControlFile->blcksz);
- nulls[1] = false;
+ values[j++] = Int32GetDatum(ControlFile->int64Align);
- values[2] = Int32GetDatum(ControlFile->relseg_size);
- nulls[2] = false;
+ values[j++] = Int32GetDatum(ControlFile->doubleAlign);
- values[3] = Int32GetDatum(ControlFile->xlog_blcksz);
- nulls[3] = false;
+ values[j++] = Int32GetDatum(ControlFile->maxAlign);
- values[4] = Int32GetDatum(ControlFile->xlog_seg_size);
- nulls[4] = false;
+ values[j++] = Int32GetDatum(ControlFile->blcksz);
- values[5] = Int32GetDatum(ControlFile->nameDataLen);
- nulls[5] = false;
+ values[j++] = Int32GetDatum(ControlFile->relseg_size);
- values[6] = Int32GetDatum(ControlFile->indexMaxKeys);
- nulls[6] = false;
+ values[j++] = Int32GetDatum(ControlFile->xlog_blcksz);
- values[7] = Int32GetDatum(ControlFile->toast_max_chunk_size);
- nulls[7] = false;
+ values[j++] = Int32GetDatum(ControlFile->xlog_seg_size);
- values[8] = Int32GetDatum(ControlFile->loblksize);
- nulls[8] = false;
+ values[j++] = Int32GetDatum(ControlFile->nameDataLen);
- values[9] = BoolGetDatum(ControlFile->float8ByVal);
- nulls[9] = false;
+ values[j++] = Int32GetDatum(ControlFile->indexMaxKeys);
- values[10] = Int32GetDatum(ControlFile->data_checksum_version);
- nulls[10] = false;
+ values[j++] = Int32GetDatum(ControlFile->toast_max_chunk_size);
- values[11] = BoolGetDatum(ControlFile->default_char_signedness);
- nulls[11] = false;
+ values[j++] = Int32GetDatum(ControlFile->loblksize);
+
+ values[j++] = BoolGetDatum(ControlFile->float8ByVal);
+
+ values[j++] = Int32GetDatum(ControlFile->data_checksum_version);
+
+ values[j++] = BoolGetDatum(ControlFile->default_char_signedness);
+
+ Assert(j == lengthof(values));
htup = heap_form_tuple(tupdesc, values, nulls);
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index a4060309ae0..b93f6521326 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -317,6 +317,10 @@ main(int argc, char *argv[])
ControlFile->max_locks_per_xact);
printf(_("track_commit_timestamp setting: %s\n"),
ControlFile->track_commit_timestamp ? _("on") : _("off"));
+ printf(_("int8 data alignment: %u\n"),
+ ControlFile->int64Align);
+ printf(_("float8 data alignment: %u\n"),
+ ControlFile->doubleAlign);
printf(_("Maximum data alignment: %u\n"),
ControlFile->maxAlign);
/* we don't print floatFormat since can't say much useful about it */
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index 431b83a67da..59edf644d06 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -724,6 +724,8 @@ GuessControlValues(void)
ControlFile.max_prepared_xacts = 0;
ControlFile.max_locks_per_xact = 64;
+ ControlFile.int64Align = ALIGNOF_INT64_T;
+ ControlFile.doubleAlign = ALIGNOF_DOUBLE;
ControlFile.maxAlign = MAXIMUM_ALIGNOF;
ControlFile.floatFormat = FLOATFORMAT_VALUE;
ControlFile.blcksz = BLCKSZ;
@@ -791,6 +793,10 @@ PrintControlValues(bool guessed)
ControlFile.checkPointCopy.oldestCommitTsXid);
printf(_("Latest checkpoint's newestCommitTsXid:%u\n"),
ControlFile.checkPointCopy.newestCommitTsXid);
+ printf(_("int8 data alignment: %u\n"),
+ ControlFile.int64Align);
+ printf(_("float8 data alignment: %u\n"),
+ ControlFile.doubleAlign);
printf(_("Maximum data alignment: %u\n"),
ControlFile.maxAlign);
/* we don't print floatFormat since can't say much useful about it */
diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c
index aa6e8b4de5d..d096affa550 100644
--- a/src/bin/pg_upgrade/controldata.c
+++ b/src/bin/pg_upgrade/controldata.c
@@ -52,7 +52,9 @@ get_control_data(ClusterInfo *cluster)
bool got_mxoff = false;
bool got_nextxlogfile = false;
bool got_float8_pass_by_value = false;
- bool got_align = false;
+ bool got_int64align = false;
+ bool got_doublealign = false;
+ bool got_maxalign = false;
bool got_blocksz = false;
bool got_largesz = false;
bool got_walsz = false;
@@ -383,6 +385,28 @@ get_control_data(ClusterInfo *cluster)
cluster->controldata.float8_pass_by_value = strstr(p, "by value") != NULL;
got_float8_pass_by_value = true;
}
+ else if ((p = strstr(bufin, "int8 data alignment:")) != NULL)
+ {
+ p = strchr(p, ':');
+
+ if (p == NULL || strlen(p) <= 1)
+ pg_fatal("%d: controldata retrieval problem", __LINE__);
+
+ p++; /* remove ':' char */
+ cluster->controldata.int64align = str2uint(p);
+ got_int64align = true;
+ }
+ else if ((p = strstr(bufin, "float8 data alignment:")) != NULL)
+ {
+ p = strchr(p, ':');
+
+ if (p == NULL || strlen(p) <= 1)
+ pg_fatal("%d: controldata retrieval problem", __LINE__);
+
+ p++; /* remove ':' char */
+ cluster->controldata.doublealign = str2uint(p);
+ got_doublealign = true;
+ }
else if ((p = strstr(bufin, "Maximum data alignment:")) != NULL)
{
p = strchr(p, ':');
@@ -391,8 +415,8 @@ get_control_data(ClusterInfo *cluster)
pg_fatal("%d: controldata retrieval problem", __LINE__);
p++; /* remove ':' char */
- cluster->controldata.align = str2uint(p);
- got_align = true;
+ cluster->controldata.maxalign = str2uint(p);
+ got_maxalign = true;
}
else if ((p = strstr(bufin, "Database block size:")) != NULL)
{
@@ -598,13 +622,28 @@ get_control_data(ClusterInfo *cluster)
#endif
}
+ /*
+ * Pre-v19 database clusters will not report int64align or doublealign.
+ * Their values must be equal to maxalign in that case.
+ */
+ if (cluster->controldata.ctrl_ver < INT64_ALIGN_PG_CONTROL_VER)
+ {
+ Assert(!got_int64align);
+ cluster->controldata.int64align = cluster->controldata.maxalign;
+ got_int64align = true;
+ Assert(!got_doublealign);
+ cluster->controldata.doublealign = cluster->controldata.maxalign;
+ got_doublealign = true;
+ }
+
/* verify that we got all the mandatory pg_control data */
if (!got_xid || !got_oid ||
!got_multi || !got_oldestxid ||
(!got_oldestmulti &&
cluster->controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER) ||
!got_mxoff || (!live_check && !got_nextxlogfile) ||
- !got_float8_pass_by_value || !got_align || !got_blocksz ||
+ !got_float8_pass_by_value || !got_blocksz ||
+ !got_int64align || !got_doublealign || !got_maxalign ||
!got_largesz || !got_walsz || !got_walseg || !got_ident ||
!got_index || !got_toast ||
(!got_large_object &&
@@ -645,7 +684,13 @@ get_control_data(ClusterInfo *cluster)
if (!got_float8_pass_by_value)
pg_log(PG_REPORT, " float8 argument passing method");
- if (!got_align)
+ if (!got_int64align)
+ pg_log(PG_REPORT, " int8 alignment");
+
+ if (!got_doublealign)
+ pg_log(PG_REPORT, " float8 alignment");
+
+ if (!got_maxalign)
pg_log(PG_REPORT, " maximum alignment");
if (!got_blocksz)
@@ -698,8 +743,16 @@ void
check_control_data(ControlData *oldctrl,
ControlData *newctrl)
{
- if (oldctrl->align == 0 || oldctrl->align != newctrl->align)
- pg_fatal("old and new pg_controldata alignments are invalid or do not match.\n"
+ if (oldctrl->int64align == 0 || oldctrl->int64align != newctrl->int64align)
+ pg_fatal("old and new pg_controldata int8 alignments are invalid or do not match.\n"
+ "Likely one cluster is a 32-bit install, the other 64-bit");
+
+ if (oldctrl->doublealign == 0 || oldctrl->doublealign != newctrl->doublealign)
+ pg_fatal("old and new pg_controldata float8 alignments are invalid or do not match.\n"
+ "Likely one cluster is a 32-bit install, the other 64-bit");
+
+ if (oldctrl->maxalign == 0 || oldctrl->maxalign != newctrl->maxalign)
+ pg_fatal("old and new pg_controldata maximum alignments are invalid or do not match.\n"
"Likely one cluster is a 32-bit install, the other 64-bit");
if (oldctrl->blocksz == 0 || oldctrl->blocksz != newctrl->blocksz)
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index ec018e4f292..6caa00a7bed 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -138,6 +138,11 @@ extern char *output_files[];
*/
#define DEFAULT_CHAR_SIGNEDNESS_CAT_VER 202502212
+/*
+ * Separate int64Align and doubleAlign fields were added to pg_control here
+ */
+#define INT64_ALIGN_PG_CONTROL_VER 1902
+
/*
* Each relation is represented by a relinfo structure.
*/
@@ -245,7 +250,9 @@ typedef struct
uint64 chkpnt_nxtmxoff;
uint32 chkpnt_oldstMulti;
uint32 chkpnt_oldstxid;
- uint32 align;
+ uint32 int64align;
+ uint32 doublealign;
+ uint32 maxalign;
uint32 blocksz;
uint32 largesz;
uint32 walsz;
diff --git a/src/include/catalog/pg_control.h b/src/include/catalog/pg_control.h
index 7503db1af51..f4f579651ca 100644
--- a/src/include/catalog/pg_control.h
+++ b/src/include/catalog/pg_control.h
@@ -22,7 +22,7 @@
/* Version identifier for this pg_control format */
-#define PG_CONTROL_VERSION 1901
+#define PG_CONTROL_VERSION 1902
/* Nonce key length, see below */
#define MOCK_AUTH_NONCE_LEN 32
@@ -190,15 +190,17 @@ typedef struct ControlFileData
* This data is used to check for hardware-architecture compatibility of
* the database and the backend executable. We need not check endianness
* explicitly, since the pg_control version will surely look wrong to a
- * machine of different endianness, but we do need to worry about MAXALIGN
- * and floating-point format. (Note: storage layout nominally also
- * depends on SHORTALIGN and INTALIGN, but in practice these are the same
- * on all architectures of interest.)
+ * machine of different endianness, but we do need to worry about data
+ * alignment and floating-point format. (Note: storage layout nominally
+ * also depends on SHORTALIGN and INTALIGN, but in practice these are the
+ * same on all architectures of interest.)
*
* Testing just one double value is not a very bulletproof test for
* floating-point compatibility, but it will catch most cases.
*/
- uint32 maxAlign; /* alignment requirement for tuples */
+ uint8 int64Align; /* alignment requirement for 8-byte integers */
+ uint8 doubleAlign; /* alignment requirement for float8 */
+ uint8 maxAlign; /* alignment requirement for tuples */
double floatFormat; /* constant 1234567.0 */
#define FLOATFORMAT_VALUE 1234567.0
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 5e5e33f64fc..238bb96f24e 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -12384,9 +12384,9 @@
descr => 'pg_controldata init state information as a function',
proname => 'pg_control_init', provolatile => 'v', prorettype => 'record',
proargtypes => '',
- proallargtypes => '{int4,int4,int4,int4,int4,int4,int4,int4,int4,bool,int4,bool}',
- proargmodes => '{o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{max_data_alignment,database_block_size,blocks_per_segment,wal_block_size,bytes_per_wal_segment,max_identifier_length,max_index_columns,max_toast_chunk_size,large_object_chunk_size,float8_pass_by_value,data_page_checksum_version,default_char_signedness}',
+ proallargtypes => '{int4,int4,int4,int4,int4,int4,int4,int4,int4,int4,int4,bool,int4,bool}',
+ proargmodes => '{o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{int8_data_alignment,float8_data_alignment,max_data_alignment,database_block_size,blocks_per_segment,wal_block_size,bytes_per_wal_segment,max_identifier_length,max_index_columns,max_toast_chunk_size,large_object_chunk_size,float8_pass_by_value,data_page_checksum_version,default_char_signedness}',
prosrc => 'pg_control_init' },
# subscripting support for built-in types
--
2.43.7
Re: Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
I wrote: > Attached a v3 of the main patch (now again numbered 0001), plus > new work in 0002 that adds the two new alignment values to > pg_control and insists on a match before pg_upgrade'ing. I've gotten cold feet about this whole idea, and no longer think we should pursue it. Aside from the problems already raised, consider this: what would extensions do with existing int64-based data types? We don't have any provision for altering the typalign of an existing type, and if we did it would imply doing table rewrites (at least for cases where the change wasn't effectively a no-op). Worse, if such a type is created using "LIKE int8" which has always been best practice, then whether it shows up with align 'l' or 'd' in a new installation will depend on whether you pg_upgrade'd or installed the extension fresh. So that looks like a mess waiting to happen. Combine that with extensions that manually set alignment = double, and never bother to update because they can't change it and don't care anyway, and the inevitable end result is that the 'l' and 'd' cases will be so randomly assigned that there's not a meaningful difference after all. Perhaps we could have got away with such a change in the pre-pg_upgrade era, but I think we cannot now. If we want to re-support AIX, I think we're stuck with going back to the old way of calculating MAXALIGN, and then re-instituting that regression test that checked for unsafely-aligned catalog columns. Bleah. Still, as long as the regression test is accurate, it seems like that'd be an annoyance not a major headache. regards, tom lane
Re: Decoupling our alignment assumptions about int64 and double
От:
Andres Freund <andres@anarazel.de>
Дата:
Hi, On 2026-02-03 17:29:46 -0500, Tom Lane wrote: > I wrote: > > Attached a v3 of the main patch (now again numbered 0001), plus > > new work in 0002 that adds the two new alignment values to > > pg_control and insists on a match before pg_upgrade'ing. > > I've gotten cold feet about this whole idea, and no longer think > we should pursue it. Aside from the problems already raised, > consider this: what would extensions do with existing int64-based > data types? We don't have any provision for altering the typalign > of an existing type, and if we did it would imply doing table > rewrites (at least for cases where the change wasn't effectively > a no-op). Worse, if such a type is created using "LIKE int8" > which has always been best practice, then whether it shows up > with align 'l' or 'd' in a new installation will depend on whether > you pg_upgrade'd or installed the extension fresh. So that looks > like a mess waiting to happen. Combine that with extensions that > manually set alignment = double, and never bother to update because > they can't change it and don't care anyway, and the inevitable end > result is that the 'l' and 'd' cases will be so randomly assigned > that there's not a meaningful difference after all. Perhaps we > could have got away with such a change in the pre-pg_upgrade era, > but I think we cannot now. I can't really see a way to avoid these issues either :( > If we want to re-support AIX, I think we're stuck with going back > to the old way of calculating MAXALIGN, and then re-instituting that > regression test that checked for unsafely-aligned catalog columns. > Bleah. Still, as long as the regression test is accurate, it seems > like that'd be an annoyance not a major headache. I am pretty unhappy about that, I think the test and rules are just about incomprehensible. I wonder if we ought to instead just redefine float8 to be be aligned to 8 bytes, leaving double alone. Something like #if ALIGNOF_DOUBLE < ALIGNOF_LONG typedef double __attribute__((aligned(8))) float8; #define ALIGNOF_FLOAT* ALIGNOF_LONG #else typedef double float8; #define ALIGNOF_FLOAT8 ALIGNOF_DOUBLE #endif should do the trick. Greetings, Andres Freund
Re: Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Andres Freund writes: > On 2026-02-03 17:29:46 -0500, Tom Lane wrote: >> If we want to re-support AIX, I think we're stuck with going back >> to the old way of calculating MAXALIGN, and then re-instituting that >> regression test that checked for unsafely-aligned catalog columns. >> Bleah. Still, as long as the regression test is accurate, it seems >> like that'd be an annoyance not a major headache. > I am pretty unhappy about that, I think the test and rules are just about > incomprehensible. I wonder if we ought to instead just redefine float8 to be > be aligned to 8 bytes, leaving double alone. I thought about that, but it seemed like there'd be nothing stopping people from declaring a catalog column as "double" rather than "float8" and thus falling into the trap anyway. I suppose we could put a check for that into Catalog.pm, though. regards, tom lane
Re: Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
I wrote: > Andres Freund writes: >> I am pretty unhappy about that, I think the test and rules are just about >> incomprehensible. I wonder if we ought to instead just redefine float8 to be >> be aligned to 8 bytes, leaving double alone. > I thought about that, but it seemed like there'd be nothing stopping > people from declaring a catalog column as "double" rather than > "float8" and thus falling into the trap anyway. I suppose we could > put a check for that into Catalog.pm, though. No, scratch that: the real objection is that we can't do that unless we are willing to break pg_upgrade on AIX. The catalogs can't have different alignment rules than user tables do. Now, maybe we're willing to go there, but it's not a pleasant prospect. regards, tom lane
Re: Decoupling our alignment assumptions about int64 and double
От:
Thomas Munro <thomas.munro@gmail.com>
Дата:
On Fri, Feb 6, 2026 at 12:33 PM Tom Lane wrote:
> Andres Freund writes:
> > On 2026-02-03 17:29:46 -0500, Tom Lane wrote:
> > I am pretty unhappy about that, I think the test and rules are just about
> > incomprehensible. I wonder if we ought to instead just redefine float8 to be
> > be aligned to 8 bytes, leaving double alone.
>
> I thought about that, but it seemed like there'd be nothing stopping
> people from declaring a catalog column as "double" rather than
> "float8" and thus falling into the trap anyway. I suppose we could
> put a check for that into Catalog.pm, though.
I see that pg_upgrade is the real problem, but if that's somehow OK
("v19 is a new port, dump and restore needed!") then I wonder if
-malign=natural (which seems to be the GCC equivalent of what the
native compiler called -qalign=natural) might be an option. Of course
that might create ABI problems for structs in library headers, IDK,
but I recall that it's not uncommon for software to tweak that sort of
thing on AIX so I wonder if system headers might have their own
alignment attributes to cope... and if some third party library breaks
(how many libraries actually deal in double though?), I wonder if it's
possible to pragma/push/whatever your way around it...
Re: Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Thomas Munro writes:
> I see that pg_upgrade is the real problem, but if that's somehow OK
> ("v19 is a new port, dump and restore needed!") then I wonder if
> -malign=natural (which seems to be the GCC equivalent of what the
> native compiler called -qalign=natural) might be an option.
I experimented with that. It's spelled -malign-natural, and it
does change ALIGNOF_DOUBLE from 4 to 8.
> Of course
> that might create ABI problems for structs in library headers,
Yeah, that. Perhaps we'd get away with it, but I think Andres'
suggestion of putting an alignment spec into typedef float8
has a far smaller blast radius. (I tested that too, and it
seems to work.)
Side observation: either approach sets ALIGNOF_DOUBLE = 8 in both
32-bit and 64-bit builds, while ALIGNOF_INT64_T is 8 in any case.
I still think we should deprecate 32-bit AIX builds because of the
hassles around finding address space for loadable modules; but
the data alignment situation isn't different.
Of course the $64 question is whether we can get away with requiring a
dump and reload (and how we'd make pg_upgrade enforce that if we did,
considering that existing installations' pg_control will only surface
the value of MAXALIGN not DOUBLEALIGN).
regards, tom lane
Re: Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
I wrote:
> Thomas Munro writes:
>> I see that pg_upgrade is the real problem, but if that's somehow OK
>> ("v19 is a new port, dump and restore needed!") then I wonder if
>> -malign=natural (which seems to be the GCC equivalent of what the
>> native compiler called -qalign=natural) might be an option.
> Of course the $64 question is whether we can get away with requiring a
> dump and reload (and how we'd make pg_upgrade enforce that if we did,
> considering that existing installations' pg_control will only surface
> the value of MAXALIGN not DOUBLEALIGN).
Your thought of maybe applying some compiler ju-jitsu led me to a
different research direction: if we can get the compiler to lay out
the catalog structs as if DOUBLEALIGN and LONGALIGN were 4, then
problem solved without need for any user-table compatibility break.
And we can: it looks like inserting
#pragma pack(4)
before each catalog struct definition (and then "#pragma pack()"
afterwards to restore the normal rules) would do the trick.
This is probably quite gcc-specific, but if we're tossing xlc
overboard that doesn't matter.
Ideally we'd find a way to embed that in the CATALOG macros rather
than needing explicit AIX-droppings all over include/catalog/*.h.
But I'm not sure that it's possible to put a #pragma in a macro.
Even if we can't be neat about it, this is seeming like an attractive
line of inquiry.
regards, tom lane
Re: Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
I wrote:
> Your thought of maybe applying some compiler ju-jitsu led me to a
> different research direction: if we can get the compiler to lay out
> the catalog structs as if DOUBLEALIGN and LONGALIGN were 4, then
> problem solved without need for any user-table compatibility break.
> And we can: it looks like inserting
> #pragma pack(4)
> before each catalog struct definition (and then "#pragma pack()"
> afterwards to restore the normal rules) would do the trick.
Here's a POC patch to fix AIX's alignment problems that way.
I feel much better about this approach than the other one ...
regards, tom lane
From fe5383dd30b93ba738ea1300f3bdf64a016a77ec Mon Sep 17 00:00:00 2001
From: Tom Lane
Date: Fri, 6 Feb 2026 21:37:27 -0500
Subject: [PATCH v4] Cope with AIX's alignment woes by using _Pragma("pack").
Because we assume that int64 and double have the same alignment
requirement, AIX's default behavior that alignof(double) = 4 while
alignof(int64) = 8 is a headache. This POC patch shows how we might
solve that in a maintainable way without breaking pg_upgrade-ability
of existing AIX databases.
The behavior of v16 and earlier on AIX is that they'd align all
typalign = 'd' types on 4-byte boundaries, because that's what
ALIGNOF_DOUBLE comes out to. That's not ideal, because it probably
incurs some inefficiency when fetching a value that's not 8-aligned,
but that doesn't seem like a sufficient reason to break
pg_upgrade-ability. Hence we want to preserve that behavior.
The problem is that we need to overlay C structs onto catalog tuples,
and int8 fields in those struct declarations may not be aligned
correctly.
In the old branches we had some annoying rules about ordering catalog
columns to avoid alignment problems, but nobody wants to resurrect
those. However, there's a better answer: make the compiler construe
those struct declarations the way we need it to by using the pack(N)
pragma. This requires no manual effort to maintain going forward:
we only have to insert the pragma into all the catalog *.h files.
We did not have this option when the AIX port was first made. This
patch depends on the C99 feature _Pragma(), as well as the pack(N)
pragma which is probably gcc-specific. But now that we've agreed
to toss xlc support out the window, there doesn't seem to be a reason
not to go this way.
In this POC patch, I only bothered to add the BEGIN/END_CATALOG_STRUCT
macros to pg_subscription.h, but of course we'd want to add them to
all the catalog headers if we do this for real. Also, since we don't
actually have any problematic catalog columns as of HEAD, I moved
pg_subscription's subskiplsn column to artificially create an
alignment hazard. We'll probably leave subskiplsn where it is in
a final patch, since there's a nonzero hazard of breaking user
queries if we re-order the catalog's columns.
In passing, I got rid of LONGALIGN[_DOWN] along with the configure
probes for ALIGNOF_LONG. We were not using those anywhere and it
seems highly unlikely that we'd do so in future. Instead supply
INT64ALIGN[_DOWN], which isn't used either but at least could
have a good reason to be used.
Discussion: https://postgr.es/m/1127261.1769649624@sss.pgh.pa.us
---
configure | 64 ++++-----------------------
configure.ac | 30 ++++---------
meson.build | 31 ++++++-------
src/include/c.h | 4 +-
src/include/catalog/genbki.h | 19 ++++++++
src/include/catalog/pg_subscription.h | 10 +++--
src/include/pg_config.h.in | 3 --
7 files changed, 59 insertions(+), 102 deletions(-)
diff --git a/configure b/configure
index ba293931878..6ff1c9a51ed 100755
--- a/configure
+++ b/configure
@@ -17137,41 +17137,6 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
-# The cast to long int works around a bug in the HP C Compiler,
-# see AC_CHECK_SIZEOF for more information.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of long" >&5
-$as_echo_n "checking alignment of long... " >&6; }
-if ${ac_cv_alignof_long+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- if ac_fn_c_compute_int "$LINENO" "(long int) offsetof (ac__type_alignof_, y)" "ac_cv_alignof_long" "$ac_includes_default
-#ifndef offsetof
-# define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
-#endif
-typedef struct { char x; long y; } ac__type_alignof_;"; then :
-
-else
- if test "$ac_cv_type_long" = yes; then
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error 77 "cannot compute alignment of long
-See \`config.log' for more details" "$LINENO" 5; }
- else
- ac_cv_alignof_long=0
- fi
-fi
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_alignof_long" >&5
-$as_echo "$ac_cv_alignof_long" >&6; }
-
-
-
-cat >>confdefs.h <<_ACEOF
-#define ALIGNOF_LONG $ac_cv_alignof_long
-_ACEOF
-
-
# The cast to long int works around a bug in the HP C Compiler,
# see AC_CHECK_SIZEOF for more information.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of int64_t" >&5
@@ -17245,27 +17210,16 @@ _ACEOF
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that long's alignment is at least as strong as
-# char, short, or int. Note that we intentionally do not consider any types
-# wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
-# much of a penalty for disk and memory space.
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) Note that we intentionally do not consider any types wider
+# than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much
+# of a penalty for disk and memory space.
-MAX_ALIGNOF=$ac_cv_alignof_double
-
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
- as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
- as_fn_error $? "alignment of 'int64_t' is greater than the alignment of 'double'" "$LINENO" 5
+if test $ac_cv_alignof_int64_t -gt $ac_cv_alignof_double ; then
+ MAX_ALIGNOF=$ac_cv_alignof_int64_t
+else
+ MAX_ALIGNOF=$ac_cv_alignof_double
fi
cat >>confdefs.h <<_ACEOF
diff --git a/configure.ac b/configure.ac
index 412fe358a2f..0cd6299d489 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2032,33 +2032,21 @@ AC_CHECK_SIZEOF([intmax_t])
AC_CHECK_ALIGNOF(short)
AC_CHECK_ALIGNOF(int)
-AC_CHECK_ALIGNOF(long)
AC_CHECK_ALIGNOF(int64_t)
AC_CHECK_ALIGNOF(double)
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that long's alignment is at least as strong as
-# char, short, or int. Note that we intentionally do not consider any types
-# wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
-# much of a penalty for disk and memory space.
-
-MAX_ALIGNOF=$ac_cv_alignof_double
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) Note that we intentionally do not consider any types wider
+# than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much
+# of a penalty for disk and memory space.
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
- AC_MSG_ERROR([alignment of 'long' is greater than the alignment of 'double'])
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
- AC_MSG_ERROR([alignment of 'int64_t' is greater than the alignment of 'double'])
+if test $ac_cv_alignof_int64_t -gt $ac_cv_alignof_double ; then
+ MAX_ALIGNOF=$ac_cv_alignof_int64_t
+else
+ MAX_ALIGNOF=$ac_cv_alignof_double
fi
AC_DEFINE_UNQUOTED(MAXIMUM_ALIGNOF, $MAX_ALIGNOF, [Define as the maximum alignment requirement of any C data type.])
diff --git a/meson.build b/meson.build
index 0722b16927e..bbcfbdc1c65 100644
--- a/meson.build
+++ b/meson.build
@@ -1798,32 +1798,27 @@ endif
# Determine memory alignment requirements for the basic C data types.
-alignof_types = ['short', 'int', 'long', 'double']
+alignof_types = ['short', 'int', 'int64_t', 'double']
foreach t : alignof_types
- align = cc.alignment(t, args: test_c_args)
+ align = cc.alignment(t, args: test_c_args, prefix: '#include ')
cdata.set('ALIGNOF_@0@'.format(t.to_upper()), align)
endforeach
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that int64_t's alignment is at least as strong
-# as long, char, short, or int. Note that we intentionally do not consider
-# any types wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8
-# would be too much of a penalty for disk and memory space.
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) Note that we intentionally do not consider any types wider
+# than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much
+# of a penalty for disk and memory space.
+
+alignof_int64_t = cdata.get('ALIGNOF_INT64_T')
alignof_double = cdata.get('ALIGNOF_DOUBLE')
-if cc.alignment('int64_t', args: test_c_args, prefix: '#include ') > alignof_double
- error('alignment of int64_t is greater than the alignment of double')
+if alignof_int64_t > alignof_double
+ cdata.set('MAXIMUM_ALIGNOF', alignof_int64_t)
+else
+ cdata.set('MAXIMUM_ALIGNOF', alignof_double)
endif
-cdata.set('MAXIMUM_ALIGNOF', alignof_double)
cdata.set('SIZEOF_LONG', cc.sizeof('long', args: test_c_args))
cdata.set('SIZEOF_LONG_LONG', cc.sizeof('long long', args: test_c_args))
diff --git a/src/include/c.h b/src/include/c.h
index 063eac9808c..e553c57b3ca 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -821,7 +821,7 @@ typedef NameData *Name;
#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
-#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
+#define INT64ALIGN(LEN) TYPEALIGN(ALIGNOF_INT64_T, (LEN))
#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
/* MAXALIGN covers only built-in types, not buffers */
@@ -833,7 +833,7 @@ typedef NameData *Name;
#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
-#define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN))
+#define INT64ALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT64_T, (LEN))
#define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
#define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
#define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_BUFFER, (LEN))
diff --git a/src/include/catalog/genbki.h b/src/include/catalog/genbki.h
index 4606a29160e..0a5299c8e01 100644
--- a/src/include/catalog/genbki.h
+++ b/src/include/catalog/genbki.h
@@ -19,6 +19,25 @@
#ifndef GENBKI_H
#define GENBKI_H
+/*
+ * These macros should be written before and after each catalog structure
+ * definition. On most platforms they do nothing, but on some platforms
+ * we need special hacks to coax the compiler into laying out the catalog
+ * struct compatibly with our tuple forming/deforming rules.
+ *
+ * On AIX, where ALIGNOF_DOUBLE < ALIGNOF_INT64_T, we need to coerce int64
+ * catalog fields to be aligned on only 4-byte boundaries. Ideally we'd
+ * write this like pack(ALIGNOF_DOUBLE), but gcc seems unwilling to take
+ * anything but a plain string literal as the argument of _Pragma.
+ */
+#if ALIGNOF_DOUBLE < ALIGNOF_INT64_T
+#define BEGIN_CATALOG_STRUCT _Pragma("pack(4)")
+#define END_CATALOG_STRUCT _Pragma("pack()")
+#else
+#define BEGIN_CATALOG_STRUCT
+#define END_CATALOG_STRUCT
+#endif
+
/* Introduces a catalog's structure definition */
#define CATALOG(name,oid,oidmacro) typedef struct CppConcat(FormData_,name)
diff --git a/src/include/catalog/pg_subscription.h b/src/include/catalog/pg_subscription.h
index f3571d2bfcf..577c240f29c 100644
--- a/src/include/catalog/pg_subscription.h
+++ b/src/include/catalog/pg_subscription.h
@@ -40,6 +40,8 @@
* here, be sure to update that (or, if the new column is not to be publicly
* readable, update associated comments and catalogs.sgml instead).
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_subscription,6100,SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101,SubscriptionRelation_Rowtype_Id) BKI_SCHEMA_MACRO
{
Oid oid; /* oid */
@@ -47,9 +49,6 @@ CATALOG(pg_subscription,6100,SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROW
Oid subdbid BKI_LOOKUP(pg_database); /* Database the
* subscription is in. */
- XLogRecPtr subskiplsn; /* All changes finished at this LSN are
- * skipped */
-
NameData subname; /* Name of the subscription */
Oid subowner BKI_LOOKUP(pg_authid); /* Owner of the subscription */
@@ -78,6 +77,9 @@ CATALOG(pg_subscription,6100,SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROW
* slots) in the upstream database are enabled
* to be synchronized to the standbys. */
+ XLogRecPtr subskiplsn; /* All changes finished at this LSN are
+ * skipped */
+
bool subretaindeadtuples; /* True if dead tuples useful for
* conflict detection are retained */
@@ -108,6 +110,8 @@ CATALOG(pg_subscription,6100,SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROW
#endif
} FormData_pg_subscription;
+END_CATALOG_STRUCT
+
typedef FormData_pg_subscription *Form_pg_subscription;
DECLARE_TOAST_WITH_MACRO(pg_subscription, 4183, 4184, PgSubscriptionToastTable, PgSubscriptionToastIndex);
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index c089f2252c3..7410192b806 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -12,9 +12,6 @@
/* The normal alignment of `int64_t', in bytes. */
#undef ALIGNOF_INT64_T
-/* The normal alignment of `long', in bytes. */
-#undef ALIGNOF_LONG
-
/* The normal alignment of `PG_INT128_TYPE', in bytes. */
#undef ALIGNOF_PG_INT128_TYPE
--
2.43.7
RE: Decoupling our alignment assumptions about int64 and double
От:
Aditya Kamath <Aditya.Kamath1@ibm.com>
Дата:
Hi Tom and community members,
>Here's a POC patch to fix AIX's alignment problems that way.
>I feel much better about this approach than the other one …
>I feel much better about this approach than the other one …
Thank you for this POC patch.
We built the master branch with this POC patch plus meson and GNU build development patches for AIX.
We tested this in our AIX environment using DOUBLE PRECISION and BIGINT columns to verify that pg_upgrade succeeds. We first created a PostgreSQL 15 database cluster, populated it with sample records, and then upgraded it to a master-branch build that includes this patch. The upgrade completed successfully.
Below are the output snapshots and TAP test results from the master branch with this patch from our run.
pg_upgrade -b $HOME/postgres_15/postgres/install/usr/local/pgsql/bin/ -B $HOME/postgres/install/usr/local/pgsql/bin/ -d $HOME/data15 -D $HOME/datamaster --check
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database connection settings ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking data type usage ok
Checking for not-null constraint inconsistencies ok
Checking for uses of gist_inet_ops/gist_cidr_ops ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for new cluster tablespace directories ok
*Clusters are compatible*
Schema of the table:
CREATE TABLE sensor_readings (
id BIGSERIAL PRIMARY KEY,
measurement_value DOUBLE PRECISION,
count_64 BIGINT,
note TEXT
);
These were the records before the upgrade in PostgreSQL version 15,
testdb=# select * from sensor_readings;
id | measurement_value | count_64 | note
----+-------------------+----------+------------
1 | 12.45 | 1001 | Reading 1
2 | 15.02 | 1002 | Reading 2
3 | 18.77 | 1003 | Reading 3
4 | 21.05 | 1004 | Reading 4
5 | 25.61 | 1005 | Reading 5
6 | 28.43 | 1006 | Reading 6
7 | 30.12 | 1007 | Reading 7
8 | 31.98 | 1008 | Reading 8
9 | 33.47 | 1009 | Reading 9
10 | 35.22 | 1010 | Reading 10
And then after pg_upgrade in Postgresql master branch
testdb=# select * from sensor_readings;
id | measurement_value | count_64 | note
----+-------------------+----------+------------
1 | 12.45 | 1001 | Reading 1
2 | 15.02 | 1002 | Reading 2
3 | 18.77 | 1003 | Reading 3
4 | 21.05 | 1004 | Reading 4
5 | 25.61 | 1005 | Reading 5
6 | 28.43 | 1006 | Reading 6
7 | 30.12 | 1007 | Reading 7
8 | 31.98 | 1008 | Reading 8
9 | 33.47 | 1009 | Reading 9
10 | 35.22 | 1010 | Reading 10
============== GNU build TAP test results =============
t/035_standby_logical_decoding.pl ..... skipped: Injection points not supported by this build
t/036_truncated_dropped.pl ............ ok
t/037_invalid_database.pl ............. ok
t/038_save_logical_slots_shutdown.pl .. ok
t/039_end_of_wal.pl ................... ok
t/040_standby_failover_slots_sync.pl .. ok
t/041_checkpoint_at_promote.pl ........ skipped: Injection points not supported by this build
t/042_low_level_backup.pl ............. ok
t/043_no_contrecord_switch.pl ......... ok
t/044_invalidate_inactive_slots.pl .... skipped: Injection points not supported by this build
t/045_archive_restartpoint.pl ......... ok
t/046_checkpoint_logical_slot.pl ...... skipped: Injection points not supported by this build
t/047_checkpoint_physical_slot.pl ..... skipped: Injection points not supported by this build
t/048_vacuum_horizon_floor.pl ......... ok
t/049_wait_for_lsn.pl ................. ok
t/050_redo_segment_missing.pl ......... skipped: Injection points not supported by this build
t/051_effective_wal_level.pl .......... ok
All tests successful.
Files=50, Tests=584, 328 wallclock secs ( 0.11 usr 0.04 sys + 11.20 cusr 16.44 csys = 27.79 CPU)
Result: PASS
============ Meson test TAP results ====================
355/361 postgresql:pg_basebackup / pg_basebackup/040_pg_createsubscriber OK 74.88s 54 subtests passed
356/361 postgresql:recovery / recovery/027_stream_regress OK 111.07s 11 subtests passed
357/361 postgresql:pg_upgrade / pg_upgrade/006_transfer_modes OK 114.24s 40 subtests passed
358/361 postgresql:pg_verifybackup / pg_verifybackup/003_corruption OK 70.04s 92 subtests passed
359/361 postgresql:subscription / subscription/100_bugs OK 27.44s 17 subtests passed
360/361 postgresql:pg_upgrade / pg_upgrade/002_pg_upgrade OK 115.77s 19 subtests passed
361/361 postgresql:pg_basebackup / pg_basebackup/010_pg_basebackup OK 86.86s 200 subtests passed
Ok: 329
Expected Fail: 0
Fail: 0
Unexpected Pass: 0
Skipped: 32
Timeout: 0
Full log written to /home/buildusr/postgres/build/meson-logs/testlog.txt
===============
Have a nice day ahead.
Thanks and regards,
Aditya.
Re: Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Aditya Kamath writes:
> We built the master branch with this POC patch plus meson and GNU build development patches for AIX.
> We tested this in our AIX environment using DOUBLE PRECISION and BIGINT columns to verify that pg_upgrade succeeds. We first created a PostgreSQL 15 database cluster, populated it with sample records, and then upgraded it to a master-branch build that includes this patch. The upgrade completed successfully.
Cool, thanks for testing.
Here's a fleshed-out version of that patch. I propagated the
BEGIN/END_CATALOG_STRUCT macros into all the catalog headers
and removed the for-test-purposes-only column rearrangement in
pg_subscription.h. I also elected to use the push/pop variants of the
pack pragma. This makes no difference today, since we're not using
that pragma elsewhere, but conceivably it'll make this easier to work
with in future. It's otherwise the same except for a bit more
comment-smithing.
regards, tom lane
From 0c610962248e666138789b36e11efd0d1a5a5304 Mon Sep 17 00:00:00 2001
From: Tom Lane
Date: Tue, 10 Feb 2026 15:30:03 -0500
Subject: [PATCH v5] Cope with AIX's alignment woes by using _Pragma("pack").
Because we assume that int64 and double have the same alignment
requirement, AIX's default behavior that alignof(double) = 4 while
alignof(int64) = 8 is a headache. There are two issues:
1. We align both int8 and float8 tuple columns per ALIGNOF_DOUBLE,
which is an ancient choice that can't be undone without breaking
pg_upgrade and creating some subtle SQL-level compatibility issues
too. However, the cost of that is just some marginal inefficiency
in fetching int8 values, which can't be too awful if the platform
architects were willing to pay the same costs for fetching float8s.
So our decision is to leave that alone. This patch makes our
alignment choices the same as they were pre-v17, namely that
ALIGNOF_DOUBLE and ALIGNOF_INT64_T are whatever the compiler prefers
and then MAXIMUM_ALIGNOF is the larger of the two. (On all supported
platforms other than AIX, all three values will be the same.)
2. We need to overlay C structs onto catalog tuples, and int8 fields
in those struct declarations may not be aligned to match this rule.
In the old branches we had some annoying rules about ordering catalog
columns to avoid alignment problems, but nobody wants to resurrect
those. However, there's a better answer: make the compiler construe
those struct declarations the way we need it to by using the pack(N)
pragma. This requires no manual effort to maintain going forward;
we only have to insert the pragma into all the catalog *.h files.
(As the catalogs stand at this writing, nothing actually changes
because we've not moved any affected columns since v16; hence no
catversion bump is required. The point of this is to not have
to worry about the issue going forward.)
We did not have this option when the AIX port was first made. This
patch depends on the C99 feature _Pragma(), as well as the pack(N)
pragma which dates to somewhere around gcc 4.0, and probably doesn't
exist in xlc at all. But now that we've agreed to toss xlc support
out the window, there doesn't seem to be a reason not to go this way.
In passing, I got rid of LONGALIGN[_DOWN] along with the configure
probes for ALIGNOF_LONG. We were not using those anywhere and it
seems highly unlikely that we'd do so in future. Instead supply
INT64ALIGN[_DOWN], which isn't used either but at least could
have a good reason to be used.
Discussion: https://postgr.es/m/1127261.1769649624@sss.pgh.pa.us
---
configure | 68 ++++---------------
configure.ac | 32 +++------
meson.build | 33 ++++-----
src/include/c.h | 4 +-
src/include/catalog/genbki.h | 19 ++++++
src/include/catalog/pg_aggregate.h | 4 ++
src/include/catalog/pg_am.h | 4 ++
src/include/catalog/pg_amop.h | 4 ++
src/include/catalog/pg_amproc.h | 4 ++
src/include/catalog/pg_attrdef.h | 4 ++
src/include/catalog/pg_attribute.h | 4 ++
src/include/catalog/pg_auth_members.h | 4 ++
src/include/catalog/pg_authid.h | 4 ++
src/include/catalog/pg_cast.h | 4 ++
src/include/catalog/pg_class.h | 4 ++
src/include/catalog/pg_collation.h | 4 ++
src/include/catalog/pg_constraint.h | 4 ++
src/include/catalog/pg_conversion.h | 4 ++
src/include/catalog/pg_database.h | 4 ++
src/include/catalog/pg_db_role_setting.h | 4 ++
src/include/catalog/pg_default_acl.h | 4 ++
src/include/catalog/pg_depend.h | 4 ++
src/include/catalog/pg_description.h | 4 ++
src/include/catalog/pg_enum.h | 4 ++
src/include/catalog/pg_event_trigger.h | 4 ++
src/include/catalog/pg_extension.h | 4 ++
src/include/catalog/pg_foreign_data_wrapper.h | 4 ++
src/include/catalog/pg_foreign_server.h | 4 ++
src/include/catalog/pg_foreign_table.h | 4 ++
src/include/catalog/pg_index.h | 4 ++
src/include/catalog/pg_inherits.h | 4 ++
src/include/catalog/pg_init_privs.h | 4 ++
src/include/catalog/pg_language.h | 4 ++
src/include/catalog/pg_largeobject.h | 4 ++
src/include/catalog/pg_largeobject_metadata.h | 4 ++
src/include/catalog/pg_namespace.h | 4 ++
src/include/catalog/pg_opclass.h | 4 ++
src/include/catalog/pg_operator.h | 4 ++
src/include/catalog/pg_opfamily.h | 4 ++
src/include/catalog/pg_parameter_acl.h | 4 ++
src/include/catalog/pg_partitioned_table.h | 4 ++
src/include/catalog/pg_policy.h | 4 ++
src/include/catalog/pg_proc.h | 4 ++
src/include/catalog/pg_publication.h | 4 ++
.../catalog/pg_publication_namespace.h | 4 ++
src/include/catalog/pg_publication_rel.h | 4 ++
src/include/catalog/pg_range.h | 4 ++
src/include/catalog/pg_replication_origin.h | 4 ++
src/include/catalog/pg_rewrite.h | 4 ++
src/include/catalog/pg_seclabel.h | 4 ++
src/include/catalog/pg_sequence.h | 4 ++
src/include/catalog/pg_shdepend.h | 4 ++
src/include/catalog/pg_shdescription.h | 4 ++
src/include/catalog/pg_shseclabel.h | 4 ++
src/include/catalog/pg_statistic.h | 4 ++
src/include/catalog/pg_statistic_ext.h | 4 ++
src/include/catalog/pg_statistic_ext_data.h | 4 ++
src/include/catalog/pg_subscription.h | 4 ++
src/include/catalog/pg_subscription_rel.h | 4 ++
src/include/catalog/pg_tablespace.h | 4 ++
src/include/catalog/pg_transform.h | 4 ++
src/include/catalog/pg_trigger.h | 4 ++
src/include/catalog/pg_ts_config.h | 4 ++
src/include/catalog/pg_ts_config_map.h | 4 ++
src/include/catalog/pg_ts_dict.h | 4 ++
src/include/catalog/pg_ts_parser.h | 4 ++
src/include/catalog/pg_ts_template.h | 4 ++
src/include/catalog/pg_type.h | 4 ++
src/include/catalog/pg_user_mapping.h | 4 ++
src/include/pg_config.h.in | 3 -
70 files changed, 315 insertions(+), 100 deletions(-)
diff --git a/configure b/configure
index a10a2c85c6a..ef6ca1422a5 100755
--- a/configure
+++ b/configure
@@ -17095,41 +17095,6 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
-# The cast to long int works around a bug in the HP C Compiler,
-# see AC_CHECK_SIZEOF for more information.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of long" >&5
-$as_echo_n "checking alignment of long... " >&6; }
-if ${ac_cv_alignof_long+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- if ac_fn_c_compute_int "$LINENO" "(long int) offsetof (ac__type_alignof_, y)" "ac_cv_alignof_long" "$ac_includes_default
-#ifndef offsetof
-# define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
-#endif
-typedef struct { char x; long y; } ac__type_alignof_;"; then :
-
-else
- if test "$ac_cv_type_long" = yes; then
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error 77 "cannot compute alignment of long
-See \`config.log' for more details" "$LINENO" 5; }
- else
- ac_cv_alignof_long=0
- fi
-fi
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_alignof_long" >&5
-$as_echo "$ac_cv_alignof_long" >&6; }
-
-
-
-cat >>confdefs.h <<_ACEOF
-#define ALIGNOF_LONG $ac_cv_alignof_long
-_ACEOF
-
-
# The cast to long int works around a bug in the HP C Compiler,
# see AC_CHECK_SIZEOF for more information.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of int64_t" >&5
@@ -17203,27 +17168,18 @@ _ACEOF
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that long's alignment is at least as strong as
-# char, short, or int. Note that we intentionally do not consider any types
-# wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
-# much of a penalty for disk and memory space.
-
-MAX_ALIGNOF=$ac_cv_alignof_double
-
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
- as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
- as_fn_error $? "alignment of 'int64_t' is greater than the alignment of 'double'" "$LINENO" 5
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) For historical reasons, both int8 and float8 datatypes have
+# typalign 'd', and therefore will be aligned per ALIGNOF_DOUBLE in database
+# tuples even if ALIGNOF_INT64_T is more. Note that we intentionally do not
+# consider any types wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed
+# 8 would be too much of a penalty for disk and memory space.
+
+if test $ac_cv_alignof_int64_t -gt $ac_cv_alignof_double ; then
+ MAX_ALIGNOF=$ac_cv_alignof_int64_t
+else
+ MAX_ALIGNOF=$ac_cv_alignof_double
fi
cat >>confdefs.h <<_ACEOF
diff --git a/configure.ac b/configure.ac
index 814e64a967e..5edcccc0a15 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2031,33 +2031,23 @@ AC_CHECK_SIZEOF([intmax_t])
AC_CHECK_ALIGNOF(short)
AC_CHECK_ALIGNOF(int)
-AC_CHECK_ALIGNOF(long)
AC_CHECK_ALIGNOF(int64_t)
AC_CHECK_ALIGNOF(double)
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that long's alignment is at least as strong as
-# char, short, or int. Note that we intentionally do not consider any types
-# wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
-# much of a penalty for disk and memory space.
-
-MAX_ALIGNOF=$ac_cv_alignof_double
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) For historical reasons, both int8 and float8 datatypes have
+# typalign 'd', and therefore will be aligned per ALIGNOF_DOUBLE in database
+# tuples even if ALIGNOF_INT64_T is more. Note that we intentionally do not
+# consider any types wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed
+# 8 would be too much of a penalty for disk and memory space.
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
- AC_MSG_ERROR([alignment of 'long' is greater than the alignment of 'double'])
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
- AC_MSG_ERROR([alignment of 'int64_t' is greater than the alignment of 'double'])
+if test $ac_cv_alignof_int64_t -gt $ac_cv_alignof_double ; then
+ MAX_ALIGNOF=$ac_cv_alignof_int64_t
+else
+ MAX_ALIGNOF=$ac_cv_alignof_double
fi
AC_DEFINE_UNQUOTED(MAXIMUM_ALIGNOF, $MAX_ALIGNOF, [Define as the maximum alignment requirement of any C data type.])
diff --git a/meson.build b/meson.build
index 96b3869df86..4d6f6b82477 100644
--- a/meson.build
+++ b/meson.build
@@ -1798,32 +1798,29 @@ endif
# Determine memory alignment requirements for the basic C data types.
-alignof_types = ['short', 'int', 'long', 'double']
+alignof_types = ['short', 'int', 'int64_t', 'double']
foreach t : alignof_types
- align = cc.alignment(t, args: test_c_args)
+ align = cc.alignment(t, args: test_c_args, prefix: '#include ')
cdata.set('ALIGNOF_@0@'.format(t.to_upper()), align)
endforeach
# Compute maximum alignment of any basic type.
#
-# We require 'double' to have the strictest alignment among the basic types,
-# because otherwise the C ABI might impose 8-byte alignment on some of the
-# other C types that correspond to TYPALIGN_DOUBLE SQL types. That could
-# cause a mismatch between the tuple layout and the C struct layout of a
-# catalog tuple. We used to carefully order catalog columns such that any
-# fixed-width, attalign=4 columns were at offsets divisible by 8 regardless
-# of MAXIMUM_ALIGNOF to avoid that, but we no longer support any platforms
-# where TYPALIGN_DOUBLE != MAXIMUM_ALIGNOF.
-#
-# We assume without checking that int64_t's alignment is at least as strong
-# as long, char, short, or int. Note that we intentionally do not consider
-# any types wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8
-# would be too much of a penalty for disk and memory space.
+# We assume without checking that the maximum alignment requirement is that
+# of int64_t and/or double. (On most platforms those are the same, but not
+# everywhere.) For historical reasons, both int8 and float8 datatypes have
+# typalign 'd', and therefore will be aligned per ALIGNOF_DOUBLE in database
+# tuples even if ALIGNOF_INT64_T is more. Note that we intentionally do not
+# consider any types wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed
+# 8 would be too much of a penalty for disk and memory space.
+
+alignof_int64_t = cdata.get('ALIGNOF_INT64_T')
alignof_double = cdata.get('ALIGNOF_DOUBLE')
-if cc.alignment('int64_t', args: test_c_args, prefix: '#include ') > alignof_double
- error('alignment of int64_t is greater than the alignment of double')
+if alignof_int64_t > alignof_double
+ cdata.set('MAXIMUM_ALIGNOF', alignof_int64_t)
+else
+ cdata.set('MAXIMUM_ALIGNOF', alignof_double)
endif
-cdata.set('MAXIMUM_ALIGNOF', alignof_double)
cdata.set('SIZEOF_LONG', cc.sizeof('long', args: test_c_args))
cdata.set('SIZEOF_LONG_LONG', cc.sizeof('long long', args: test_c_args))
diff --git a/src/include/c.h b/src/include/c.h
index 063eac9808c..e553c57b3ca 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -821,7 +821,7 @@ typedef NameData *Name;
#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
-#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
+#define INT64ALIGN(LEN) TYPEALIGN(ALIGNOF_INT64_T, (LEN))
#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
/* MAXALIGN covers only built-in types, not buffers */
@@ -833,7 +833,7 @@ typedef NameData *Name;
#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
-#define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN))
+#define INT64ALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT64_T, (LEN))
#define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
#define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
#define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_BUFFER, (LEN))
diff --git a/src/include/catalog/genbki.h b/src/include/catalog/genbki.h
index 4606a29160e..12d2a3e295b 100644
--- a/src/include/catalog/genbki.h
+++ b/src/include/catalog/genbki.h
@@ -19,6 +19,25 @@
#ifndef GENBKI_H
#define GENBKI_H
+/*
+ * These macros should be written before and after each catalog structure
+ * definition. On most platforms they do nothing, but on some platforms
+ * we need special hacks to coax the compiler into laying out the catalog
+ * struct compatibly with our tuple forming/deforming rules.
+ *
+ * On AIX, where ALIGNOF_DOUBLE < ALIGNOF_INT64_T, we need to coerce int64
+ * catalog fields to be aligned on just 4-byte boundaries. Ideally we'd
+ * write this like pack(push,ALIGNOF_DOUBLE), but gcc seems unwilling
+ * to take anything but a plain string literal as the argument of _Pragma.
+ */
+#if ALIGNOF_DOUBLE < ALIGNOF_INT64_T
+#define BEGIN_CATALOG_STRUCT _Pragma("pack(push,4)")
+#define END_CATALOG_STRUCT _Pragma("pack(pop)")
+#else
+#define BEGIN_CATALOG_STRUCT
+#define END_CATALOG_STRUCT
+#endif
+
/* Introduces a catalog's structure definition */
#define CATALOG(name,oid,oidmacro) typedef struct CppConcat(FormData_,name)
diff --git a/src/include/catalog/pg_aggregate.h b/src/include/catalog/pg_aggregate.h
index 7ea0f64176c..2b4f5dae5f2 100644
--- a/src/include/catalog/pg_aggregate.h
+++ b/src/include/catalog/pg_aggregate.h
@@ -29,6 +29,8 @@
* cpp turns this into typedef struct FormData_pg_aggregate
* ----------------------------------------------------------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_aggregate,2600,AggregateRelationId)
{
/* pg_proc OID of the aggregate itself */
@@ -101,6 +103,8 @@ CATALOG(pg_aggregate,2600,AggregateRelationId)
#endif
} FormData_pg_aggregate;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_aggregate corresponds to a pointer to a tuple with
* the format of pg_aggregate relation.
diff --git a/src/include/catalog/pg_am.h b/src/include/catalog/pg_am.h
index e039315255c..62bc3fb8206 100644
--- a/src/include/catalog/pg_am.h
+++ b/src/include/catalog/pg_am.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_am
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_am,2601,AccessMethodRelationId)
{
Oid oid; /* oid */
@@ -40,6 +42,8 @@ CATALOG(pg_am,2601,AccessMethodRelationId)
char amtype;
} FormData_pg_am;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_am corresponds to a pointer to a tuple with
* the format of pg_am relation.
diff --git a/src/include/catalog/pg_amop.h b/src/include/catalog/pg_amop.h
index b27abb3b457..ebc774d73fb 100644
--- a/src/include/catalog/pg_amop.h
+++ b/src/include/catalog/pg_amop.h
@@ -51,6 +51,8 @@
* typedef struct FormData_pg_amop
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_amop,2602,AccessMethodOperatorRelationId)
{
Oid oid; /* oid */
@@ -80,6 +82,8 @@ CATALOG(pg_amop,2602,AccessMethodOperatorRelationId)
Oid amopsortfamily BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_opfamily);
} FormData_pg_amop;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_amop corresponds to a pointer to a tuple with
* the format of pg_amop relation.
diff --git a/src/include/catalog/pg_amproc.h b/src/include/catalog/pg_amproc.h
index 15c1201ff65..3a3869e75a9 100644
--- a/src/include/catalog/pg_amproc.h
+++ b/src/include/catalog/pg_amproc.h
@@ -40,6 +40,8 @@
* typedef struct FormData_pg_amproc
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_amproc,2603,AccessMethodProcedureRelationId)
{
Oid oid; /* oid */
@@ -60,6 +62,8 @@ CATALOG(pg_amproc,2603,AccessMethodProcedureRelationId)
regproc amproc BKI_LOOKUP(pg_proc);
} FormData_pg_amproc;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_amproc corresponds to a pointer to a tuple with
* the format of pg_amproc relation.
diff --git a/src/include/catalog/pg_attrdef.h b/src/include/catalog/pg_attrdef.h
index 89ea89a6daa..8bbc3b88827 100644
--- a/src/include/catalog/pg_attrdef.h
+++ b/src/include/catalog/pg_attrdef.h
@@ -27,6 +27,8 @@
* typedef struct FormData_pg_attrdef
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_attrdef,2604,AttrDefaultRelationId)
{
Oid oid; /* oid */
@@ -41,6 +43,8 @@ CATALOG(pg_attrdef,2604,AttrDefaultRelationId)
#endif
} FormData_pg_attrdef;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_attrdef corresponds to a pointer to a tuple with
* the format of pg_attrdef relation.
diff --git a/src/include/catalog/pg_attribute.h b/src/include/catalog/pg_attribute.h
index 45844bb752c..f33a57573f2 100644
--- a/src/include/catalog/pg_attribute.h
+++ b/src/include/catalog/pg_attribute.h
@@ -34,6 +34,8 @@
* You may need to change catalog/genbki.pl as well.
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_attribute,1249,AttributeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(75,AttributeRelation_Rowtype_Id) BKI_SCHEMA_MACRO
{
Oid attrelid BKI_LOOKUP(pg_class); /* OID of relation containing
@@ -185,6 +187,8 @@ CATALOG(pg_attribute,1249,AttributeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(75,
#endif
} FormData_pg_attribute;
+END_CATALOG_STRUCT
+
/*
* ATTRIBUTE_FIXED_PART_SIZE is the size of the fixed-layout,
* guaranteed-not-null part of a pg_attribute row. This is in fact as much
diff --git a/src/include/catalog/pg_auth_members.h b/src/include/catalog/pg_auth_members.h
index 92cf5271496..b1902321a8f 100644
--- a/src/include/catalog/pg_auth_members.h
+++ b/src/include/catalog/pg_auth_members.h
@@ -27,6 +27,8 @@
* typedef struct FormData_pg_auth_members
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_auth_members,1261,AuthMemRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(2843,AuthMemRelation_Rowtype_Id) BKI_SCHEMA_MACRO
{
Oid oid; /* oid */
@@ -38,6 +40,8 @@ CATALOG(pg_auth_members,1261,AuthMemRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_
bool set_option; /* use SET ROLE to the target role? */
} FormData_pg_auth_members;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_auth_members corresponds to a pointer to a tuple with
* the format of pg_auth_members relation.
diff --git a/src/include/catalog/pg_authid.h b/src/include/catalog/pg_authid.h
index bddb154cd1b..baf5b099797 100644
--- a/src/include/catalog/pg_authid.h
+++ b/src/include/catalog/pg_authid.h
@@ -28,6 +28,8 @@
* typedef struct FormData_pg_authid
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_authid,1260,AuthIdRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(2842,AuthIdRelation_Rowtype_Id) BKI_SCHEMA_MACRO
{
Oid oid; /* oid */
@@ -48,6 +50,8 @@ CATALOG(pg_authid,1260,AuthIdRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(284
#endif
} FormData_pg_authid;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_authid corresponds to a pointer to a tuple with
* the format of pg_authid relation.
diff --git a/src/include/catalog/pg_cast.h b/src/include/catalog/pg_cast.h
index 2c9633a5ecb..d81314946ee 100644
--- a/src/include/catalog/pg_cast.h
+++ b/src/include/catalog/pg_cast.h
@@ -29,6 +29,8 @@
* typedef struct FormData_pg_cast
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_cast,2605,CastRelationId)
{
Oid oid; /* oid */
@@ -49,6 +51,8 @@ CATALOG(pg_cast,2605,CastRelationId)
char castmethod;
} FormData_pg_cast;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_cast corresponds to a pointer to a tuple with
* the format of pg_cast relation.
diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h
index 89ab34c8349..ae6e36aeff6 100644
--- a/src/include/catalog/pg_class.h
+++ b/src/include/catalog/pg_class.h
@@ -29,6 +29,8 @@
* BKI_BOOTSTRAP catalogs, since only those rows appear in pg_class.dat.
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,RelationRelation_Rowtype_Id) BKI_SCHEMA_MACRO
{
/* oid */
@@ -144,6 +146,8 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat
#endif
} FormData_pg_class;
+END_CATALOG_STRUCT
+
/* Size of fixed part of pg_class tuples, not counting var-length fields */
#define CLASS_TUPLE_SIZE \
(offsetof(FormData_pg_class,relminmxid) + sizeof(TransactionId))
diff --git a/src/include/catalog/pg_collation.h b/src/include/catalog/pg_collation.h
index 11abde18be9..8b1917ee99f 100644
--- a/src/include/catalog/pg_collation.h
+++ b/src/include/catalog/pg_collation.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_collation
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_collation,3456,CollationRelationId)
{
Oid oid; /* oid */
@@ -50,6 +52,8 @@ CATALOG(pg_collation,3456,CollationRelationId)
#endif
} FormData_pg_collation;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_collation corresponds to a pointer to a row with
* the format of pg_collation relation.
diff --git a/src/include/catalog/pg_constraint.h b/src/include/catalog/pg_constraint.h
index d5661b5bdff..1b7fedf1750 100644
--- a/src/include/catalog/pg_constraint.h
+++ b/src/include/catalog/pg_constraint.h
@@ -28,6 +28,8 @@
* typedef struct FormData_pg_constraint
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_constraint,2606,ConstraintRelationId)
{
Oid oid; /* oid */
@@ -167,6 +169,8 @@ CATALOG(pg_constraint,2606,ConstraintRelationId)
#endif
} FormData_pg_constraint;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_constraint corresponds to a pointer to a tuple with
* the format of pg_constraint relation.
diff --git a/src/include/catalog/pg_conversion.h b/src/include/catalog/pg_conversion.h
index f6a3d14e6b3..71f5de90497 100644
--- a/src/include/catalog/pg_conversion.h
+++ b/src/include/catalog/pg_conversion.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_conversion
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_conversion,2607,ConversionRelationId)
{
/* oid */
@@ -53,6 +55,8 @@ CATALOG(pg_conversion,2607,ConversionRelationId)
bool condefault BKI_DEFAULT(t);
} FormData_pg_conversion;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_conversion corresponds to a pointer to a tuple with
* the format of pg_conversion relation.
diff --git a/src/include/catalog/pg_database.h b/src/include/catalog/pg_database.h
index a380bdc5134..8a495e96eed 100644
--- a/src/include/catalog/pg_database.h
+++ b/src/include/catalog/pg_database.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_database
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_database,1262,DatabaseRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(1248,DatabaseRelation_Rowtype_Id) BKI_SCHEMA_MACRO
{
/* oid */
@@ -88,6 +90,8 @@ CATALOG(pg_database,1262,DatabaseRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID
#endif
} FormData_pg_database;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_database corresponds to a pointer to a tuple with
* the format of pg_database relation.
diff --git a/src/include/catalog/pg_db_role_setting.h b/src/include/catalog/pg_db_role_setting.h
index c2d728b03db..f1cbba020b2 100644
--- a/src/include/catalog/pg_db_role_setting.h
+++ b/src/include/catalog/pg_db_role_setting.h
@@ -31,6 +31,8 @@
* typedef struct FormData_pg_db_role_setting
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_db_role_setting,2964,DbRoleSettingRelationId) BKI_SHARED_RELATION
{
/* database, or 0 for a role-specific setting */
@@ -44,6 +46,8 @@ CATALOG(pg_db_role_setting,2964,DbRoleSettingRelationId) BKI_SHARED_RELATION
#endif
} FormData_pg_db_role_setting;
+END_CATALOG_STRUCT
+
typedef FormData_pg_db_role_setting * Form_pg_db_role_setting;
DECLARE_TOAST_WITH_MACRO(pg_db_role_setting, 2966, 2967, PgDbRoleSettingToastTable, PgDbRoleSettingToastIndex);
diff --git a/src/include/catalog/pg_default_acl.h b/src/include/catalog/pg_default_acl.h
index c9cb4580010..dc1722f7a68 100644
--- a/src/include/catalog/pg_default_acl.h
+++ b/src/include/catalog/pg_default_acl.h
@@ -27,6 +27,8 @@
* typedef struct FormData_pg_default_acl
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_default_acl,826,DefaultAclRelationId)
{
Oid oid; /* oid */
@@ -42,6 +44,8 @@ CATALOG(pg_default_acl,826,DefaultAclRelationId)
#endif
} FormData_pg_default_acl;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_default_acl corresponds to a pointer to a tuple with
* the format of pg_default_acl relation.
diff --git a/src/include/catalog/pg_depend.h b/src/include/catalog/pg_depend.h
index 6b849bc6d4c..af1423ade44 100644
--- a/src/include/catalog/pg_depend.h
+++ b/src/include/catalog/pg_depend.h
@@ -39,6 +39,8 @@
* typedef struct FormData_pg_depend
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_depend,2608,DependRelationId)
{
/*
@@ -64,6 +66,8 @@ CATALOG(pg_depend,2608,DependRelationId)
char deptype; /* see codes in dependency.h */
} FormData_pg_depend;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_depend corresponds to a pointer to a row with
* the format of pg_depend relation.
diff --git a/src/include/catalog/pg_description.h b/src/include/catalog/pg_description.h
index 03fb1555037..98971d8ca11 100644
--- a/src/include/catalog/pg_description.h
+++ b/src/include/catalog/pg_description.h
@@ -45,6 +45,8 @@
* typedef struct FormData_pg_description
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_description,2609,DescriptionRelationId)
{
Oid objoid; /* OID of object itself */
@@ -56,6 +58,8 @@ CATALOG(pg_description,2609,DescriptionRelationId)
#endif
} FormData_pg_description;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_description corresponds to a pointer to a tuple with
* the format of pg_description relation.
diff --git a/src/include/catalog/pg_enum.h b/src/include/catalog/pg_enum.h
index cbcc8fa6280..a1c73817fff 100644
--- a/src/include/catalog/pg_enum.h
+++ b/src/include/catalog/pg_enum.h
@@ -28,6 +28,8 @@
* typedef struct FormData_pg_enum
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_enum,3501,EnumRelationId)
{
Oid oid; /* oid */
@@ -36,6 +38,8 @@ CATALOG(pg_enum,3501,EnumRelationId)
NameData enumlabel; /* text representation of enum value */
} FormData_pg_enum;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_enum corresponds to a pointer to a tuple with
* the format of pg_enum relation.
diff --git a/src/include/catalog/pg_event_trigger.h b/src/include/catalog/pg_event_trigger.h
index c24113c2973..eaacaaf2e2c 100644
--- a/src/include/catalog/pg_event_trigger.h
+++ b/src/include/catalog/pg_event_trigger.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_event_trigger
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_event_trigger,3466,EventTriggerRelationId)
{
Oid oid; /* oid */
@@ -42,6 +44,8 @@ CATALOG(pg_event_trigger,3466,EventTriggerRelationId)
#endif
} FormData_pg_event_trigger;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_event_trigger corresponds to a pointer to a tuple with
* the format of pg_event_trigger relation.
diff --git a/src/include/catalog/pg_extension.h b/src/include/catalog/pg_extension.h
index 8ab5e3141d0..19ec291ad7e 100644
--- a/src/include/catalog/pg_extension.h
+++ b/src/include/catalog/pg_extension.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_extension
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_extension,3079,ExtensionRelationId)
{
Oid oid; /* oid */
@@ -44,6 +46,8 @@ CATALOG(pg_extension,3079,ExtensionRelationId)
#endif
} FormData_pg_extension;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_extension corresponds to a pointer to a tuple with
* the format of pg_extension relation.
diff --git a/src/include/catalog/pg_foreign_data_wrapper.h b/src/include/catalog/pg_foreign_data_wrapper.h
index d47bf467810..e6009069e82 100644
--- a/src/include/catalog/pg_foreign_data_wrapper.h
+++ b/src/include/catalog/pg_foreign_data_wrapper.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_foreign_data_wrapper
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_foreign_data_wrapper,2328,ForeignDataWrapperRelationId)
{
Oid oid; /* oid */
@@ -43,6 +45,8 @@ CATALOG(pg_foreign_data_wrapper,2328,ForeignDataWrapperRelationId)
#endif
} FormData_pg_foreign_data_wrapper;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_foreign_data_wrapper corresponds to a pointer to a tuple with
* the format of pg_foreign_data_wrapper relation.
diff --git a/src/include/catalog/pg_foreign_server.h b/src/include/catalog/pg_foreign_server.h
index beee97a4ddb..cac0b9faafe 100644
--- a/src/include/catalog/pg_foreign_server.h
+++ b/src/include/catalog/pg_foreign_server.h
@@ -25,6 +25,8 @@
* typedef struct FormData_pg_foreign_server
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_foreign_server,1417,ForeignServerRelationId)
{
Oid oid; /* oid */
@@ -40,6 +42,8 @@ CATALOG(pg_foreign_server,1417,ForeignServerRelationId)
#endif
} FormData_pg_foreign_server;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_foreign_server corresponds to a pointer to a tuple with
* the format of pg_foreign_server relation.
diff --git a/src/include/catalog/pg_foreign_table.h b/src/include/catalog/pg_foreign_table.h
index 35c858f9de3..601115c183d 100644
--- a/src/include/catalog/pg_foreign_table.h
+++ b/src/include/catalog/pg_foreign_table.h
@@ -25,6 +25,8 @@
* typedef struct FormData_pg_foreign_table
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_foreign_table,3118,ForeignTableRelationId)
{
Oid ftrelid BKI_LOOKUP(pg_class); /* OID of foreign table */
@@ -35,6 +37,8 @@ CATALOG(pg_foreign_table,3118,ForeignTableRelationId)
#endif
} FormData_pg_foreign_table;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_foreign_table corresponds to a pointer to a tuple with
* the format of pg_foreign_table relation.
diff --git a/src/include/catalog/pg_index.h b/src/include/catalog/pg_index.h
index 02c99d70faf..d722efe49b4 100644
--- a/src/include/catalog/pg_index.h
+++ b/src/include/catalog/pg_index.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_index.
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_index,2610,IndexRelationId) BKI_SCHEMA_MACRO
{
Oid indexrelid BKI_LOOKUP(pg_class); /* OID of the index */
@@ -62,6 +64,8 @@ CATALOG(pg_index,2610,IndexRelationId) BKI_SCHEMA_MACRO
#endif
} FormData_pg_index;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_index corresponds to a pointer to a tuple with
* the format of pg_index relation.
diff --git a/src/include/catalog/pg_inherits.h b/src/include/catalog/pg_inherits.h
index c14aee773c3..7a36241d7b3 100644
--- a/src/include/catalog/pg_inherits.h
+++ b/src/include/catalog/pg_inherits.h
@@ -29,6 +29,8 @@
* typedef struct FormData_pg_inherits
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_inherits,2611,InheritsRelationId)
{
Oid inhrelid BKI_LOOKUP(pg_class);
@@ -37,6 +39,8 @@ CATALOG(pg_inherits,2611,InheritsRelationId)
bool inhdetachpending;
} FormData_pg_inherits;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_inherits corresponds to a pointer to a tuple with
* the format of pg_inherits relation.
diff --git a/src/include/catalog/pg_init_privs.h b/src/include/catalog/pg_init_privs.h
index 71d6d1c90d0..44c7e50d470 100644
--- a/src/include/catalog/pg_init_privs.h
+++ b/src/include/catalog/pg_init_privs.h
@@ -43,6 +43,8 @@
* typedef struct FormData_pg_init_privs
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_init_privs,3394,InitPrivsRelationId)
{
Oid objoid; /* OID of object itself */
@@ -56,6 +58,8 @@ CATALOG(pg_init_privs,3394,InitPrivsRelationId)
#endif
} FormData_pg_init_privs;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_init_privs corresponds to a pointer to a tuple with
* the format of pg_init_privs relation.
diff --git a/src/include/catalog/pg_language.h b/src/include/catalog/pg_language.h
index b049f20515a..d64e4525547 100644
--- a/src/include/catalog/pg_language.h
+++ b/src/include/catalog/pg_language.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_language
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_language,2612,LanguageRelationId)
{
Oid oid; /* oid */
@@ -57,6 +59,8 @@ CATALOG(pg_language,2612,LanguageRelationId)
#endif
} FormData_pg_language;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_language corresponds to a pointer to a tuple with
* the format of pg_language relation.
diff --git a/src/include/catalog/pg_largeobject.h b/src/include/catalog/pg_largeobject.h
index 8f845267c73..4f3c14c7eda 100644
--- a/src/include/catalog/pg_largeobject.h
+++ b/src/include/catalog/pg_largeobject.h
@@ -27,6 +27,8 @@
* typedef struct FormData_pg_largeobject
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_largeobject,2613,LargeObjectRelationId)
{
Oid loid BKI_LOOKUP(pg_largeobject_metadata); /* Identifier of large
@@ -38,6 +40,8 @@ CATALOG(pg_largeobject,2613,LargeObjectRelationId)
* zero-length) */
} FormData_pg_largeobject;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_largeobject corresponds to a pointer to a tuple with
* the format of pg_largeobject relation.
diff --git a/src/include/catalog/pg_largeobject_metadata.h b/src/include/catalog/pg_largeobject_metadata.h
index 2ace42e4096..86f369255d4 100644
--- a/src/include/catalog/pg_largeobject_metadata.h
+++ b/src/include/catalog/pg_largeobject_metadata.h
@@ -27,6 +27,8 @@
* typedef struct FormData_pg_largeobject_metadata
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_largeobject_metadata,2995,LargeObjectMetadataRelationId)
{
Oid oid; /* oid */
@@ -39,6 +41,8 @@ CATALOG(pg_largeobject_metadata,2995,LargeObjectMetadataRelationId)
#endif
} FormData_pg_largeobject_metadata;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_largeobject_metadata corresponds to a pointer to a tuple
* with the format of pg_largeobject_metadata relation.
diff --git a/src/include/catalog/pg_namespace.h b/src/include/catalog/pg_namespace.h
index a84a8db194b..474f4c574e0 100644
--- a/src/include/catalog/pg_namespace.h
+++ b/src/include/catalog/pg_namespace.h
@@ -32,6 +32,8 @@
* nspacl access privilege list
* ----------------------------------------------------------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_namespace,2615,NamespaceRelationId)
{
Oid oid; /* oid */
@@ -44,6 +46,8 @@ CATALOG(pg_namespace,2615,NamespaceRelationId)
#endif
} FormData_pg_namespace;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_namespace corresponds to a pointer to a tuple with
* the format of pg_namespace relation.
diff --git a/src/include/catalog/pg_opclass.h b/src/include/catalog/pg_opclass.h
index 4fed59acb0e..46170c6c3c3 100644
--- a/src/include/catalog/pg_opclass.h
+++ b/src/include/catalog/pg_opclass.h
@@ -46,6 +46,8 @@
* typedef struct FormData_pg_opclass
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_opclass,2616,OperatorClassRelationId)
{
Oid oid; /* oid */
@@ -75,6 +77,8 @@ CATALOG(pg_opclass,2616,OperatorClassRelationId)
Oid opckeytype BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_type);
} FormData_pg_opclass;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_opclass corresponds to a pointer to a tuple with
* the format of pg_opclass relation.
diff --git a/src/include/catalog/pg_operator.h b/src/include/catalog/pg_operator.h
index 89bec146f5c..f5b4d04783a 100644
--- a/src/include/catalog/pg_operator.h
+++ b/src/include/catalog/pg_operator.h
@@ -28,6 +28,8 @@
* typedef struct FormData_pg_operator
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_operator,2617,OperatorRelationId)
{
Oid oid; /* oid */
@@ -75,6 +77,8 @@ CATALOG(pg_operator,2617,OperatorRelationId)
regproc oprjoin BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
} FormData_pg_operator;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_operator corresponds to a pointer to a tuple with
* the format of pg_operator relation.
diff --git a/src/include/catalog/pg_opfamily.h b/src/include/catalog/pg_opfamily.h
index afebcc9ae5a..563703f0f22 100644
--- a/src/include/catalog/pg_opfamily.h
+++ b/src/include/catalog/pg_opfamily.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_opfamily
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_opfamily,2753,OperatorFamilyRelationId)
{
Oid oid; /* oid */
@@ -43,6 +45,8 @@ CATALOG(pg_opfamily,2753,OperatorFamilyRelationId)
Oid opfowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
} FormData_pg_opfamily;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_opfamily corresponds to a pointer to a tuple with
* the format of pg_opfamily relation.
diff --git a/src/include/catalog/pg_parameter_acl.h b/src/include/catalog/pg_parameter_acl.h
index 13a85db92db..a26b05a9bf2 100644
--- a/src/include/catalog/pg_parameter_acl.h
+++ b/src/include/catalog/pg_parameter_acl.h
@@ -27,6 +27,8 @@
* typedef struct FormData_pg_parameter_acl
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_parameter_acl,6243,ParameterAclRelationId) BKI_SHARED_RELATION
{
Oid oid; /* oid */
@@ -40,6 +42,8 @@ CATALOG(pg_parameter_acl,6243,ParameterAclRelationId) BKI_SHARED_RELATION
#endif
} FormData_pg_parameter_acl;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_parameter_acl corresponds to a pointer to a tuple with
diff --git a/src/include/catalog/pg_partitioned_table.h b/src/include/catalog/pg_partitioned_table.h
index e9a67bf6d40..db477951018 100644
--- a/src/include/catalog/pg_partitioned_table.h
+++ b/src/include/catalog/pg_partitioned_table.h
@@ -27,6 +27,8 @@
* typedef struct FormData_pg_partitioned_table
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_partitioned_table,3350,PartitionedRelationId)
{
Oid partrelid BKI_LOOKUP(pg_class); /* partitioned table oid */
@@ -57,6 +59,8 @@ CATALOG(pg_partitioned_table,3350,PartitionedRelationId)
#endif
} FormData_pg_partitioned_table;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_partitioned_table corresponds to a pointer to a tuple with
* the format of pg_partitioned_table relation.
diff --git a/src/include/catalog/pg_policy.h b/src/include/catalog/pg_policy.h
index f64af8e3279..5bcaf0cd896 100644
--- a/src/include/catalog/pg_policy.h
+++ b/src/include/catalog/pg_policy.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_policy
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_policy,3256,PolicyRelationId)
{
Oid oid; /* oid */
@@ -43,6 +45,8 @@ CATALOG(pg_policy,3256,PolicyRelationId)
#endif
} FormData_pg_policy;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_policy corresponds to a pointer to a row with
* the format of pg_policy relation.
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 6ada01d6e19..2f9e0b695e2 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -27,6 +27,8 @@
* typedef struct FormData_pg_proc
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_proc,1255,ProcedureRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81,ProcedureRelation_Rowtype_Id) BKI_SCHEMA_MACRO
{
Oid oid; /* oid */
@@ -128,6 +130,8 @@ CATALOG(pg_proc,1255,ProcedureRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81,Proce
#endif
} FormData_pg_proc;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_proc corresponds to a pointer to a tuple with
* the format of pg_proc relation.
diff --git a/src/include/catalog/pg_publication.h b/src/include/catalog/pg_publication.h
index 368becca899..6e5f73caa9e 100644
--- a/src/include/catalog/pg_publication.h
+++ b/src/include/catalog/pg_publication.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_publication
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_publication,6104,PublicationRelationId)
{
Oid oid; /* oid */
@@ -68,6 +70,8 @@ CATALOG(pg_publication,6104,PublicationRelationId)
char pubgencols;
} FormData_pg_publication;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_publication corresponds to a pointer to a tuple with
* the format of pg_publication relation.
diff --git a/src/include/catalog/pg_publication_namespace.h b/src/include/catalog/pg_publication_namespace.h
index 1ce84fb5da9..6c21b248db2 100644
--- a/src/include/catalog/pg_publication_namespace.h
+++ b/src/include/catalog/pg_publication_namespace.h
@@ -27,6 +27,8 @@
* typedef struct FormData_pg_publication_namespace
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_publication_namespace,6237,PublicationNamespaceRelationId)
{
Oid oid; /* oid */
@@ -34,6 +36,8 @@ CATALOG(pg_publication_namespace,6237,PublicationNamespaceRelationId)
Oid pnnspid BKI_LOOKUP(pg_namespace); /* Oid of the schema */
} FormData_pg_publication_namespace;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_publication_namespace corresponds to a pointer to a tuple with
* the format of pg_publication_namespace relation.
diff --git a/src/include/catalog/pg_publication_rel.h b/src/include/catalog/pg_publication_rel.h
index 3a8790e8482..63eb7c75f53 100644
--- a/src/include/catalog/pg_publication_rel.h
+++ b/src/include/catalog/pg_publication_rel.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_publication_rel
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_publication_rel,6106,PublicationRelRelationId)
{
Oid oid; /* oid */
@@ -38,6 +40,8 @@ CATALOG(pg_publication_rel,6106,PublicationRelRelationId)
#endif
} FormData_pg_publication_rel;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_publication_rel corresponds to a pointer to a tuple with
* the format of pg_publication_rel relation.
diff --git a/src/include/catalog/pg_range.h b/src/include/catalog/pg_range.h
index 32ee8cf43a0..ee87ed3bf42 100644
--- a/src/include/catalog/pg_range.h
+++ b/src/include/catalog/pg_range.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_range
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_range,3541,RangeRelationId)
{
/* OID of owning range type */
@@ -59,6 +61,8 @@ CATALOG(pg_range,3541,RangeRelationId)
regproc rngsubdiff BKI_LOOKUP_OPT(pg_proc);
} FormData_pg_range;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_range corresponds to a pointer to a tuple with
* the format of pg_range relation.
diff --git a/src/include/catalog/pg_replication_origin.h b/src/include/catalog/pg_replication_origin.h
index bf54442fd06..565d71ad0b3 100644
--- a/src/include/catalog/pg_replication_origin.h
+++ b/src/include/catalog/pg_replication_origin.h
@@ -27,6 +27,8 @@
* typedef struct FormData_pg_replication_origin
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_replication_origin,6000,ReplicationOriginRelationId) BKI_SHARED_RELATION
{
/*
@@ -52,6 +54,8 @@ CATALOG(pg_replication_origin,6000,ReplicationOriginRelationId) BKI_SHARED_RELAT
#endif
} FormData_pg_replication_origin;
+END_CATALOG_STRUCT
+
typedef FormData_pg_replication_origin *Form_pg_replication_origin;
DECLARE_UNIQUE_INDEX_PKEY(pg_replication_origin_roiident_index, 6001, ReplicationOriginIdentIndex, pg_replication_origin, btree(roident oid_ops));
diff --git a/src/include/catalog/pg_rewrite.h b/src/include/catalog/pg_rewrite.h
index c9ce420eb6f..fe82e84be4e 100644
--- a/src/include/catalog/pg_rewrite.h
+++ b/src/include/catalog/pg_rewrite.h
@@ -29,6 +29,8 @@
* typedef struct FormData_pg_rewrite
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_rewrite,2618,RewriteRelationId)
{
Oid oid; /* oid */
@@ -44,6 +46,8 @@ CATALOG(pg_rewrite,2618,RewriteRelationId)
#endif
} FormData_pg_rewrite;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_rewrite corresponds to a pointer to a tuple with
* the format of pg_rewrite relation.
diff --git a/src/include/catalog/pg_seclabel.h b/src/include/catalog/pg_seclabel.h
index 0c9d094b81b..8f5788ca663 100644
--- a/src/include/catalog/pg_seclabel.h
+++ b/src/include/catalog/pg_seclabel.h
@@ -25,6 +25,8 @@
* typedef struct FormData_pg_seclabel
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_seclabel,3596,SecLabelRelationId)
{
Oid objoid; /* OID of the object itself */
@@ -38,6 +40,8 @@ CATALOG(pg_seclabel,3596,SecLabelRelationId)
#endif
} FormData_pg_seclabel;
+END_CATALOG_STRUCT
+
DECLARE_TOAST(pg_seclabel, 3598, 3599);
DECLARE_UNIQUE_INDEX_PKEY(pg_seclabel_object_index, 3597, SecLabelObjectIndexId, pg_seclabel, btree(objoid oid_ops, classoid oid_ops, objsubid int4_ops, provider text_ops));
diff --git a/src/include/catalog/pg_sequence.h b/src/include/catalog/pg_sequence.h
index f8b9eaa9270..59820a86b8b 100644
--- a/src/include/catalog/pg_sequence.h
+++ b/src/include/catalog/pg_sequence.h
@@ -20,6 +20,8 @@
#include "catalog/genbki.h"
#include "catalog/pg_sequence_d.h" /* IWYU pragma: export */
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_sequence,2224,SequenceRelationId)
{
Oid seqrelid BKI_LOOKUP(pg_class);
@@ -32,6 +34,8 @@ CATALOG(pg_sequence,2224,SequenceRelationId)
bool seqcycle;
} FormData_pg_sequence;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_sequence corresponds to a pointer to a tuple with
* the format of pg_sequence relation.
diff --git a/src/include/catalog/pg_shdepend.h b/src/include/catalog/pg_shdepend.h
index 5e0945c55f2..80d5eb0255e 100644
--- a/src/include/catalog/pg_shdepend.h
+++ b/src/include/catalog/pg_shdepend.h
@@ -35,6 +35,8 @@
* typedef struct FormData_pg_shdepend
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_shdepend,1214,SharedDependRelationId) BKI_SHARED_RELATION
{
/*
@@ -65,6 +67,8 @@ CATALOG(pg_shdepend,1214,SharedDependRelationId) BKI_SHARED_RELATION
char deptype; /* see codes in dependency.h */
} FormData_pg_shdepend;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_shdepend corresponds to a pointer to a row with
* the format of pg_shdepend relation.
diff --git a/src/include/catalog/pg_shdescription.h b/src/include/catalog/pg_shdescription.h
index 8fad7972d4c..f53d9f5dcd6 100644
--- a/src/include/catalog/pg_shdescription.h
+++ b/src/include/catalog/pg_shdescription.h
@@ -38,6 +38,8 @@
* typedef struct FormData_pg_shdescription
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_shdescription,2396,SharedDescriptionRelationId) BKI_SHARED_RELATION
{
Oid objoid; /* OID of object itself */
@@ -48,6 +50,8 @@ CATALOG(pg_shdescription,2396,SharedDescriptionRelationId) BKI_SHARED_RELATION
#endif
} FormData_pg_shdescription;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_shdescription corresponds to a pointer to a tuple with
* the format of pg_shdescription relation.
diff --git a/src/include/catalog/pg_shseclabel.h b/src/include/catalog/pg_shseclabel.h
index c13ced36850..273c7790194 100644
--- a/src/include/catalog/pg_shseclabel.h
+++ b/src/include/catalog/pg_shseclabel.h
@@ -25,6 +25,8 @@
* typedef struct FormData_pg_shseclabel
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_shseclabel,3592,SharedSecLabelRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(4066,SharedSecLabelRelation_Rowtype_Id) BKI_SCHEMA_MACRO
{
Oid objoid; /* OID of the shared object itself */
@@ -37,6 +39,8 @@ CATALOG(pg_shseclabel,3592,SharedSecLabelRelationId) BKI_SHARED_RELATION BKI_ROW
#endif
} FormData_pg_shseclabel;
+END_CATALOG_STRUCT
+
typedef FormData_pg_shseclabel * Form_pg_shseclabel;
DECLARE_TOAST_WITH_MACRO(pg_shseclabel, 4060, 4061, PgShseclabelToastTable, PgShseclabelToastIndex);
diff --git a/src/include/catalog/pg_statistic.h b/src/include/catalog/pg_statistic.h
index c31c163d0cc..032bf177b95 100644
--- a/src/include/catalog/pg_statistic.h
+++ b/src/include/catalog/pg_statistic.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_statistic
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_statistic,2619,StatisticRelationId)
{
/* These fields form the unique key for the entry: */
@@ -124,6 +126,8 @@ CATALOG(pg_statistic,2619,StatisticRelationId)
#endif
} FormData_pg_statistic;
+END_CATALOG_STRUCT
+
#define STATISTIC_NUM_SLOTS 5
diff --git a/src/include/catalog/pg_statistic_ext.h b/src/include/catalog/pg_statistic_ext.h
index 6842954d4cb..e4a0cb4d41c 100644
--- a/src/include/catalog/pg_statistic_ext.h
+++ b/src/include/catalog/pg_statistic_ext.h
@@ -30,6 +30,8 @@
* typedef struct FormData_pg_statistic_ext
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_statistic_ext,3381,StatisticExtRelationId)
{
Oid oid; /* oid */
@@ -61,6 +63,8 @@ CATALOG(pg_statistic_ext,3381,StatisticExtRelationId)
} FormData_pg_statistic_ext;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_statistic_ext corresponds to a pointer to a tuple with
* the format of pg_statistic_ext relation.
diff --git a/src/include/catalog/pg_statistic_ext_data.h b/src/include/catalog/pg_statistic_ext_data.h
index 7b7f2593491..dbc4acc7d1a 100644
--- a/src/include/catalog/pg_statistic_ext_data.h
+++ b/src/include/catalog/pg_statistic_ext_data.h
@@ -28,6 +28,8 @@
* typedef struct FormData_pg_statistic_ext_data
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_statistic_ext_data,3429,StatisticExtDataRelationId)
{
Oid stxoid BKI_LOOKUP(pg_statistic_ext); /* statistics object
@@ -45,6 +47,8 @@ CATALOG(pg_statistic_ext_data,3429,StatisticExtDataRelationId)
} FormData_pg_statistic_ext_data;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_statistic_ext_data corresponds to a pointer to a tuple with
* the format of pg_statistic_ext_data relation.
diff --git a/src/include/catalog/pg_subscription.h b/src/include/catalog/pg_subscription.h
index f3571d2bfcf..45d7a975ed2 100644
--- a/src/include/catalog/pg_subscription.h
+++ b/src/include/catalog/pg_subscription.h
@@ -40,6 +40,8 @@
* here, be sure to update that (or, if the new column is not to be publicly
* readable, update associated comments and catalogs.sgml instead).
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_subscription,6100,SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101,SubscriptionRelation_Rowtype_Id) BKI_SCHEMA_MACRO
{
Oid oid; /* oid */
@@ -108,6 +110,8 @@ CATALOG(pg_subscription,6100,SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROW
#endif
} FormData_pg_subscription;
+END_CATALOG_STRUCT
+
typedef FormData_pg_subscription *Form_pg_subscription;
DECLARE_TOAST_WITH_MACRO(pg_subscription, 4183, 4184, PgSubscriptionToastTable, PgSubscriptionToastIndex);
diff --git a/src/include/catalog/pg_subscription_rel.h b/src/include/catalog/pg_subscription_rel.h
index f810b34c78d..502640d3018 100644
--- a/src/include/catalog/pg_subscription_rel.h
+++ b/src/include/catalog/pg_subscription_rel.h
@@ -28,6 +28,8 @@
* typedef struct FormData_pg_subscription_rel
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_subscription_rel,6102,SubscriptionRelRelationId)
{
Oid srsubid BKI_LOOKUP(pg_subscription); /* Oid of subscription */
@@ -47,6 +49,8 @@ CATALOG(pg_subscription_rel,6102,SubscriptionRelRelationId)
#endif
} FormData_pg_subscription_rel;
+END_CATALOG_STRUCT
+
typedef FormData_pg_subscription_rel *Form_pg_subscription_rel;
DECLARE_UNIQUE_INDEX_PKEY(pg_subscription_rel_srrelid_srsubid_index, 6117, SubscriptionRelSrrelidSrsubidIndexId, pg_subscription_rel, btree(srrelid oid_ops, srsubid oid_ops));
diff --git a/src/include/catalog/pg_tablespace.h b/src/include/catalog/pg_tablespace.h
index fe7a5ab538f..3bd4a74f003 100644
--- a/src/include/catalog/pg_tablespace.h
+++ b/src/include/catalog/pg_tablespace.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_tablespace
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_tablespace,1213,TableSpaceRelationId) BKI_SHARED_RELATION
{
Oid oid; /* oid */
@@ -40,6 +42,8 @@ CATALOG(pg_tablespace,1213,TableSpaceRelationId) BKI_SHARED_RELATION
#endif
} FormData_pg_tablespace;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_tablespace corresponds to a pointer to a tuple with
* the format of pg_tablespace relation.
diff --git a/src/include/catalog/pg_transform.h b/src/include/catalog/pg_transform.h
index f8bdad17897..115608de43c 100644
--- a/src/include/catalog/pg_transform.h
+++ b/src/include/catalog/pg_transform.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_transform
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_transform,3576,TransformRelationId)
{
Oid oid; /* oid */
@@ -35,6 +37,8 @@ CATALOG(pg_transform,3576,TransformRelationId)
regproc trftosql BKI_LOOKUP_OPT(pg_proc);
} FormData_pg_transform;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_transform corresponds to a pointer to a tuple with
* the format of pg_transform relation.
diff --git a/src/include/catalog/pg_trigger.h b/src/include/catalog/pg_trigger.h
index 563aa1ad638..2377e2f3167 100644
--- a/src/include/catalog/pg_trigger.h
+++ b/src/include/catalog/pg_trigger.h
@@ -31,6 +31,8 @@
* to be associated with a deferrable constraint.
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_trigger,2620,TriggerRelationId)
{
Oid oid; /* oid */
@@ -72,6 +74,8 @@ CATALOG(pg_trigger,2620,TriggerRelationId)
#endif
} FormData_pg_trigger;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_trigger corresponds to a pointer to a tuple with
* the format of pg_trigger relation.
diff --git a/src/include/catalog/pg_ts_config.h b/src/include/catalog/pg_ts_config.h
index 3e249e5d85c..0bbcb3249dc 100644
--- a/src/include/catalog/pg_ts_config.h
+++ b/src/include/catalog/pg_ts_config.h
@@ -27,6 +27,8 @@
* typedef struct FormData_pg_ts_config
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_ts_config,3602,TSConfigRelationId)
{
/* oid */
@@ -45,6 +47,8 @@ CATALOG(pg_ts_config,3602,TSConfigRelationId)
Oid cfgparser BKI_LOOKUP(pg_ts_parser);
} FormData_pg_ts_config;
+END_CATALOG_STRUCT
+
typedef FormData_pg_ts_config *Form_pg_ts_config;
DECLARE_UNIQUE_INDEX(pg_ts_config_cfgname_index, 3608, TSConfigNameNspIndexId, pg_ts_config, btree(cfgname name_ops, cfgnamespace oid_ops));
diff --git a/src/include/catalog/pg_ts_config_map.h b/src/include/catalog/pg_ts_config_map.h
index 46ac7290c3b..51feb1b9e8f 100644
--- a/src/include/catalog/pg_ts_config_map.h
+++ b/src/include/catalog/pg_ts_config_map.h
@@ -27,6 +27,8 @@
* typedef struct FormData_pg_ts_config_map
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_ts_config_map,3603,TSConfigMapRelationId)
{
/* OID of configuration owning this entry */
@@ -42,6 +44,8 @@ CATALOG(pg_ts_config_map,3603,TSConfigMapRelationId)
Oid mapdict BKI_LOOKUP(pg_ts_dict);
} FormData_pg_ts_config_map;
+END_CATALOG_STRUCT
+
typedef FormData_pg_ts_config_map *Form_pg_ts_config_map;
DECLARE_UNIQUE_INDEX_PKEY(pg_ts_config_map_index, 3609, TSConfigMapIndexId, pg_ts_config_map, btree(mapcfg oid_ops, maptokentype int4_ops, mapseqno int4_ops));
diff --git a/src/include/catalog/pg_ts_dict.h b/src/include/catalog/pg_ts_dict.h
index 826e79325f0..d47b05ae5cc 100644
--- a/src/include/catalog/pg_ts_dict.h
+++ b/src/include/catalog/pg_ts_dict.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_ts_dict
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_ts_dict,3600,TSDictionaryRelationId)
{
/* oid */
@@ -49,6 +51,8 @@ CATALOG(pg_ts_dict,3600,TSDictionaryRelationId)
#endif
} FormData_pg_ts_dict;
+END_CATALOG_STRUCT
+
typedef FormData_pg_ts_dict *Form_pg_ts_dict;
DECLARE_TOAST(pg_ts_dict, 4169, 4170);
diff --git a/src/include/catalog/pg_ts_parser.h b/src/include/catalog/pg_ts_parser.h
index 30eabc91c91..181e869ac75 100644
--- a/src/include/catalog/pg_ts_parser.h
+++ b/src/include/catalog/pg_ts_parser.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_ts_parser
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_ts_parser,3601,TSParserRelationId)
{
Oid oid; /* oid */
@@ -52,6 +54,8 @@ CATALOG(pg_ts_parser,3601,TSParserRelationId)
regproc prslextype BKI_LOOKUP(pg_proc);
} FormData_pg_ts_parser;
+END_CATALOG_STRUCT
+
typedef FormData_pg_ts_parser *Form_pg_ts_parser;
DECLARE_UNIQUE_INDEX(pg_ts_parser_prsname_index, 3606, TSParserNameNspIndexId, pg_ts_parser, btree(prsname name_ops, prsnamespace oid_ops));
diff --git a/src/include/catalog/pg_ts_template.h b/src/include/catalog/pg_ts_template.h
index 990f209fec2..5c28991e27b 100644
--- a/src/include/catalog/pg_ts_template.h
+++ b/src/include/catalog/pg_ts_template.h
@@ -26,6 +26,8 @@
* typedef struct FormData_pg_ts_template
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_ts_template,3764,TSTemplateRelationId)
{
Oid oid; /* oid */
@@ -43,6 +45,8 @@ CATALOG(pg_ts_template,3764,TSTemplateRelationId)
regproc tmpllexize BKI_LOOKUP(pg_proc);
} FormData_pg_ts_template;
+END_CATALOG_STRUCT
+
typedef FormData_pg_ts_template *Form_pg_ts_template;
DECLARE_UNIQUE_INDEX(pg_ts_template_tmplname_index, 3766, TSTemplateNameNspIndexId, pg_ts_template, btree(tmplname name_ops, tmplnamespace oid_ops));
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 70d4a20c02b..74183ec5a2e 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -33,6 +33,8 @@
* See struct FormData_pg_attribute for details.
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_type,1247,TypeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(71,TypeRelation_Rowtype_Id) BKI_SCHEMA_MACRO
{
Oid oid; /* oid */
@@ -253,6 +255,8 @@ CATALOG(pg_type,1247,TypeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(71,TypeRelati
#endif
} FormData_pg_type;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_type corresponds to a pointer to a row with
* the format of pg_type relation.
diff --git a/src/include/catalog/pg_user_mapping.h b/src/include/catalog/pg_user_mapping.h
index 42fb41a6341..921a9ec009d 100644
--- a/src/include/catalog/pg_user_mapping.h
+++ b/src/include/catalog/pg_user_mapping.h
@@ -25,6 +25,8 @@
* typedef struct FormData_pg_user_mapping
* ----------------
*/
+BEGIN_CATALOG_STRUCT
+
CATALOG(pg_user_mapping,1418,UserMappingRelationId)
{
Oid oid; /* oid */
@@ -40,6 +42,8 @@ CATALOG(pg_user_mapping,1418,UserMappingRelationId)
#endif
} FormData_pg_user_mapping;
+END_CATALOG_STRUCT
+
/* ----------------
* Form_pg_user_mapping corresponds to a pointer to a tuple with
* the format of pg_user_mapping relation.
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 339268dc8ef..5699c033ade 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -12,9 +12,6 @@
/* The normal alignment of `int64_t', in bytes. */
#undef ALIGNOF_INT64_T
-/* The normal alignment of `long', in bytes. */
-#undef ALIGNOF_LONG
-
/* The normal alignment of `PG_INT128_TYPE', in bytes. */
#undef ALIGNOF_PG_INT128_TYPE
--
2.43.7
Re: Decoupling our alignment assumptions about int64 and double
От:
Thomas Munro <thomas.munro@gmail.com>
Дата:
> But now that we've agreed to toss xlc support > out the window, We weren't the only ones, apparently... I don't know the details but it would be surprising if this stuff doesn't work on this tool chain: https://www.ibm.com/docs/en/openxl-c-and-cpp-aix/17.1.4?topic=new-enhanced-llvm-clang-support
Re: Decoupling our alignment assumptions about int64 and double
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Thomas Munro writes: > it would be surprising if this stuff doesn't work on this tool chain: > https://www.ibm.com/docs/en/openxl-c-and-cpp-aix/17.1.4?topic=new-enhanced-llvm-clang-support Yeah, I'd be interested in trying that toolchain once we have a finished port on gcc. regards, tom lane
RE: Decoupling our alignment assumptions about int64 and double
От:
Aditya Kamath <Aditya.Kamath1@ibm.com>
Дата:
Hi Tom and community members,
>Cool, thanks for testing.
>Here's a fleshed-out version of that patch. I propagated the
>BEGIN/END_CATALOG_STRUCT macros into all the catalog headers
>and removed the for-test-purposes-only column rearrangement in
>pg_subscription.h. I also elected to use the push/pop variants of the
>pack pragma. This makes no difference today, since we're not using
>that pragma elsewhere, but conceivably it'll make this easier to work
>with in future. It's otherwise the same except for a bit more
>comment-smithing.
We tested the patch "v5-0001-Cope-with-AIX-s-alignment-woes-by-using-_Pragma-p.patch". Thank you for the same. We were able to upgrade the database from pg15 to the latest master branch having this patch and our GNU and Meson patches.
Thank you once again for the patch and we liked the idea.
Attaching the results of the same below,
==================Meson test case run with TAP test ====================
354/361 postgresql:recovery / recovery/033_replay_tsp_drops OK 104.35s 3 subtests passed 355/361 postgresql:pg_basebackup / pg_basebackup/040_pg_createsubscriber OK 74.12s 54 subtests passed 356/361 postgresql:recovery / recovery/027_stream_regress OK 108.43s 11 subtests passed 357/361 postgresql:pg_upgrade / pg_upgrade/006_transfer_modes OK 111.43s 40 subtests passed 358/361 postgresql:pg_verifybackup / pg_verifybackup/003_corruption OK 70.00s 92 subtests passed 359/361 postgresql:subscription / subscription/100_bugs OK 27.98s 17 subtests passed 360/361 postgresql:pg_upgrade / pg_upgrade/002_pg_upgrade OK 113.34s 19 subtests passed 361/361 postgresql:pg_basebackup / pg_basebackup/010_pg_basebackup OK 85.73s 200 subtests passed Ok: 330 Expected Fail: 0 Fail: 0 Unexpected Pass: 0 Skipped: 31 Timeout: 0 Full log written to /home/buildusr/postgres/build/meson-logs/testlog.txt
==================GNU build test case run with TAP test ====================
t/043_no_contrecord_switch.pl ......... ok t/044_invalidate_inactive_slots.pl .... skipped: Injection points not supported by this build t/045_archive_restartpoint.pl ......... ok t/046_checkpoint_logical_slot.pl ...... skipped: Injection points not supported by this build t/047_checkpoint_physical_slot.pl ..... skipped: Injection points not supported by this build t/048_vacuum_horizon_floor.pl ......... ok t/049_wait_for_lsn.pl ................. ok t/050_redo_segment_missing.pl ......... skipped: Injection points not supported by this build t/051_effective_wal_level.pl .......... ok All tests successful. Files=50, Tests=584, 326 wallclock secs ( 0.11 usr 0.04 sys + 11.14 cusr 16.39 csys = 27.68 CPU) Result: PASS gmake[2]: Leaving directory '/home/buildusr/postgres/src/test/recovery' gmake[1]: Leaving directory '/home/buildusr/postgres/src/test'
=========== Database records before upgrade via Postgres 15 ==============
bash-5.2$ pg_ctl --version
pg_ctl (PostgreSQL) 15.15
pg_ctl (PostgreSQL) 15.15
These were the records before the upgrade in PostgreSQL version 15,
testdb=# select * from sensor_readings;
id | measurement_value | count_64 | note
----+-------------------+----------+------------
1 | 12.45 | 1001 | Reading 1
2 | 15.02 | 1002 | Reading 2
3 | 18.77 | 1003 | Reading 3
4 | 21.05 | 1004 | Reading 4
5 | 25.61 | 1005 | Reading 5
6 | 28.43 | 1006 | Reading 6
7 | 30.12 | 1007 | Reading 7
8 | 31.98 | 1008 | Reading 8
9 | 33.47 | 1009 | Reading 9
10 | 35.22 | 1010 | Reading 10
============================= Data base recovery check and DB records after upgrade ==========================
bash-5.2$ pg_ctl --version pg_ctl (PostgreSQL) 19devel bash-5.2$ pg_upgrade -b $HOME/postgres_15/postgres/install/usr/local/pgsql/bin/ -B $HOME/postgres/install/usr/local/pgsql/bin/ -d $HOME/data15 -D $ HOME/datamaster --check Performing Consistency Checks ----------------------------- Checking cluster versions ok Checking database connection settings ok Checking database user is the install user ok Checking for prepared transactions ok Checking for contrib/isn with bigint-passing mismatch ok Checking data type usage ok Checking for not-null constraint inconsistencies ok Checking for uses of gist_inet_ops/gist_cidr_ops ok Checking for presence of required libraries ok Checking database user is the install user ok Checking for prepared transactions ok Checking for new cluster tablespace directories ok *Clusters are compatible*
====================== Data base records after upgrade Postgres Master branch ====================
testdb=# select * from sensor_readings;
id | measurement_value | count_64 | note
----+-------------------+----------+——————
1 | 12.45 | 1001 | Reading 1
2 | 15.02 | 1002 | Reading 2
3 | 18.77 | 1003 | Reading 3
4 | 21.05 | 1004 | Reading 4
5 | 25.61 | 1005 | Reading 5
6 | 28.43 | 1006 | Reading 6
7 | 30.12 | 1007 | Reading 7
8 | 31.98 | 1008 | Reading 8
9 | 33.47 | 1009 | Reading 9
10 | 35.22 | 1010 | Reading 10
>Thomas Munro <thomas.munro@gmail.com> writes:
>> it would be surprising if this stuff doesn't work on this tool chain:
>> https://www.ibm.com/docs/en/openxl-c-and-cpp-aix/17.1.4?topic=new-enhanced-llvm-clang-support
>Yeah, I'd be interested in trying that toolchain once we have a
>finished port on gcc.
>Thomas Munro <thomas.munro@gmail.com> writes:
>> it would be surprising if this stuff doesn't work on this tool chain:
>> https://www.ibm.com/docs/en/openxl-c-and-cpp-aix/17.1.4?topic=new-enhanced-llvm-clang-support
>Yeah, I'd be interested in trying that toolchain once we have a
>finished port on gcc.
Sure, Tom and Thomas. Once we complete the GCC part of porting we can setup this compiler to use in the p9-aix1-postgres1 OSU lab node. Let me know if you need access to the same. We can provide the access. This has better config in the OSU lab than the GCC farm LPAR.
Have a nice day ahead.
Thanks and regards,
Aditya.