1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00
Files
postgres/src/include/catalog/pg_aggregate.h
Tom Lane ecae097252 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
2026-02-23 12:34:54 -05:00

187 lines
6.0 KiB
C

/*-------------------------------------------------------------------------
*
* pg_aggregate.h
* definition of the "aggregate" system catalog (pg_aggregate)
*
*
* Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/catalog/pg_aggregate.h
*
* NOTES
* The Catalog.pm module reads this file and derives schema
* information.
*
*-------------------------------------------------------------------------
*/
#ifndef PG_AGGREGATE_H
#define PG_AGGREGATE_H
#include "catalog/genbki.h"
#include "catalog/pg_aggregate_d.h" /* IWYU pragma: export */
#include "catalog/objectaddress.h"
#include "nodes/pg_list.h"
/* ----------------------------------------------------------------
* pg_aggregate definition.
* cpp turns this into typedef struct FormData_pg_aggregate
* ----------------------------------------------------------------
*/
BEGIN_CATALOG_STRUCT
CATALOG(pg_aggregate,2600,AggregateRelationId)
{
/* pg_proc OID of the aggregate itself */
regproc aggfnoid BKI_LOOKUP(pg_proc);
/* aggregate kind, see AGGKIND_ categories below */
char aggkind BKI_DEFAULT(n);
/* number of arguments that are "direct" arguments */
int16 aggnumdirectargs BKI_DEFAULT(0);
/* transition function */
regproc aggtransfn BKI_LOOKUP(pg_proc);
/* final function (0 if none) */
regproc aggfinalfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
/* combine function (0 if none) */
regproc aggcombinefn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
/* function to convert transtype to bytea (0 if none) */
regproc aggserialfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
/* function to convert bytea to transtype (0 if none) */
regproc aggdeserialfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
/* forward function for moving-aggregate mode (0 if none) */
regproc aggmtransfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
/* inverse function for moving-aggregate mode (0 if none) */
regproc aggminvtransfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
/* final function for moving-aggregate mode (0 if none) */
regproc aggmfinalfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
/* true to pass extra dummy arguments to aggfinalfn */
bool aggfinalextra BKI_DEFAULT(f);
/* true to pass extra dummy arguments to aggmfinalfn */
bool aggmfinalextra BKI_DEFAULT(f);
/* tells whether aggfinalfn modifies transition state */
char aggfinalmodify BKI_DEFAULT(r);
/* tells whether aggmfinalfn modifies transition state */
char aggmfinalmodify BKI_DEFAULT(r);
/* associated sort operator (0 if none) */
Oid aggsortop BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_operator);
/* type of aggregate's transition (state) data */
Oid aggtranstype BKI_LOOKUP(pg_type);
/* estimated size of state data (0 for default estimate) */
int32 aggtransspace BKI_DEFAULT(0);
/* type of moving-aggregate state data (0 if none) */
Oid aggmtranstype BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_type);
/* estimated size of moving-agg state (0 for default est) */
int32 aggmtransspace BKI_DEFAULT(0);
#ifdef CATALOG_VARLEN /* variable-length fields start here */
/* initial value for transition state (can be NULL) */
text agginitval BKI_DEFAULT(_null_);
/* initial value for moving-agg state (can be NULL) */
text aggminitval BKI_DEFAULT(_null_);
#endif
} FormData_pg_aggregate;
END_CATALOG_STRUCT
/* ----------------
* Form_pg_aggregate corresponds to a pointer to a tuple with
* the format of pg_aggregate relation.
* ----------------
*/
typedef FormData_pg_aggregate *Form_pg_aggregate;
DECLARE_TOAST(pg_aggregate, 4159, 4160);
DECLARE_UNIQUE_INDEX_PKEY(pg_aggregate_fnoid_index, 2650, AggregateFnoidIndexId, pg_aggregate, btree(aggfnoid oid_ops));
MAKE_SYSCACHE(AGGFNOID, pg_aggregate_fnoid_index, 16);
#ifdef EXPOSE_TO_CLIENT_CODE
/*
* Symbolic values for aggkind column. We distinguish normal aggregates
* from ordered-set aggregates (which have two sets of arguments, namely
* direct and aggregated arguments) and from hypothetical-set aggregates
* (which are a subclass of ordered-set aggregates in which the last
* direct arguments have to match up in number and datatypes with the
* aggregated arguments).
*/
#define AGGKIND_NORMAL 'n'
#define AGGKIND_ORDERED_SET 'o'
#define AGGKIND_HYPOTHETICAL 'h'
/* Use this macro to test for "ordered-set agg including hypothetical case" */
#define AGGKIND_IS_ORDERED_SET(kind) ((kind) != AGGKIND_NORMAL)
/*
* Symbolic values for aggfinalmodify and aggmfinalmodify columns.
* Preferably, finalfns do not modify the transition state value at all,
* but in some cases that would cost too much performance. We distinguish
* "pure read only" and "trashes it arbitrarily" cases, as well as the
* intermediate case where multiple finalfn calls are allowed but the
* transfn cannot be applied anymore after the first finalfn call.
*/
#define AGGMODIFY_READ_ONLY 'r'
#define AGGMODIFY_SHAREABLE 's'
#define AGGMODIFY_READ_WRITE 'w'
#endif /* EXPOSE_TO_CLIENT_CODE */
extern ObjectAddress AggregateCreate(const char *aggName,
Oid aggNamespace,
bool replace,
char aggKind,
int numArgs,
int numDirectArgs,
oidvector *parameterTypes,
Datum allParameterTypes,
Datum parameterModes,
Datum parameterNames,
List *parameterDefaults,
Oid variadicArgType,
List *aggtransfnName,
List *aggfinalfnName,
List *aggcombinefnName,
List *aggserialfnName,
List *aggdeserialfnName,
List *aggmtransfnName,
List *aggminvtransfnName,
List *aggmfinalfnName,
bool finalfnExtraArgs,
bool mfinalfnExtraArgs,
char finalfnModify,
char mfinalfnModify,
List *aggsortopName,
Oid aggTransType,
int32 aggTransSpace,
Oid aggmTransType,
int32 aggmTransSpace,
const char *agginitval,
const char *aggminitval,
char proparallel);
#endif /* PG_AGGREGATE_H */