Introduce macros for typalign and typstorage constants.

Our usual practice for "poor man's enum" catalog columns is to define
macros for the possible values and use those, not literal constants,
in C code.  But for some reason lost in the mists of time, this was
never done for typalign/attalign or typstorage/attstorage.  It's never
too late to make it better though, so let's do that.

The reason I got interested in this right now is the need to duplicate
some uses of the TYPSTORAGE constants in an upcoming ALTER TYPE patch.
But in general, this sort of change aids greppability and readability,
so it's a good idea even without any specific motivation.

I may have missed a few places that could be converted, and it's even
more likely that pending patches will re-introduce some hard-coded
references.  But that's not fatal --- there's no expectation that
we'd actually change any of these values.  We can clean up stragglers
over time.

Discussion: https://postgr.es/m/16457.1583189537@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2020-03-04 10:34:25 -05:00
parent 0ad6f848ee
commit 3ed2005ff5
76 changed files with 341 additions and 309 deletions

View File

@ -119,7 +119,7 @@ gin_extract_hstore_query(PG_FUNCTION_ARGS)
text *item;
deconstruct_array(query,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&key_datums, &key_nulls, &key_count);
entries = (Datum *) palloc(sizeof(Datum) * key_count);

View File

@ -555,7 +555,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
int i;
deconstruct_array(query,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&key_datums, &key_nulls, &key_count);
for (i = 0; res && i < key_count; ++i)
@ -578,7 +578,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
int i;
deconstruct_array(query,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&key_datums, &key_nulls, &key_count);
res = false;

View File

@ -560,7 +560,7 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
errmsg("wrong number of array subscripts")));
deconstruct_array(key_array,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&key_datums, &key_nulls, &key_count);
/* see discussion in hstoreArrayToPairs() */
@ -599,7 +599,7 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
errmsg("arrays must have same bounds")));
deconstruct_array(value_array,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&value_datums, &value_nulls, &value_count);
Assert(key_count == value_count);
@ -689,7 +689,7 @@ hstore_from_array(PG_FUNCTION_ARGS)
}
deconstruct_array(in_array,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&in_datums, &in_nulls, &in_count);
count = in_count / 2;

View File

@ -81,7 +81,7 @@ hstoreArrayToPairs(ArrayType *a, int *npairs)
j;
deconstruct_array(a,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&key_datums, &key_nulls, &key_count);
if (key_count == 0)
@ -583,7 +583,7 @@ hstore_slice_to_array(PG_FUNCTION_ARGS)
int i;
deconstruct_array(key_array,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&key_datums, &key_nulls, &key_count);
if (key_count == 0)
@ -623,7 +623,7 @@ hstore_slice_to_array(PG_FUNCTION_ARGS)
ARR_NDIM(key_array),
ARR_DIMS(key_array),
ARR_LBOUND(key_array),
TEXTOID, -1, false, 'i');
TEXTOID, -1, false, TYPALIGN_INT);
PG_RETURN_POINTER(aout);
}
@ -720,7 +720,7 @@ hstore_akeys(PG_FUNCTION_ARGS)
}
a = construct_array(d, count,
TEXTOID, -1, false, 'i');
TEXTOID, -1, false, TYPALIGN_INT);
PG_RETURN_POINTER(a);
}
@ -767,7 +767,7 @@ hstore_avals(PG_FUNCTION_ARGS)
}
a = construct_md_array(d, nulls, 1, &count, &lb,
TEXTOID, -1, false, 'i');
TEXTOID, -1, false, TYPALIGN_INT);
PG_RETURN_POINTER(a);
}
@ -819,7 +819,7 @@ hstore_to_array_internal(HStore *hs, int ndims)
return construct_md_array(out_datums, out_nulls,
ndims, out_size, lb,
TEXTOID, -1, false, 'i');
TEXTOID, -1, false, TYPALIGN_INT);
}
PG_FUNCTION_INFO_V1(hstore_to_array);

View File

@ -385,7 +385,7 @@ bt_page_print_tuples(FuncCallContext *fctx, struct user_args *uargs)
nposting,
TIDOID,
sizeof(ItemPointerData),
false, 's'));
false, TYPALIGN_SHORT));
pfree(tids_datum);
}
else

View File

@ -144,7 +144,8 @@ gin_page_opaque_info(PG_FUNCTION_ARGS)
values[0] = Int64GetDatum(opaq->rightlink);
values[1] = Int32GetDatum(opaq->maxoff);
values[2] = PointerGetDatum(construct_array(flags, nflags,
TEXTOID, -1, false, 'i'));
TEXTOID,
-1, false, TYPALIGN_INT));
/* Build and return the result tuple. */
resultTuple = heap_form_tuple(tupdesc, values, nulls);
@ -247,7 +248,7 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
ndecoded,
TIDOID,
sizeof(ItemPointerData),
false, 's'));
false, TYPALIGN_SHORT));
pfree(tids_datum);
pfree(tids);

View File

@ -560,14 +560,18 @@ hash_metapage_info(PG_FUNCTION_ARGS)
values[j++] = PointerGetDatum(construct_array(spares,
HASH_MAX_SPLITPOINTS,
INT8OID,
8, FLOAT8PASSBYVAL, 'd'));
sizeof(int64),
FLOAT8PASSBYVAL,
TYPALIGN_DOUBLE));
for (i = 0; i < HASH_MAX_BITMAPS; i++)
mapp[i] = Int64GetDatum((int64) metad->hashm_mapp[i]);
values[j++] = PointerGetDatum(construct_array(mapp,
HASH_MAX_BITMAPS,
INT8OID,
8, FLOAT8PASSBYVAL, 'd'));
sizeof(int64),
FLOAT8PASSBYVAL,
TYPALIGN_DOUBLE));
tuple = heap_form_tuple(tupleDesc, values, nulls);

View File

@ -589,7 +589,7 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
/* build value */
Assert(cnt <= bitcnt);
a = construct_array(flags, cnt, TEXTOID, -1, false, 'i');
a = construct_array(flags, cnt, TEXTOID, -1, false, TYPALIGN_INT);
values[0] = PointerGetDatum(a);
/*
@ -611,7 +611,7 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
if (cnt == 0)
a = construct_empty_array(TEXTOID);
else
a = construct_array(flags, cnt, TEXTOID, -1, false, 'i');
a = construct_array(flags, cnt, TEXTOID, -1, false, TYPALIGN_INT);
pfree(flags);
values[1] = PointerGetDatum(a);

View File

@ -980,7 +980,7 @@ show_trgm(PG_FUNCTION_ARGS)
TEXTOID,
-1,
false,
'i');
TYPALIGN_INT);
for (i = 0; i < ARRNELEM(trg); i++)
pfree(DatumGetPointer(d[i]));

View File

@ -787,11 +787,11 @@ parse_key_value_arrays(ArrayType *key_array, ArrayType *val_array,
return 0;
deconstruct_array(key_array,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&key_datums, &key_nulls, &key_count);
deconstruct_array(val_array,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&val_datums, &val_nulls, &val_count);
if (key_count != val_count)

View File

@ -24,7 +24,7 @@
* that have been put into a tuple but never sent to disk. Hopefully there
* are few such places.
*
* Varlenas still have alignment 'i' (or 'd') in pg_type/pg_attribute, since
* Varlenas still have alignment INT (or DOUBLE) in pg_type/pg_attribute, since
* that's the normal requirement for the untoasted format. But we ignore that
* for the 1-byte-header format. This means that the actual start position
* of a varlena datum may vary depending on which format it has. To determine
@ -39,7 +39,7 @@
* catalog, this is now risky: it's only safe if the preceding field is
* word-aligned, so that there will never be any padding.
*
* We don't pack varlenas whose attstorage is 'p', since the data type
* We don't pack varlenas whose attstorage is PLAIN, since the data type
* isn't expecting to have to detoast values. This is used in particular
* by oidvector and int2vector, which are used in the system catalogs
* and we'd like to still refer to them via C struct offsets.
@ -66,10 +66,10 @@
/* Does att's datatype allow packing into the 1-byte-header varlena format? */
#define ATT_IS_PACKABLE(att) \
((att)->attlen == -1 && (att)->attstorage != 'p')
((att)->attlen == -1 && (att)->attstorage != TYPSTORAGE_PLAIN)
/* Use this if it's already known varlena */
#define VARLENA_ATT_IS_PACKABLE(att) \
((att)->attstorage != 'p')
((att)->attstorage != TYPSTORAGE_PLAIN)
/* ----------------------------------------------------------------
@ -274,7 +274,7 @@ fill_val(Form_pg_attribute att,
{
/* cstring ... never needs alignment */
*infomask |= HEAP_HASVARWIDTH;
Assert(att->attalign == 'c');
Assert(att->attalign == TYPALIGN_CHAR);
data_length = strlen(DatumGetCString(datum)) + 1;
memcpy(data, DatumGetPointer(datum), data_length);
}

View File

@ -100,7 +100,8 @@ index_form_tuple(TupleDesc tupleDescriptor,
*/
if (!VARATT_IS_EXTENDED(DatumGetPointer(untoasted_values[i])) &&
VARSIZE(DatumGetPointer(untoasted_values[i])) > TOAST_INDEX_TARGET &&
(att->attstorage == 'x' || att->attstorage == 'm'))
(att->attstorage == TYPSTORAGE_EXTENDED ||
att->attstorage == TYPSTORAGE_MAIN))
{
Datum cvalue = toast_compress_datum(untoasted_values[i]);

View File

@ -892,7 +892,7 @@ transformRelOptions(Datum oldOptions, List *defList, const char *namspace,
int noldoptions;
int i;
deconstruct_array(array, TEXTOID, -1, false, 'i',
deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
&oldoptions, NULL, &noldoptions);
for (i = 0; i < noldoptions; i++)
@ -1060,7 +1060,7 @@ untransformRelOptions(Datum options)
array = DatumGetArrayTypeP(options);
deconstruct_array(array, TEXTOID, -1, false, 'i',
deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
&optiondatums, NULL, &noptions);
for (i = 0; i < noptions; i++)
@ -1201,7 +1201,7 @@ parseRelOptions(Datum options, bool validate, relopt_kind kind,
Datum *optiondatums;
int noptions;
deconstruct_array(array, TEXTOID, -1, false, 'i',
deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
&optiondatums, NULL, &noptions);
for (i = 0; i < noptions; i++)

View File

@ -725,32 +725,32 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
case TEXTARRAYOID:
att->attlen = -1;
att->attbyval = false;
att->attalign = 'i';
att->attstorage = 'x';
att->attalign = TYPALIGN_INT;
att->attstorage = TYPSTORAGE_EXTENDED;
att->attcollation = DEFAULT_COLLATION_OID;
break;
case BOOLOID:
att->attlen = 1;
att->attbyval = true;
att->attalign = 'c';
att->attstorage = 'p';
att->attalign = TYPALIGN_CHAR;
att->attstorage = TYPSTORAGE_PLAIN;
att->attcollation = InvalidOid;
break;
case INT4OID:
att->attlen = 4;
att->attbyval = true;
att->attalign = 'i';
att->attstorage = 'p';
att->attalign = TYPALIGN_INT;
att->attstorage = TYPSTORAGE_PLAIN;
att->attcollation = InvalidOid;
break;
case INT8OID:
att->attlen = 8;
att->attbyval = FLOAT8PASSBYVAL;
att->attalign = 'd';
att->attstorage = 'p';
att->attalign = TYPALIGN_DOUBLE;
att->attstorage = TYPSTORAGE_PLAIN;
att->attcollation = InvalidOid;
break;

View File

@ -2023,7 +2023,7 @@ heapam_relation_needs_toast_table(Relation rel)
maxlength_unknown = true;
else
data_length += maxlen;
if (att->attstorage != 'p')
if (att->attstorage != TYPSTORAGE_PLAIN)
has_toastable_attrs = true;
}
}

View File

@ -159,11 +159,12 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
/* ----------
* Compress and/or save external until data fits into target length
*
* 1: Inline compress attributes with attstorage 'x', and store very
* large attributes with attstorage 'x' or 'e' external immediately
* 2: Store attributes with attstorage 'x' or 'e' external
* 3: Inline compress attributes with attstorage 'm'
* 4: Store attributes with attstorage 'm' external
* 1: Inline compress attributes with attstorage EXTENDED, and store very
* large attributes with attstorage EXTENDED or EXTERNAL external
* immediately
* 2: Store attributes with attstorage EXTENDED or EXTERNAL external
* 3: Inline compress attributes with attstorage MAIN
* 4: Store attributes with attstorage MAIN external
* ----------
*/
@ -176,8 +177,9 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
maxDataLen = RelationGetToastTupleTarget(rel, TOAST_TUPLE_TARGET) - hoff;
/*
* Look for attributes with attstorage 'x' to compress. Also find large
* attributes with attstorage 'x' or 'e', and store them external.
* Look for attributes with attstorage EXTENDED to compress. Also find
* large attributes with attstorage EXTENDED or EXTERNAL, and store them
* external.
*/
while (heap_compute_data_size(tupleDesc,
toast_values, toast_isnull) > maxDataLen)
@ -189,13 +191,16 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
break;
/*
* Attempt to compress it inline, if it has attstorage 'x'
* Attempt to compress it inline, if it has attstorage EXTENDED
*/
if (TupleDescAttr(tupleDesc, biggest_attno)->attstorage == 'x')
if (TupleDescAttr(tupleDesc, biggest_attno)->attstorage == TYPSTORAGE_EXTENDED)
toast_tuple_try_compression(&ttc, biggest_attno);
else
{
/* has attstorage 'e', ignore on subsequent compression passes */
/*
* has attstorage EXTERNAL, ignore on subsequent compression
* passes
*/
toast_attr[biggest_attno].tai_colflags |= TOASTCOL_INCOMPRESSIBLE;
}
@ -213,9 +218,9 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
}
/*
* Second we look for attributes of attstorage 'x' or 'e' that are still
* inline, and make them external. But skip this if there's no toast
* table to push them to.
* Second we look for attributes of attstorage EXTENDED or EXTERNAL that
* are still inline, and make them external. But skip this if there's no
* toast table to push them to.
*/
while (heap_compute_data_size(tupleDesc,
toast_values, toast_isnull) > maxDataLen &&
@ -230,7 +235,7 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
}
/*
* Round 3 - this time we take attributes with storage 'm' into
* Round 3 - this time we take attributes with storage MAIN into
* compression
*/
while (heap_compute_data_size(tupleDesc,
@ -246,8 +251,8 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
}
/*
* Finally we store attributes of type 'm' externally. At this point we
* increase the target tuple size, so that 'm' attributes aren't stored
* Finally we store attributes of type MAIN externally. At this point we
* increase the target tuple size, so that MAIN attributes aren't stored
* externally unless really necessary.
*/
maxDataLen = TOAST_TUPLE_TARGET_MAIN - hoff;

View File

@ -7,7 +7,7 @@
* Copyright (c) 2000-2020, PostgreSQL Global Development Group
*
* IDENTIFICATION
* src/backend/access/common/toast_helper.c
* src/backend/access/table/toast_helper.c
*
*-------------------------------------------------------------------------
*/
@ -18,6 +18,8 @@
#include "access/table.h"
#include "access/toast_helper.h"
#include "access/toast_internals.h"
#include "catalog/pg_type_d.h"
/*
* Prepare to TOAST a tuple.
@ -120,7 +122,7 @@ toast_tuple_init(ToastTupleContext *ttc)
/*
* If the table's attribute says PLAIN always, force it so.
*/
if (att->attstorage == 'p')
if (att->attstorage == TYPSTORAGE_PLAIN)
ttc->ttc_attr[i].tai_colflags |= TOASTCOL_IGNORE;
/*
@ -134,7 +136,7 @@ toast_tuple_init(ToastTupleContext *ttc)
if (VARATT_IS_EXTERNAL(new_value))
{
ttc->ttc_attr[i].tai_oldexternal = new_value;
if (att->attstorage == 'p')
if (att->attstorage == TYPSTORAGE_PLAIN)
new_value = detoast_attr(new_value);
else
new_value = detoast_external_attr(new_value);
@ -165,8 +167,8 @@ toast_tuple_init(ToastTupleContext *ttc)
* for_compression flag is passed as true, it must also not be marked
* TOASTCOL_INCOMPRESSIBLE.
*
* The column must have attstorage 'e' or 'x' if check_main is false, and
* must have attstorage 'm' if check_main is true.
* The column must have attstorage EXTERNAL or EXTENDED if check_main is
* false, and must have attstorage MAIN if check_main is true.
*
* The column must have a minimum size of MAXALIGN(TOAST_POINTER_SIZE);
* if not, no benefit is to be expected by compressing it.
@ -195,13 +197,14 @@ toast_tuple_find_biggest_attribute(ToastTupleContext *ttc,
if ((ttc->ttc_attr[i].tai_colflags & skip_colflags) != 0)
continue;
if (VARATT_IS_EXTERNAL(DatumGetPointer(ttc->ttc_values[i])))
continue; /* can't happen, toast_action would be 'p' */
continue; /* can't happen, toast_action would be PLAIN */
if (for_compression &&
VARATT_IS_COMPRESSED(DatumGetPointer(ttc->ttc_values[i])))
continue;
if (check_main && att->attstorage != 'm')
if (check_main && att->attstorage != TYPSTORAGE_MAIN)
continue;
if (!check_main && att->attstorage != 'x' && att->attstorage != 'e')
if (!check_main && att->attstorage != TYPSTORAGE_EXTENDED &&
att->attstorage != TYPSTORAGE_EXTERNAL)
continue;
if (ttc->ttc_attr[i].tai_size > biggest_size)

View File

@ -101,55 +101,55 @@ struct typinfo
};
static const struct typinfo TypInfo[] = {
{"bool", BOOLOID, 0, 1, true, 'c', 'p', InvalidOid,
{"bool", BOOLOID, 0, 1, true, TYPALIGN_CHAR, TYPSTORAGE_PLAIN, InvalidOid,
F_BOOLIN, F_BOOLOUT},
{"bytea", BYTEAOID, 0, -1, false, 'i', 'x', InvalidOid,
{"bytea", BYTEAOID, 0, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
F_BYTEAIN, F_BYTEAOUT},
{"char", CHAROID, 0, 1, true, 'c', 'p', InvalidOid,
{"char", CHAROID, 0, 1, true, TYPALIGN_CHAR, TYPSTORAGE_PLAIN, InvalidOid,
F_CHARIN, F_CHAROUT},
{"int2", INT2OID, 0, 2, true, 's', 'p', InvalidOid,
{"int2", INT2OID, 0, 2, true, TYPALIGN_SHORT, TYPSTORAGE_PLAIN, InvalidOid,
F_INT2IN, F_INT2OUT},
{"int4", INT4OID, 0, 4, true, 'i', 'p', InvalidOid,
{"int4", INT4OID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_INT4IN, F_INT4OUT},
{"float4", FLOAT4OID, 0, 4, true, 'i', 'p', InvalidOid,
{"float4", FLOAT4OID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_FLOAT4IN, F_FLOAT4OUT},
{"name", NAMEOID, CHAROID, NAMEDATALEN, false, 'c', 'p', C_COLLATION_OID,
{"name", NAMEOID, CHAROID, NAMEDATALEN, false, TYPALIGN_CHAR, TYPSTORAGE_PLAIN, C_COLLATION_OID,
F_NAMEIN, F_NAMEOUT},
{"regclass", REGCLASSOID, 0, 4, true, 'i', 'p', InvalidOid,
{"regclass", REGCLASSOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_REGCLASSIN, F_REGCLASSOUT},
{"regproc", REGPROCOID, 0, 4, true, 'i', 'p', InvalidOid,
{"regproc", REGPROCOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_REGPROCIN, F_REGPROCOUT},
{"regtype", REGTYPEOID, 0, 4, true, 'i', 'p', InvalidOid,
{"regtype", REGTYPEOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_REGTYPEIN, F_REGTYPEOUT},
{"regrole", REGROLEOID, 0, 4, true, 'i', 'p', InvalidOid,
{"regrole", REGROLEOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_REGROLEIN, F_REGROLEOUT},
{"regnamespace", REGNAMESPACEOID, 0, 4, true, 'i', 'p', InvalidOid,
{"regnamespace", REGNAMESPACEOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_REGNAMESPACEIN, F_REGNAMESPACEOUT},
{"text", TEXTOID, 0, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
{"text", TEXTOID, 0, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, DEFAULT_COLLATION_OID,
F_TEXTIN, F_TEXTOUT},
{"oid", OIDOID, 0, 4, true, 'i', 'p', InvalidOid,
{"oid", OIDOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_OIDIN, F_OIDOUT},
{"tid", TIDOID, 0, 6, false, 's', 'p', InvalidOid,
{"tid", TIDOID, 0, 6, false, TYPALIGN_SHORT, TYPSTORAGE_PLAIN, InvalidOid,
F_TIDIN, F_TIDOUT},
{"xid", XIDOID, 0, 4, true, 'i', 'p', InvalidOid,
{"xid", XIDOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_XIDIN, F_XIDOUT},
{"cid", CIDOID, 0, 4, true, 'i', 'p', InvalidOid,
{"cid", CIDOID, 0, 4, true, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_CIDIN, F_CIDOUT},
{"pg_node_tree", PGNODETREEOID, 0, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
{"pg_node_tree", PGNODETREEOID, 0, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, DEFAULT_COLLATION_OID,
F_PG_NODE_TREE_IN, F_PG_NODE_TREE_OUT},
{"int2vector", INT2VECTOROID, INT2OID, -1, false, 'i', 'p', InvalidOid,
{"int2vector", INT2VECTOROID, INT2OID, -1, false, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_INT2VECTORIN, F_INT2VECTOROUT},
{"oidvector", OIDVECTOROID, OIDOID, -1, false, 'i', 'p', InvalidOid,
{"oidvector", OIDVECTOROID, OIDOID, -1, false, TYPALIGN_INT, TYPSTORAGE_PLAIN, InvalidOid,
F_OIDVECTORIN, F_OIDVECTOROUT},
{"_int4", INT4ARRAYOID, INT4OID, -1, false, 'i', 'x', InvalidOid,
{"_int4", INT4ARRAYOID, INT4OID, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
F_ARRAY_IN, F_ARRAY_OUT},
{"_text", 1009, TEXTOID, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
{"_text", 1009, TEXTOID, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, DEFAULT_COLLATION_OID,
F_ARRAY_IN, F_ARRAY_OUT},
{"_oid", 1028, OIDOID, -1, false, 'i', 'x', InvalidOid,
{"_oid", 1028, OIDOID, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
F_ARRAY_IN, F_ARRAY_OUT},
{"_char", 1002, CHAROID, -1, false, 'i', 'x', InvalidOid,
{"_char", 1002, CHAROID, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
F_ARRAY_IN, F_ARRAY_OUT},
{"_aclitem", 1034, ACLITEMOID, -1, false, 'i', 'x', InvalidOid,
{"_aclitem", 1034, ACLITEMOID, -1, false, TYPALIGN_INT, TYPSTORAGE_EXTENDED, InvalidOid,
F_ARRAY_IN, F_ARRAY_OUT}
};

View File

@ -156,8 +156,8 @@ static const FormData_pg_attribute a1 = {
.attcacheoff = -1,
.atttypmod = -1,
.attbyval = false,
.attstorage = 'p',
.attalign = 's',
.attstorage = TYPSTORAGE_PLAIN,
.attalign = TYPALIGN_SHORT,
.attnotnull = true,
.attislocal = true,
};
@ -170,8 +170,8 @@ static const FormData_pg_attribute a2 = {
.attcacheoff = -1,
.atttypmod = -1,
.attbyval = true,
.attstorage = 'p',
.attalign = 'i',
.attstorage = TYPSTORAGE_PLAIN,
.attalign = TYPALIGN_INT,
.attnotnull = true,
.attislocal = true,
};
@ -184,8 +184,8 @@ static const FormData_pg_attribute a3 = {
.attcacheoff = -1,
.atttypmod = -1,
.attbyval = true,
.attstorage = 'p',
.attalign = 'i',
.attstorage = TYPSTORAGE_PLAIN,
.attalign = TYPALIGN_INT,
.attnotnull = true,
.attislocal = true,
};
@ -198,8 +198,8 @@ static const FormData_pg_attribute a4 = {
.attcacheoff = -1,
.atttypmod = -1,
.attbyval = true,
.attstorage = 'p',
.attalign = 'i',
.attstorage = TYPSTORAGE_PLAIN,
.attalign = TYPALIGN_INT,
.attnotnull = true,
.attislocal = true,
};
@ -212,8 +212,8 @@ static const FormData_pg_attribute a5 = {
.attcacheoff = -1,
.atttypmod = -1,
.attbyval = true,
.attstorage = 'p',
.attalign = 'i',
.attstorage = TYPSTORAGE_PLAIN,
.attalign = TYPALIGN_INT,
.attnotnull = true,
.attislocal = true,
};
@ -232,8 +232,8 @@ static const FormData_pg_attribute a6 = {
.attcacheoff = -1,
.atttypmod = -1,
.attbyval = true,
.attstorage = 'p',
.attalign = 'i',
.attstorage = TYPSTORAGE_PLAIN,
.attalign = TYPALIGN_INT,
.attnotnull = true,
.attislocal = true,
};
@ -1053,8 +1053,8 @@ AddNewRelationType(const char *typeName,
NULL, /* default value - none */
NULL, /* default binary representation */
false, /* passed by reference */
'd', /* alignment - must be the largest! */
'x', /* fully TOASTable */
TYPALIGN_DOUBLE, /* alignment - must be the largest! */
TYPSTORAGE_EXTENDED, /* fully TOASTable */
-1, /* typmod */
0, /* array dimensions for typBaseType */
false, /* Type NOT NULL */
@ -1334,8 +1334,8 @@ heap_create_with_catalog(const char *relname,
NULL, /* default value - none */
NULL, /* default binary representation */
false, /* passed by reference */
'd', /* alignment - must be the largest! */
'x', /* fully TOASTable */
TYPALIGN_DOUBLE, /* alignment - must be the largest! */
TYPSTORAGE_EXTENDED, /* fully TOASTable */
-1, /* typmod */
0, /* array dimensions for typBaseType */
false, /* Type NOT NULL */

View File

@ -1967,7 +1967,7 @@ textarray_to_strvaluelist(ArrayType *arr)
List *list = NIL;
int i;
deconstruct_array(arr, TEXTOID, -1, false, 'i',
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
&elems, &nulls, &nelems);
for (i = 0; i < nelems; i++)
@ -2024,7 +2024,7 @@ pg_get_object_address(PG_FUNCTION_ARGS)
bool *nulls;
int nelems;
deconstruct_array(namearr, TEXTOID, -1, false, 'i',
deconstruct_array(namearr, TEXTOID, -1, false, TYPALIGN_INT,
&elems, &nulls, &nelems);
if (nelems != 1)
ereport(ERROR,
@ -2042,7 +2042,7 @@ pg_get_object_address(PG_FUNCTION_ARGS)
bool *nulls;
int nelems;
deconstruct_array(namearr, TEXTOID, -1, false, 'i',
deconstruct_array(namearr, TEXTOID, -1, false, TYPALIGN_INT,
&elems, &nulls, &nelems);
if (nelems != 1)
ereport(ERROR,
@ -2081,7 +2081,7 @@ pg_get_object_address(PG_FUNCTION_ARGS)
int nelems;
int i;
deconstruct_array(argsarr, TEXTOID, -1, false, 'i',
deconstruct_array(argsarr, TEXTOID, -1, false, TYPALIGN_INT,
&elems, &nulls, &nelems);
args = NIL;
@ -5333,7 +5333,7 @@ strlist_to_textarray(List *list)
lb[0] = 1;
arr = construct_md_array(datums, nulls, 1, &j,
lb, TEXTOID, -1, false, 'i');
lb, TEXTOID, -1, false, TYPALIGN_INT);
MemoryContextDelete(memcxt);

View File

@ -108,7 +108,7 @@ CreateConstraintEntry(const char *constraintName,
for (i = 0; i < constraintNKeys; i++)
conkey[i] = Int16GetDatum(constraintKey[i]);
conkeyArray = construct_array(conkey, constraintNKeys,
INT2OID, 2, true, 's');
INT2OID, 2, true, TYPALIGN_SHORT);
}
else
conkeyArray = NULL;
@ -121,19 +121,19 @@ CreateConstraintEntry(const char *constraintName,
for (i = 0; i < foreignNKeys; i++)
fkdatums[i] = Int16GetDatum(foreignKey[i]);
confkeyArray = construct_array(fkdatums, foreignNKeys,
INT2OID, 2, true, 's');
INT2OID, 2, true, TYPALIGN_SHORT);
for (i = 0; i < foreignNKeys; i++)
fkdatums[i] = ObjectIdGetDatum(pfEqOp[i]);
conpfeqopArray = construct_array(fkdatums, foreignNKeys,
OIDOID, sizeof(Oid), true, 'i');
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
for (i = 0; i < foreignNKeys; i++)
fkdatums[i] = ObjectIdGetDatum(ppEqOp[i]);
conppeqopArray = construct_array(fkdatums, foreignNKeys,
OIDOID, sizeof(Oid), true, 'i');
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
for (i = 0; i < foreignNKeys; i++)
fkdatums[i] = ObjectIdGetDatum(ffEqOp[i]);
conffeqopArray = construct_array(fkdatums, foreignNKeys,
OIDOID, sizeof(Oid), true, 'i');
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
}
else
{
@ -151,7 +151,7 @@ CreateConstraintEntry(const char *constraintName,
for (i = 0; i < constraintNKeys; i++)
opdatums[i] = ObjectIdGetDatum(exclOp[i]);
conexclopArray = construct_array(opdatums, constraintNKeys,
OIDOID, sizeof(Oid), true, 'i');
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
}
else
conexclopArray = NULL;

View File

@ -1171,7 +1171,7 @@ oid_array_to_list(Datum datum)
deconstruct_array(array,
OIDOID,
sizeof(Oid), true, 'i',
sizeof(Oid), true, TYPALIGN_INT,
&values, NULL, &nelems);
for (i = 0; i < nelems; i++)
result = lappend_oid(result, values[i]);

View File

@ -216,7 +216,7 @@ textarray_to_stringlist(ArrayType *textarray)
List *res = NIL;
deconstruct_array(textarray,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&elems, NULL, &nelems);
if (nelems == 0)

View File

@ -111,8 +111,8 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
values[Anum_pg_type_typmodin - 1] = ObjectIdGetDatum(InvalidOid);
values[Anum_pg_type_typmodout - 1] = ObjectIdGetDatum(InvalidOid);
values[Anum_pg_type_typanalyze - 1] = ObjectIdGetDatum(InvalidOid);
values[Anum_pg_type_typalign - 1] = CharGetDatum('i');
values[Anum_pg_type_typstorage - 1] = CharGetDatum('p');
values[Anum_pg_type_typalign - 1] = CharGetDatum(TYPALIGN_INT);
values[Anum_pg_type_typstorage - 1] = CharGetDatum(TYPSTORAGE_PLAIN);
values[Anum_pg_type_typnotnull - 1] = BoolGetDatum(false);
values[Anum_pg_type_typbasetype - 1] = ObjectIdGetDatum(InvalidOid);
values[Anum_pg_type_typtypmod - 1] = Int32GetDatum(-1);
@ -259,7 +259,7 @@ TypeCreate(Oid newTypeOid,
*/
if (internalSize == (int16) sizeof(char))
{
if (alignment != 'c')
if (alignment != TYPALIGN_CHAR)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("alignment \"%c\" is invalid for passed-by-value type of size %d",
@ -267,7 +267,7 @@ TypeCreate(Oid newTypeOid,
}
else if (internalSize == (int16) sizeof(int16))
{
if (alignment != 's')
if (alignment != TYPALIGN_SHORT)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("alignment \"%c\" is invalid for passed-by-value type of size %d",
@ -275,7 +275,7 @@ TypeCreate(Oid newTypeOid,
}
else if (internalSize == (int16) sizeof(int32))
{
if (alignment != 'i')
if (alignment != TYPALIGN_INT)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("alignment \"%c\" is invalid for passed-by-value type of size %d",
@ -284,7 +284,7 @@ TypeCreate(Oid newTypeOid,
#if SIZEOF_DATUM == 8
else if (internalSize == (int16) sizeof(Datum))
{
if (alignment != 'd')
if (alignment != TYPALIGN_DOUBLE)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("alignment \"%c\" is invalid for passed-by-value type of size %d",
@ -300,13 +300,14 @@ TypeCreate(Oid newTypeOid,
else
{
/* varlena types must have int align or better */
if (internalSize == -1 && !(alignment == 'i' || alignment == 'd'))
if (internalSize == -1 &&
!(alignment == TYPALIGN_INT || alignment == TYPALIGN_DOUBLE))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("alignment \"%c\" is invalid for variable-length type",
alignment)));
/* cstring must have char alignment */
if (internalSize == -2 && !(alignment == 'c'))
if (internalSize == -2 && !(alignment == TYPALIGN_CHAR))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("alignment \"%c\" is invalid for variable-length type",
@ -314,7 +315,7 @@ TypeCreate(Oid newTypeOid,
}
/* Only varlena types can be toasted */
if (storage != 'p' && internalSize != -1)
if (storage != TYPSTORAGE_PLAIN && internalSize != -1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("fixed-size types must have storage PLAIN")));

View File

@ -221,9 +221,9 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
* toast :-(. This is essential for chunk_data because type bytea is
* toastable; hit the other two just to be sure.
*/
TupleDescAttr(tupdesc, 0)->attstorage = 'p';
TupleDescAttr(tupdesc, 1)->attstorage = 'p';
TupleDescAttr(tupdesc, 2)->attstorage = 'p';
TupleDescAttr(tupdesc, 0)->attstorage = TYPSTORAGE_PLAIN;
TupleDescAttr(tupdesc, 1)->attstorage = TYPSTORAGE_PLAIN;
TupleDescAttr(tupdesc, 2)->attstorage = TYPSTORAGE_PLAIN;
/*
* Toast tables for regular relations go in pg_toast; those for temp

View File

@ -1527,7 +1527,7 @@ update_attstats(Oid relid, bool inh, int natts, VacAttrStats **vacattrstats)
/* XXX knows more than it should about type float4: */
arry = construct_array(numdatums, nnum,
FLOAT4OID,
sizeof(float4), true, 'i');
sizeof(float4), true, TYPALIGN_INT);
values[i++] = PointerGetDatum(arry); /* stanumbersN */
}
else

View File

@ -357,7 +357,8 @@ filter_list_to_array(List *filterlist)
pfree(result);
}
return PointerGetDatum(construct_array(data, l, TEXTOID, -1, false, 'i'));
return PointerGetDatum(construct_array(data, l, TEXTOID,
-1, false, TYPALIGN_INT));
}
/*

View File

@ -2293,7 +2293,7 @@ convert_requires_to_datum(List *requires)
}
a = construct_array(datums, ndatums,
NAMEOID,
NAMEDATALEN, false, 'c');
NAMEDATALEN, false, TYPALIGN_CHAR);
return PointerGetDatum(a);
}
@ -2503,7 +2503,7 @@ pg_extension_config_dump(PG_FUNCTION_ARGS)
a = construct_array(&elementDatum, 1,
OIDOID,
sizeof(Oid), true, 'i');
sizeof(Oid), true, TYPALIGN_INT);
}
else
{
@ -2539,7 +2539,7 @@ pg_extension_config_dump(PG_FUNCTION_ARGS)
-1 /* varlena array */ ,
sizeof(Oid) /* OID's typlen */ ,
true /* OID's typbyval */ ,
'i' /* OID's typalign */ );
TYPALIGN_INT /* OID's typalign */ );
}
repl_val[Anum_pg_extension_extconfig - 1] = PointerGetDatum(a);
repl_repl[Anum_pg_extension_extconfig - 1] = true;
@ -2556,7 +2556,7 @@ pg_extension_config_dump(PG_FUNCTION_ARGS)
a = construct_array(&elementDatum, 1,
TEXTOID,
-1, false, 'i');
-1, false, TYPALIGN_INT);
}
else
{
@ -2577,7 +2577,7 @@ pg_extension_config_dump(PG_FUNCTION_ARGS)
-1 /* varlena array */ ,
-1 /* TEXT's typlen */ ,
false /* TEXT's typbyval */ ,
'i' /* TEXT's typalign */ );
TYPALIGN_INT /* TEXT's typalign */ );
}
repl_val[Anum_pg_extension_extcondition - 1] = PointerGetDatum(a);
repl_repl[Anum_pg_extension_extcondition - 1] = true;
@ -2698,14 +2698,14 @@ extension_config_remove(Oid extensionoid, Oid tableoid)
int i;
/* We already checked there are no nulls */
deconstruct_array(a, OIDOID, sizeof(Oid), true, 'i',
deconstruct_array(a, OIDOID, sizeof(Oid), true, TYPALIGN_INT,
&dvalues, NULL, &nelems);
for (i = arrayIndex; i < arrayLength - 1; i++)
dvalues[i] = dvalues[i + 1];
a = construct_array(dvalues, arrayLength - 1,
OIDOID, sizeof(Oid), true, 'i');
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
repl_val[Anum_pg_extension_extconfig - 1] = PointerGetDatum(a);
}
@ -2744,14 +2744,14 @@ extension_config_remove(Oid extensionoid, Oid tableoid)
int i;
/* We already checked there are no nulls */
deconstruct_array(a, TEXTOID, -1, false, 'i',
deconstruct_array(a, TEXTOID, -1, false, TYPALIGN_INT,
&dvalues, NULL, &nelems);
for (i = arrayIndex; i < arrayLength - 1; i++)
dvalues[i] = dvalues[i + 1];
a = construct_array(dvalues, arrayLength - 1,
TEXTOID, -1, false, 'i');
TEXTOID, -1, false, TYPALIGN_INT);
repl_val[Anum_pg_extension_extcondition - 1] = PointerGetDatum(a);
}

View File

@ -433,9 +433,9 @@ interpret_function_parameter_list(ParseState *pstate,
if (outCount > 0 || varCount > 0)
{
*allParameterTypes = construct_array(allTypes, parameterCount, OIDOID,
sizeof(Oid), true, 'i');
sizeof(Oid), true, TYPALIGN_INT);
*parameterModes = construct_array(paramModes, parameterCount, CHAROID,
1, true, 'c');
1, true, TYPALIGN_CHAR);
if (outCount > 1)
*requiredResultType = RECORDOID;
/* otherwise we set requiredResultType correctly above */
@ -454,7 +454,7 @@ interpret_function_parameter_list(ParseState *pstate,
paramNames[i] = CStringGetTextDatum("");
}
*parameterNames = construct_array(paramNames, parameterCount, TEXTOID,
-1, false, 'i');
-1, false, TYPALIGN_INT);
}
else
*parameterNames = NULL;
@ -1107,7 +1107,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
foreach(lc, trftypes_list)
arr[i++] = ObjectIdGetDatum(lfirst_oid(lc));
trftypes = construct_array(arr, list_length(trftypes_list),
OIDOID, sizeof(Oid), true, 'i');
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
}
else
{

View File

@ -614,7 +614,7 @@ RemoveRoleFromObjectPolicy(Oid roleid, Oid classid, Oid policy_id)
/* This is the array for the new tuple */
role_ids = construct_array(role_oids, num_roles, OIDOID,
sizeof(Oid), true, 'i');
sizeof(Oid), true, TYPALIGN_INT);
replaces[Anum_pg_policy_polroles - 1] = true;
values[Anum_pg_policy_polroles - 1] = PointerGetDatum(role_ids);
@ -735,7 +735,7 @@ CreatePolicy(CreatePolicyStmt *stmt)
/* Collect role ids */
role_oids = policy_role_list_to_array(stmt->roles, &nitems);
role_ids = construct_array(role_oids, nitems, OIDOID,
sizeof(Oid), true, 'i');
sizeof(Oid), true, TYPALIGN_INT);
/* Parse the supplied clause */
qual_pstate = make_parsestate(NULL);
@ -919,7 +919,7 @@ AlterPolicy(AlterPolicyStmt *stmt)
{
role_oids = policy_role_list_to_array(stmt->roles, &nitems);
role_ids = construct_array(role_oids, nitems, OIDOID,
sizeof(Oid), true, 'i');
sizeof(Oid), true, TYPALIGN_INT);
}
/* Get id of table. Also handles permissions checks. */

View File

@ -788,6 +788,7 @@ build_regtype_array(Oid *param_types, int num_params)
tmp_ary[i] = ObjectIdGetDatum(param_types[i]);
/* XXX: this hardcodes assumptions about the regtype type */
result = construct_array(tmp_ary, num_params, REGTYPEOID, 4, true, 'i');
result = construct_array(tmp_ary, num_params, REGTYPEOID,
4, true, TYPALIGN_INT);
return PointerGetDatum(result);
}

View File

@ -323,7 +323,7 @@ CreateStatistics(CreateStatsStmt *stmt)
if (build_mcv)
types[ntypes++] = CharGetDatum(STATS_EXT_MCV);
Assert(ntypes > 0 && ntypes <= lengthof(types));
stxkind = construct_array(types, ntypes, CHAROID, 1, true, 'c');
stxkind = construct_array(types, ntypes, CHAROID, 1, true, TYPALIGN_CHAR);
statrel = table_open(StatisticExtRelationId, RowExclusiveLock);

View File

@ -293,7 +293,7 @@ publicationListToArray(List *publist)
MemoryContextSwitchTo(oldcxt);
arr = construct_array(datums, list_length(publist),
TEXTOID, -1, false, 'i');
TEXTOID, -1, false, TYPALIGN_INT);
MemoryContextDelete(memcxt);

View File

@ -2030,14 +2030,14 @@ storage_name(char c)
{
switch (c)
{
case 'p':
case TYPSTORAGE_PLAIN:
return "PLAIN";
case 'm':
return "MAIN";
case 'x':
return "EXTENDED";
case 'e':
case TYPSTORAGE_EXTERNAL:
return "EXTERNAL";
case TYPSTORAGE_EXTENDED:
return "EXTENDED";
case TYPSTORAGE_MAIN:
return "MAIN";
default:
return "???";
}
@ -7388,13 +7388,13 @@ ATExecSetStorage(Relation rel, const char *colName, Node *newValue, LOCKMODE loc
storagemode = strVal(newValue);
if (pg_strcasecmp(storagemode, "plain") == 0)
newstorage = 'p';
newstorage = TYPSTORAGE_PLAIN;
else if (pg_strcasecmp(storagemode, "external") == 0)
newstorage = 'e';
newstorage = TYPSTORAGE_EXTERNAL;
else if (pg_strcasecmp(storagemode, "extended") == 0)
newstorage = 'x';
newstorage = TYPSTORAGE_EXTENDED;
else if (pg_strcasecmp(storagemode, "main") == 0)
newstorage = 'm';
newstorage = TYPSTORAGE_MAIN;
else
{
ereport(ERROR,
@ -7426,7 +7426,7 @@ ATExecSetStorage(Relation rel, const char *colName, Node *newValue, LOCKMODE loc
* safety check: do not allow toasted storage modes unless column datatype
* is TOAST-aware.
*/
if (newstorage == 'p' || TypeIsToastable(attrtuple->atttypid))
if (newstorage == TYPSTORAGE_PLAIN || TypeIsToastable(attrtuple->atttypid))
attrtuple->attstorage = newstorage;
else
ereport(ERROR,

View File

@ -132,8 +132,8 @@ DefineType(ParseState *pstate, List *names, List *parameters)
Oid elemType = InvalidOid;
char *defaultValue = NULL;
bool byValue = false;
char alignment = 'i'; /* default alignment */
char storage = 'p'; /* default TOAST storage method */
char alignment = TYPALIGN_INT; /* default alignment */
char storage = TYPSTORAGE_PLAIN; /* default TOAST storage method */
Oid collation = InvalidOid;
DefElem *likeTypeEl = NULL;
DefElem *internalLengthEl = NULL;
@ -382,16 +382,16 @@ DefineType(ParseState *pstate, List *names, List *parameters)
if (pg_strcasecmp(a, "double") == 0 ||
pg_strcasecmp(a, "float8") == 0 ||
pg_strcasecmp(a, "pg_catalog.float8") == 0)
alignment = 'd';
alignment = TYPALIGN_DOUBLE;
else if (pg_strcasecmp(a, "int4") == 0 ||
pg_strcasecmp(a, "pg_catalog.int4") == 0)
alignment = 'i';
alignment = TYPALIGN_INT;
else if (pg_strcasecmp(a, "int2") == 0 ||
pg_strcasecmp(a, "pg_catalog.int2") == 0)
alignment = 's';
alignment = TYPALIGN_SHORT;
else if (pg_strcasecmp(a, "char") == 0 ||
pg_strcasecmp(a, "pg_catalog.bpchar") == 0)
alignment = 'c';
alignment = TYPALIGN_CHAR;
else
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@ -402,13 +402,13 @@ DefineType(ParseState *pstate, List *names, List *parameters)
char *a = defGetString(storageEl);
if (pg_strcasecmp(a, "plain") == 0)
storage = 'p';
storage = TYPSTORAGE_PLAIN;
else if (pg_strcasecmp(a, "external") == 0)
storage = 'e';
storage = TYPSTORAGE_EXTERNAL;
else if (pg_strcasecmp(a, "extended") == 0)
storage = 'x';
storage = TYPSTORAGE_EXTENDED;
else if (pg_strcasecmp(a, "main") == 0)
storage = 'm';
storage = TYPSTORAGE_MAIN;
else
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@ -643,8 +643,8 @@ DefineType(ParseState *pstate, List *names, List *parameters)
*/
array_type = makeArrayTypeName(typeName, typeNamespace);
/* alignment must be 'i' or 'd' for arrays */
alignment = (alignment == 'd') ? 'd' : 'i';
/* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for arrays */
alignment = (alignment == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
TypeCreate(array_oid, /* force assignment of this type OID */
array_type, /* type name */
@ -672,7 +672,7 @@ DefineType(ParseState *pstate, List *names, List *parameters)
NULL, /* binary default isn't sent either */
false, /* never passed by value */
alignment, /* see above */
'x', /* ARRAY is always toastable */
TYPSTORAGE_EXTENDED, /* ARRAY is always toastable */
-1, /* typMod (Domains only) */
0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */
@ -1078,8 +1078,8 @@ DefineDomain(CreateDomainStmt *stmt)
*/
domainArrayName = makeArrayTypeName(domainName, domainNamespace);
/* alignment must be 'i' or 'd' for arrays */
alignment = (alignment == 'd') ? 'd' : 'i';
/* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for arrays */
alignment = (alignment == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
TypeCreate(domainArrayOid, /* force assignment of this type OID */
domainArrayName, /* type name */
@ -1107,7 +1107,7 @@ DefineDomain(CreateDomainStmt *stmt)
NULL, /* binary default isn't sent either */
false, /* never passed by value */
alignment, /* see above */
'x', /* ARRAY is always toastable */
TYPSTORAGE_EXTENDED, /* ARRAY is always toastable */
-1, /* typMod (Domains only) */
0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */
@ -1221,8 +1221,8 @@ DefineEnum(CreateEnumStmt *stmt)
NULL, /* never a default type value */
NULL, /* binary default isn't sent either */
true, /* always passed by value */
'i', /* int alignment */
'p', /* TOAST strategy always plain */
TYPALIGN_INT, /* int alignment */
TYPSTORAGE_PLAIN, /* TOAST strategy always plain */
-1, /* typMod (Domains only) */
0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */
@ -1261,8 +1261,8 @@ DefineEnum(CreateEnumStmt *stmt)
NULL, /* never a default type value */
NULL, /* binary default isn't sent either */
false, /* never passed by value */
'i', /* enums have align i, so do their arrays */
'x', /* ARRAY is always toastable */
TYPALIGN_INT, /* enums have int align, so do their arrays */
TYPSTORAGE_EXTENDED, /* ARRAY is always toastable */
-1, /* typMod (Domains only) */
0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */
@ -1516,8 +1516,8 @@ DefineRange(CreateRangeStmt *stmt)
get_typlenbyvalalign(rangeSubtype,
&subtyplen, &subtypbyval, &subtypalign);
/* alignment must be 'i' or 'd' for ranges */
alignment = (subtypalign == 'd') ? 'd' : 'i';
/* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for ranges */
alignment = (subtypalign == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
/* Allocate OID for array type */
rangeArrayOid = AssignTypeArrayOid();
@ -1550,7 +1550,7 @@ DefineRange(CreateRangeStmt *stmt)
NULL, /* no binary form available either */
false, /* never passed by value */
alignment, /* alignment */
'x', /* TOAST strategy (always extended) */
TYPSTORAGE_EXTENDED, /* TOAST strategy (always extended) */
-1, /* typMod (Domains only) */
0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */
@ -1592,7 +1592,7 @@ DefineRange(CreateRangeStmt *stmt)
NULL, /* binary default isn't sent either */
false, /* never passed by value */
alignment, /* alignment - same as range's */
'x', /* ARRAY is always toastable */
TYPSTORAGE_EXTENDED, /* ARRAY is always toastable */
-1, /* typMod (Domains only) */
0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */

View File

@ -207,7 +207,7 @@ TidListEval(TidScanState *tidstate)
continue;
itemarray = DatumGetArrayTypeP(arraydatum);
deconstruct_array(itemarray,
TIDOID, sizeof(ItemPointerData), false, 's',
TIDOID, sizeof(ItemPointerData), false, TYPALIGN_SHORT,
&ipdatums, &ipnulls, &ndatums);
if (numTids + ndatums > numAllocTids)
{

View File

@ -476,13 +476,13 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc,
LLVMPositionBuilderAtEnd(b, attcheckalignblocks[attnum]);
/* determine required alignment */
if (att->attalign == 'i')
if (att->attalign == TYPALIGN_INT)
alignto = ALIGNOF_INT;
else if (att->attalign == 'c')
else if (att->attalign == TYPALIGN_CHAR)
alignto = 1;
else if (att->attalign == 'd')
else if (att->attalign == TYPALIGN_DOUBLE)
alignto = ALIGNOF_DOUBLE;
else if (att->attalign == 's')
else if (att->attalign == TYPALIGN_SHORT)
alignto = ALIGNOF_SHORT;
else
{

View File

@ -2390,7 +2390,7 @@ gethba_options(HbaLine *hba)
Assert(noptions <= MAX_HBA_OPTIONS);
if (noptions > 0)
return construct_array(options, noptions, TEXTOID, -1, false, 'i');
return construct_array(options, noptions, TEXTOID, -1, false, TYPALIGN_INT);
else
return NULL;
}

View File

@ -409,7 +409,7 @@ typenameTypeMod(ParseState *pstate, const TypeName *typeName, Type typ)
/* hardwired knowledge about cstring's representation details here */
arrtypmod = construct_array(datums, n, CSTRINGOID,
-2, false, 'c');
-2, false, TYPALIGN_CHAR);
/* arrange to report location if type's typmodin function fails */
setup_parser_errposition_callback(&pcbstate, pstate, typeName->location);

View File

@ -1473,7 +1473,7 @@ generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx,
constraintId);
deconstruct_array(DatumGetArrayTypeP(datum),
OIDOID, sizeof(Oid), true, 'i',
OIDOID, sizeof(Oid), true, TYPALIGN_INT,
&elems, NULL, &nElems);
for (i = 0; i < nElems; i++)

View File

@ -203,7 +203,7 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin
Assert(ARR_ELEMTYPE(arr) == TEXTOID);
deconstruct_array(arr, TEXTOID, -1, false, 'i',
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
&datum_opts, NULL, &nelems);
if (nelems % 2 != 0)

View File

@ -73,7 +73,7 @@ ts_lexize(PG_FUNCTION_ARGS)
TEXTOID,
-1,
false,
'i');
TYPALIGN_INT);
ptr = res;
while (ptr->lexeme)

View File

@ -220,7 +220,7 @@ ArrayGetIntegerTypmods(ArrayType *arr, int *n)
/* hardwired knowledge about cstring's representation details here */
deconstruct_array(arr, CSTRINGOID,
-2, false, 'c',
-2, false, TYPALIGN_CHAR,
&elem_values, NULL, n);
result = (int32 *) palloc(*n * sizeof(int32));

View File

@ -602,7 +602,8 @@ enum_range_internal(Oid enumtypoid, Oid lower, Oid upper)
/* and build the result array */
/* note this hardwires some details about the representation of Oid */
result = construct_array(elems, cnt, enumtypoid, sizeof(Oid), true, 'i');
result = construct_array(elems, cnt, enumtypoid,
sizeof(Oid), true, TYPALIGN_INT);
pfree(elems);

View File

@ -2878,7 +2878,7 @@ float8_combine(PG_FUNCTION_ARGS)
result = construct_array(transdatums, 3,
FLOAT8OID,
sizeof(float8), FLOAT8PASSBYVAL, 'd');
sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
PG_RETURN_ARRAYTYPE_P(result);
}
@ -2950,7 +2950,7 @@ float8_accum(PG_FUNCTION_ARGS)
result = construct_array(transdatums, 3,
FLOAT8OID,
sizeof(float8), FLOAT8PASSBYVAL, 'd');
sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
PG_RETURN_ARRAYTYPE_P(result);
}
@ -3024,7 +3024,7 @@ float4_accum(PG_FUNCTION_ARGS)
result = construct_array(transdatums, 3,
FLOAT8OID,
sizeof(float8), FLOAT8PASSBYVAL, 'd');
sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
PG_RETURN_ARRAYTYPE_P(result);
}
@ -3256,7 +3256,7 @@ float8_regr_accum(PG_FUNCTION_ARGS)
result = construct_array(transdatums, 6,
FLOAT8OID,
sizeof(float8), FLOAT8PASSBYVAL, 'd');
sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
PG_RETURN_ARRAYTYPE_P(result);
}
@ -3397,7 +3397,7 @@ float8_regr_combine(PG_FUNCTION_ARGS)
result = construct_array(transdatums, 6,
FLOAT8OID,
sizeof(float8), FLOAT8PASSBYVAL, 'd');
sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE);
PG_RETURN_ARRAYTYPE_P(result);
}

View File

@ -136,7 +136,8 @@ format_type_extended(Oid type_oid, int32 typemod, bits16 flags)
*/
array_base_type = typeform->typelem;
if (array_base_type != InvalidOid && typeform->typstorage != 'p')
if (array_base_type != InvalidOid &&
typeform->typstorage != TYPSTORAGE_PLAIN)
{
/* Switch our attention to the array element type */
ReleaseSysCache(tuple);

View File

@ -1142,7 +1142,7 @@ json_object(PG_FUNCTION_ARGS)
}
deconstruct_array(in_array,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&in_datums, &in_nulls, &in_count);
count = in_count / 2;
@ -1219,11 +1219,11 @@ json_object_two_arg(PG_FUNCTION_ARGS)
PG_RETURN_DATUM(CStringGetTextDatum("{}"));
deconstruct_array(key_array,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&key_datums, &key_nulls, &key_count);
deconstruct_array(val_array,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&val_datums, &val_nulls, &val_count);
if (key_count != val_count)

View File

@ -1317,7 +1317,7 @@ jsonb_object(PG_FUNCTION_ARGS)
}
deconstruct_array(in_array,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&in_datums, &in_nulls, &in_count);
count = in_count / 2;
@ -1405,11 +1405,11 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS)
goto close_object;
deconstruct_array(key_array,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&key_datums, &key_nulls, &key_count);
deconstruct_array(val_array,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&val_datums, &val_nulls, &val_count);
if (key_count != val_count)

View File

@ -886,7 +886,7 @@ gin_extract_jsonb_query(PG_FUNCTION_ARGS)
j;
deconstruct_array(query,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&key_datums, &key_nulls, &key_count);
entries = (Datum *) palloc(sizeof(Datum) * key_count);

View File

@ -53,8 +53,8 @@ jsonb_exists_any(PG_FUNCTION_ARGS)
bool *key_nulls;
int elem_count;
deconstruct_array(keys, TEXTOID, -1, false, 'i', &key_datums, &key_nulls,
&elem_count);
deconstruct_array(keys, TEXTOID, -1, false, TYPALIGN_INT,
&key_datums, &key_nulls, &elem_count);
for (i = 0; i < elem_count; i++)
{
@ -86,8 +86,8 @@ jsonb_exists_all(PG_FUNCTION_ARGS)
bool *key_nulls;
int elem_count;
deconstruct_array(keys, TEXTOID, -1, false, 'i', &key_datums, &key_nulls,
&elem_count);
deconstruct_array(keys, TEXTOID, -1, false, TYPALIGN_INT,
&key_datums, &key_nulls, &elem_count);
for (i = 0; i < elem_count; i++)
{

View File

@ -1019,7 +1019,7 @@ get_path_all(FunctionCallInfo fcinfo, bool as_text)
if (array_contains_nulls(path))
PG_RETURN_NULL();
deconstruct_array(path, TEXTOID, -1, false, 'i',
deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
&pathtext, &pathnulls, &npath);
tpath = palloc(npath * sizeof(char *));
@ -1479,7 +1479,7 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
if (array_contains_nulls(path))
PG_RETURN_NULL();
deconstruct_array(path, TEXTOID, -1, false, 'i',
deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
&pathtext, &pathnulls, &npath);
/* Identify whether we have object, array, or scalar at top-level */
@ -4361,7 +4361,7 @@ jsonb_delete_array(PG_FUNCTION_ARGS)
if (JB_ROOT_COUNT(in) == 0)
PG_RETURN_JSONB_P(in);
deconstruct_array(keys, TEXTOID, -1, false, 'i',
deconstruct_array(keys, TEXTOID, -1, false, TYPALIGN_INT,
&keys_elems, &keys_nulls, &keys_len);
if (keys_len == 0)
@ -4511,7 +4511,7 @@ jsonb_set(PG_FUNCTION_ARGS)
if (JB_ROOT_COUNT(in) == 0 && !create)
PG_RETURN_JSONB_P(in);
deconstruct_array(path, TEXTOID, -1, false, 'i',
deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
&path_elems, &path_nulls, &path_len);
if (path_len == 0)
@ -4622,7 +4622,7 @@ jsonb_delete_path(PG_FUNCTION_ARGS)
if (JB_ROOT_COUNT(in) == 0)
PG_RETURN_JSONB_P(in);
deconstruct_array(path, TEXTOID, -1, false, 'i',
deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
&path_elems, &path_nulls, &path_len);
if (path_len == 0)
@ -4665,7 +4665,7 @@ jsonb_insert(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cannot set path in scalar")));
deconstruct_array(path, TEXTOID, -1, false, 'i',
deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
&path_elems, &path_nulls, &path_len);
if (path_len == 0)

View File

@ -519,7 +519,7 @@ pg_blocking_pids(PG_FUNCTION_ARGS)
/* Construct array, using hardwired knowledge about int4 type */
PG_RETURN_ARRAYTYPE_P(construct_array(arrayelems, narrayelems,
INT4OID,
sizeof(int32), true, 'i'));
sizeof(int32), true, TYPALIGN_INT));
}
@ -560,7 +560,7 @@ pg_safe_snapshot_blocking_pids(PG_FUNCTION_ARGS)
/* Construct array, using hardwired knowledge about int4 type */
PG_RETURN_ARRAYTYPE_P(construct_array(blocker_datums, num_blockers,
INT4OID,
sizeof(int32), true, 'i'));
sizeof(int32), true, TYPALIGN_INT));
}

View File

@ -358,7 +358,7 @@ current_schemas(PG_FUNCTION_ARGS)
NAMEOID,
NAMEDATALEN, /* sizeof(Name) */
false, /* Name is not by-val */
'c'); /* alignment of Name */
TYPALIGN_CHAR); /* alignment of Name */
PG_RETURN_POINTER(array);
}

View File

@ -755,7 +755,7 @@ percentile_disc_multi_final(PG_FUNCTION_ARGS)
deconstruct_array(param, FLOAT8OID,
/* hard-wired info on type float8 */
8, FLOAT8PASSBYVAL, 'd',
sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE,
&percentiles_datum,
&percentiles_null,
&num_percentiles);
@ -879,7 +879,7 @@ percentile_cont_multi_final_common(FunctionCallInfo fcinfo,
deconstruct_array(param, FLOAT8OID,
/* hard-wired info on type float8 */
8, FLOAT8PASSBYVAL, 'd',
sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE,
&percentiles_datum,
&percentiles_null,
&num_percentiles);
@ -1002,7 +1002,9 @@ percentile_cont_float8_multi_final(PG_FUNCTION_ARGS)
return percentile_cont_multi_final_common(fcinfo,
FLOAT8OID,
/* hard-wired info on type float8 */
8, FLOAT8PASSBYVAL, 'd',
sizeof(float8),
FLOAT8PASSBYVAL,
TYPALIGN_DOUBLE,
float8_lerp);
}
@ -1015,7 +1017,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, 'd',
16, false, TYPALIGN_DOUBLE,
interval_lerp);
}

View File

@ -160,7 +160,7 @@ binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS)
int i;
deconstruct_array(textArray,
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&textDatums, NULL, &ndatums);
for (i = 0; i < ndatums; i++)
{

View File

@ -2389,7 +2389,7 @@ range_contains_elem_internal(TypeCacheEntry *typcache, const RangeType *r, Datum
/* Does datatype allow packing into the 1-byte-header varlena format? */
#define TYPE_IS_PACKABLE(typlen, typstorage) \
((typlen) == -1 && (typstorage) != 'p')
((typlen) == -1 && (typstorage) != TYPSTORAGE_PLAIN)
/*
* Increment data_length by the space needed by the datum, including any
@ -2473,7 +2473,7 @@ datum_write(Pointer ptr, Datum datum, bool typbyval, char typalign,
else if (typlen == -2)
{
/* cstring ... never needs alignment */
Assert(typalign == 'c');
Assert(typalign == TYPALIGN_CHAR);
data_length = strlen(DatumGetCString(datum)) + 1;
memcpy(ptr, DatumGetPointer(datum), data_length);
}

View File

@ -1329,7 +1329,7 @@ build_regexp_match_result(regexp_matches_ctx *matchctx)
lbs[0] = 1;
/* XXX: this hardcodes assumptions about the text type */
return construct_md_array(elems, nulls, 1, dims, lbs,
TEXTOID, -1, false, 'i');
TEXTOID, -1, false, TYPALIGN_INT);
}
/*

View File

@ -2154,7 +2154,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
elog(ERROR, "null indkey for index %u", indexId);
deconstruct_array(DatumGetArrayTypeP(cols),
INT2OID, 2, true, 's',
INT2OID, 2, true, TYPALIGN_SHORT,
&keys, NULL, &nKeys);
for (j = keyatts; j < nKeys; j++)
@ -2279,7 +2279,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
constraintId);
deconstruct_array(DatumGetArrayTypeP(val),
OIDOID, sizeof(Oid), true, 'i',
OIDOID, sizeof(Oid), true, TYPALIGN_INT,
&elems, NULL, &nElems);
operators = (Oid *) palloc(nElems * sizeof(Oid));
@ -2335,7 +2335,7 @@ decompile_column_index_array(Datum column_index_array, Oid relId,
/* Extract data from array of int16 */
deconstruct_array(DatumGetArrayTypeP(column_index_array),
INT2OID, 2, true, 's',
INT2OID, 2, true, TYPALIGN_SHORT,
&keys, NULL, &nKeys);
for (j = 0; j < nKeys; j++)
@ -2730,7 +2730,7 @@ pg_get_functiondef(PG_FUNCTION_ARGS)
-1 /* varlenarray */ ,
-1 /* TEXT's typlen */ ,
false /* TEXT's typbyval */ ,
'i' /* TEXT's typalign */ ,
TYPALIGN_INT /* TEXT's typalign */ ,
&isnull);
if (!isnull)
{
@ -11277,7 +11277,7 @@ flatten_reloptions(Oid relid)
initStringInfo(&buf);
deconstruct_array(DatumGetArrayTypeP(reloptions),
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&options, NULL, &noptions);
for (i = 0; i < noptions; i++)

View File

@ -3421,7 +3421,7 @@ interval_accum(PG_FUNCTION_ARGS)
ArrayType *result;
deconstruct_array(transarray,
INTERVALOID, sizeof(Interval), false, 'd',
INTERVALOID, sizeof(Interval), false, TYPALIGN_DOUBLE,
&transdatums, NULL, &ndatums);
if (ndatums != 2)
elog(ERROR, "expected 2-element interval array");
@ -3438,7 +3438,7 @@ interval_accum(PG_FUNCTION_ARGS)
transdatums[1] = IntervalPGetDatum(&N);
result = construct_array(transdatums, 2,
INTERVALOID, sizeof(Interval), false, 'd');
INTERVALOID, sizeof(Interval), false, TYPALIGN_DOUBLE);
PG_RETURN_ARRAYTYPE_P(result);
}
@ -3461,7 +3461,7 @@ interval_combine(PG_FUNCTION_ARGS)
ArrayType *result;
deconstruct_array(transarray1,
INTERVALOID, sizeof(Interval), false, 'd',
INTERVALOID, sizeof(Interval), false, TYPALIGN_DOUBLE,
&transdatums1, NULL, &ndatums1);
if (ndatums1 != 2)
elog(ERROR, "expected 2-element interval array");
@ -3470,7 +3470,7 @@ interval_combine(PG_FUNCTION_ARGS)
N1 = *(DatumGetIntervalP(transdatums1[1]));
deconstruct_array(transarray2,
INTERVALOID, sizeof(Interval), false, 'd',
INTERVALOID, sizeof(Interval), false, TYPALIGN_DOUBLE,
&transdatums2, NULL, &ndatums2);
if (ndatums2 != 2)
elog(ERROR, "expected 2-element interval array");
@ -3487,7 +3487,7 @@ interval_combine(PG_FUNCTION_ARGS)
transdatums1[1] = IntervalPGetDatum(&N1);
result = construct_array(transdatums1, 2,
INTERVALOID, sizeof(Interval), false, 'd');
INTERVALOID, sizeof(Interval), false, TYPALIGN_DOUBLE);
PG_RETURN_ARRAYTYPE_P(result);
}
@ -3505,7 +3505,7 @@ interval_accum_inv(PG_FUNCTION_ARGS)
ArrayType *result;
deconstruct_array(transarray,
INTERVALOID, sizeof(Interval), false, 'd',
INTERVALOID, sizeof(Interval), false, TYPALIGN_DOUBLE,
&transdatums, NULL, &ndatums);
if (ndatums != 2)
elog(ERROR, "expected 2-element interval array");
@ -3522,7 +3522,7 @@ interval_accum_inv(PG_FUNCTION_ARGS)
transdatums[1] = IntervalPGetDatum(&N);
result = construct_array(transdatums, 2,
INTERVALOID, sizeof(Interval), false, 'd');
INTERVALOID, sizeof(Interval), false, TYPALIGN_DOUBLE);
PG_RETURN_ARRAYTYPE_P(result);
}
@ -3537,7 +3537,7 @@ interval_avg(PG_FUNCTION_ARGS)
N;
deconstruct_array(transarray,
INTERVALOID, sizeof(Interval), false, 'd',
INTERVALOID, sizeof(Interval), false, TYPALIGN_DOUBLE,
&transdatums, NULL, &ndatums);
if (ndatums != 2)
elog(ERROR, "expected 2-element interval array");

View File

@ -303,7 +303,7 @@ tsvector_setweight_by_filter(PG_FUNCTION_ARGS)
memcpy(tsout, tsin, VARSIZE(tsin));
entry = ARRPTR(tsout);
deconstruct_array(lexemes, TEXTOID, -1, false, 'i',
deconstruct_array(lexemes, TEXTOID, -1, false, TYPALIGN_INT,
&dlexemes, &nulls, &nlexemes);
/*
@ -582,7 +582,7 @@ tsvector_delete_arr(PG_FUNCTION_ARGS)
Datum *dlexemes;
bool *nulls;
deconstruct_array(lexemes, TEXTOID, -1, false, 'i',
deconstruct_array(lexemes, TEXTOID, -1, false, TYPALIGN_INT,
&dlexemes, &nulls, &nlex);
/*
@ -692,9 +692,9 @@ tsvector_unnest(PG_FUNCTION_ARGS)
}
values[1] = PointerGetDatum(construct_array(positions, posv->npos,
INT2OID, 2, true, 's'));
INT2OID, 2, true, TYPALIGN_SHORT));
values[2] = PointerGetDatum(construct_array(weights, posv->npos,
TEXTOID, -1, false, 'i'));
TEXTOID, -1, false, TYPALIGN_INT));
}
else
{
@ -731,7 +731,7 @@ tsvector_to_array(PG_FUNCTION_ARGS)
arrin[i].len));
}
array = construct_array(elements, tsin->size, TEXTOID, -1, false, 'i');
array = construct_array(elements, tsin->size, TEXTOID, -1, false, TYPALIGN_INT);
pfree(elements);
PG_FREE_IF_COPY(tsin, 0);
@ -755,7 +755,7 @@ array_to_tsvector(PG_FUNCTION_ARGS)
datalen = 0;
char *cur;
deconstruct_array(v, TEXTOID, -1, false, 'i', &dlexemes, &nulls, &nitems);
deconstruct_array(v, TEXTOID, -1, false, TYPALIGN_INT, &dlexemes, &nulls, &nitems);
/* Reject nulls (maybe we should just ignore them, instead?) */
for (i = 0; i < nitems; i++)
@ -823,7 +823,7 @@ tsvector_filter(PG_FUNCTION_ARGS)
int cur_pos = 0;
char mask = 0;
deconstruct_array(weights, CHAROID, 1, true, 'c',
deconstruct_array(weights, CHAROID, 1, true, TYPALIGN_CHAR,
&dweights, &nulls, &nweights);
for (i = 0; i < nweights; i++)

View File

@ -4754,7 +4754,7 @@ text_to_array_internal(PG_FUNCTION_ARGS)
/* XXX: this hardcodes assumptions about the text type */
PG_RETURN_ARRAYTYPE_P(construct_md_array(elems, nulls,
1, dims, lbs,
TEXTOID, -1, false, 'i'));
TEXTOID, -1, false, TYPALIGN_INT));
}
text_position_setup(inputstring, fldsep, PG_GET_COLLATION(), &state);

View File

@ -4036,7 +4036,7 @@ xpath_internal(text *xpath_expr_text, xmltype *data, ArrayType *namespaces,
Assert(ARR_ELEMTYPE(namespaces) == TEXTOID);
deconstruct_array(namespaces, TEXTOID, -1, false, 'i',
deconstruct_array(namespaces, TEXTOID, -1, false, TYPALIGN_INT,
&ns_names_uris, &ns_names_uris_nulls,
&ns_count);

View File

@ -230,7 +230,8 @@ DecodeTextArrayToBitmapset(Datum array)
if (ARR_NDIM(arr) != 1 || ARR_HASNULL(arr) || ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "expected 1-D text array");
deconstruct_array(arr, TEXTOID, -1, false, 'i', &elems, NULL, &nelems);
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
&elems, NULL, &nelems);
for (bms = NULL, i = 0; i < nelems; ++i)
{

View File

@ -2189,7 +2189,7 @@ get_typalign(Oid typid)
return result;
}
else
return 'i';
return TYPALIGN_INT;
}
#endif
@ -2209,7 +2209,7 @@ get_typstorage(Oid typid)
return result;
}
else
return 'p';
return TYPSTORAGE_PLAIN;
}
/*

View File

@ -917,7 +917,7 @@ get_func_arg_info(HeapTuple procTup,
else
{
deconstruct_array(DatumGetArrayTypeP(proargnames),
TEXTOID, -1, false, 'i',
TEXTOID, -1, false, TYPALIGN_INT,
&elems, NULL, &nelems);
if (nelems != numargs) /* should not happen */
elog(ERROR, "proargnames must have the same number of elements as the function has arguments");
@ -1030,7 +1030,7 @@ get_func_input_arg_names(Datum proargnames, Datum proargmodes,
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "proargnames is not a 1-D text array");
deconstruct_array(arr, TEXTOID, -1, false, 'i',
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
&argnames, NULL, &numargs);
if (proargmodes != PointerGetDatum(NULL))
{
@ -1143,7 +1143,7 @@ get_func_result_name(Oid functionId)
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "proargnames is not a 1-D text array");
deconstruct_array(arr, TEXTOID, -1, false, 'i',
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
&argnames, NULL, &nargnames);
Assert(nargnames == numargs);
@ -1290,7 +1290,7 @@ build_function_result_tupdesc_d(char prokind,
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "proargnames is not a 1-D text array");
deconstruct_array(arr, TEXTOID, -1, false, 'i',
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
&argnames, NULL, &nargnames);
Assert(nargnames == numargs);
}

View File

@ -10470,7 +10470,7 @@ ProcessGUCArray(ArrayType *array,
-1 /* varlenarray */ ,
-1 /* TEXT's typlen */ ,
false /* TEXT's typbyval */ ,
'i' /* TEXT's typalign */ ,
TYPALIGN_INT /* TEXT's typalign */ ,
&isnull);
if (isnull)
@ -10549,7 +10549,7 @@ GUCArrayAdd(ArrayType *array, const char *name, const char *value)
-1 /* varlenarray */ ,
-1 /* TEXT's typlen */ ,
false /* TEXT's typbyval */ ,
'i' /* TEXT's typalign */ ,
TYPALIGN_INT /* TEXT's typalign */ ,
&isnull);
if (isnull)
continue;
@ -10569,12 +10569,12 @@ GUCArrayAdd(ArrayType *array, const char *name, const char *value)
-1 /* varlena array */ ,
-1 /* TEXT's typlen */ ,
false /* TEXT's typbyval */ ,
'i' /* TEXT's typalign */ );
TYPALIGN_INT /* TEXT's typalign */ );
}
else
a = construct_array(&datum, 1,
TEXTOID,
-1, false, 'i');
-1, false, TYPALIGN_INT);
return a;
}
@ -10620,7 +10620,7 @@ GUCArrayDelete(ArrayType *array, const char *name)
-1 /* varlenarray */ ,
-1 /* TEXT's typlen */ ,
false /* TEXT's typbyval */ ,
'i' /* TEXT's typalign */ ,
TYPALIGN_INT /* TEXT's typalign */ ,
&isnull);
if (isnull)
continue;
@ -10639,11 +10639,11 @@ GUCArrayDelete(ArrayType *array, const char *name)
-1 /* varlenarray */ ,
-1 /* TEXT's typlen */ ,
false /* TEXT's typbyval */ ,
'i' /* TEXT's typalign */ );
TYPALIGN_INT /* TEXT's typalign */ );
else
newarray = construct_array(&d, 1,
TEXTOID,
-1, false, 'i');
-1, false, TYPALIGN_INT);
index++;
}
@ -10686,7 +10686,7 @@ GUCArrayReset(ArrayType *array)
-1 /* varlenarray */ ,
-1 /* TEXT's typlen */ ,
false /* TEXT's typbyval */ ,
'i' /* TEXT's typalign */ ,
TYPALIGN_INT /* TEXT's typalign */ ,
&isnull);
if (isnull)
continue;
@ -10707,11 +10707,11 @@ GUCArrayReset(ArrayType *array)
-1 /* varlenarray */ ,
-1 /* TEXT's typlen */ ,
false /* TEXT's typbyval */ ,
'i' /* TEXT's typalign */ );
TYPALIGN_INT /* TEXT's typalign */ );
else
newarray = construct_array(&d, 1,
TEXTOID,
-1, false, 'i');
-1, false, TYPALIGN_INT);
index++;
pfree(val);

View File

@ -10756,22 +10756,22 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
appendStringLiteralAH(q, typdelim, fout);
}
if (strcmp(typalign, "c") == 0)
if (*typalign == TYPALIGN_CHAR)
appendPQExpBufferStr(q, ",\n ALIGNMENT = char");
else if (strcmp(typalign, "s") == 0)
else if (*typalign == TYPALIGN_SHORT)
appendPQExpBufferStr(q, ",\n ALIGNMENT = int2");
else if (strcmp(typalign, "i") == 0)
else if (*typalign == TYPALIGN_INT)
appendPQExpBufferStr(q, ",\n ALIGNMENT = int4");
else if (strcmp(typalign, "d") == 0)
else if (*typalign == TYPALIGN_DOUBLE)
appendPQExpBufferStr(q, ",\n ALIGNMENT = double");
if (strcmp(typstorage, "p") == 0)
if (*typstorage == TYPSTORAGE_PLAIN)
appendPQExpBufferStr(q, ",\n STORAGE = plain");
else if (strcmp(typstorage, "e") == 0)
else if (*typstorage == TYPSTORAGE_EXTERNAL)
appendPQExpBufferStr(q, ",\n STORAGE = external");
else if (strcmp(typstorage, "x") == 0)
else if (*typstorage == TYPSTORAGE_EXTENDED)
appendPQExpBufferStr(q, ",\n STORAGE = extended");
else if (strcmp(typstorage, "m") == 0)
else if (*typstorage == TYPSTORAGE_MAIN)
appendPQExpBufferStr(q, ",\n STORAGE = main");
if (strcmp(typbyval, "t") == 0)
@ -16129,18 +16129,18 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
{
switch (tbinfo->attstorage[j])
{
case 'p':
case TYPSTORAGE_PLAIN:
storage = "PLAIN";
break;
case 'e':
case TYPSTORAGE_EXTERNAL:
storage = "EXTERNAL";
break;
case 'm':
storage = "MAIN";
break;
case 'x':
case TYPSTORAGE_EXTENDED:
storage = "EXTENDED";
break;
case TYPSTORAGE_MAIN:
storage = "MAIN";
break;
default:
storage = NULL;
}

View File

@ -20,12 +20,12 @@
* Information about one column of a tuple being toasted.
*
* NOTE: toast_action[i] can have these values:
* ' ' default handling
* 'p' already processed --- don't touch it
* 'x' incompressible, but OK to move off
* ' ' default handling
* TYPSTORAGE_PLAIN already processed --- don't touch it
* TYPSTORAGE_EXTENDED incompressible, but OK to move off
*
* NOTE: toast_attr[i].tai_size is only made valid for varlena attributes with
* toast_action[i] different from 'p'.
* toast_action[i] different from TYPSTORAGE_PLAIN.
*/
typedef struct
{

View File

@ -14,6 +14,8 @@
#ifndef TUPMACS_H
#define TUPMACS_H
#include "catalog/pg_type_d.h" /* for TYPALIGN macros */
/*
* Check a tuple's null bitmap to determine whether the attribute is null.
@ -145,11 +147,11 @@
*/
#define att_align_nominal(cur_offset, attalign) \
( \
((attalign) == 'i') ? INTALIGN(cur_offset) : \
(((attalign) == 'c') ? (uintptr_t) (cur_offset) : \
(((attalign) == 'd') ? DOUBLEALIGN(cur_offset) : \
((attalign) == TYPALIGN_INT) ? INTALIGN(cur_offset) : \
(((attalign) == TYPALIGN_CHAR) ? (uintptr_t) (cur_offset) : \
(((attalign) == TYPALIGN_DOUBLE) ? DOUBLEALIGN(cur_offset) : \
( \
AssertMacro((attalign) == 's'), \
AssertMacro((attalign) == TYPALIGN_SHORT), \
SHORTALIGN(cur_offset) \
))) \
)

View File

@ -110,14 +110,7 @@ CATALOG(pg_attribute,1249,AttributeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(75,
/*----------
* attstorage tells for VARLENA attributes, what the heap access
* methods can do to it if a given tuple doesn't fit into a page.
* Possible values are
* 'p': Value must be stored plain always
* 'e': Value can be stored in "secondary" relation (if relation
* has one, see pg_class.reltoastrelid)
* 'm': Value can be stored compressed inline
* 'x': Value can be stored compressed inline or in "secondary"
* Note that 'm' fields can also be moved out to secondary storage,
* but only as a last resort ('e' and 'x' fields are moved first).
* Possible values are as for pg_type.typstorage (see TYPSTORAGE macros).
*----------
*/
char attstorage;

View File

@ -155,6 +155,7 @@ CATALOG(pg_type,1247,TypeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(71,TypeRelati
* 's' = SHORT alignment (2 bytes on most machines).
* 'i' = INT alignment (4 bytes on most machines).
* 'd' = DOUBLE alignment (8 bytes on many machines, but by no means all).
* (Use the TYPALIGN macros below for these.)
*
* See include/access/tupmacs.h for the macros that compute these
* alignment requirements. Note also that we allow the nominal alignment
@ -176,6 +177,10 @@ CATALOG(pg_type,1247,TypeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(71,TypeRelati
* 'e' EXTERNAL external storage possible, don't try to compress
* 'x' EXTENDED try to compress and store external if required
* 'm' MAIN like 'x' but try to keep in main tuple
* (Use the TYPSTORAGE macros below for these.)
*
* Note that 'm' fields can also be moved out to secondary storage,
* but only as a last resort ('e' and 'x' fields are moved first).
* ----------------
*/
char typstorage BKI_DEFAULT(p) BKI_ARRAY_DEFAULT(x);
@ -278,6 +283,16 @@ typedef FormData_pg_type *Form_pg_type;
#define TYPCATEGORY_BITSTRING 'V' /* er ... "varbit"? */
#define TYPCATEGORY_UNKNOWN 'X'
#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_DOUBLE 'd' /* double alignment (often 8 bytes) */
#define TYPSTORAGE_PLAIN 'p' /* type not prepared for toasting */
#define TYPSTORAGE_EXTERNAL 'e' /* toastable, don't try to compress */
#define TYPSTORAGE_EXTENDED 'x' /* fully toastable */
#define TYPSTORAGE_MAIN 'm' /* like 'x' but try to store inline */
/* Is a type OID a polymorphic pseudotype? (Beware of multiple evaluation) */
#define IsPolymorphicType(typid) \
((typid) == ANYELEMENTOID || \

View File

@ -186,6 +186,6 @@ extern Oid get_index_column_opclass(Oid index_oid, int attno);
/* type_is_array_domain accepts both plain arrays and domains over arrays */
#define type_is_array_domain(typid) (get_base_element_type(typid) != InvalidOid)
#define TypeIsToastable(typid) (get_typstorage(typid) != 'p')
#define TypeIsToastable(typid) (get_typstorage(typid) != TYPSTORAGE_PLAIN)
#endif /* LSYSCACHE_H */

View File

@ -2125,13 +2125,13 @@ build_datatype(HeapTuple typeTup, int32 typmod,
*/
typ->typisarray = (typeStruct->typlen == -1 &&
OidIsValid(typeStruct->typelem) &&
typeStruct->typstorage != 'p');
typeStruct->typstorage != TYPSTORAGE_PLAIN);
}
else if (typeStruct->typtype == TYPTYPE_DOMAIN)
{
/* we can short-circuit looking up base types if it's not varlena */
typ->typisarray = (typeStruct->typlen == -1 &&
typeStruct->typstorage != 'p' &&
typeStruct->typstorage != TYPSTORAGE_PLAIN &&
OidIsValid(get_base_element_type(typeStruct->typbasetype)));
}
else

View File

@ -1456,7 +1456,7 @@ plpgsql_fulfill_promise(PLpgSQL_execstate *estate,
PointerGetDatum(construct_md_array(elems, NULL,
1, dims, lbs,
TEXTOID,
-1, false, 'i')),
-1, false, TYPALIGN_INT)),
false, true);
}
else

View File

@ -328,7 +328,7 @@ PLy_output_setup_func(PLyObToDatum *arg, MemoryContext arg_mcxt,
/* hard-wired knowledge about type RECORD: */
arg->typbyval = false;
arg->typlen = -1;
arg->typalign = 'd';
arg->typalign = TYPALIGN_DOUBLE;
}
/*
@ -451,7 +451,7 @@ PLy_input_setup_func(PLyDatumToOb *arg, MemoryContext arg_mcxt,
/* hard-wired knowledge about type RECORD: */
arg->typbyval = false;
arg->typlen = -1;
arg->typalign = 'd';
arg->typalign = TYPALIGN_DOUBLE;
}
/*

View File

@ -87,7 +87,7 @@ test_rls_hooks_permissive(CmdType cmdtype, Relation relation)
policy->policy_name = pstrdup("extension policy");
policy->polcmd = '*';
policy->roles = construct_array(&role, 1, OIDOID, sizeof(Oid), true, 'i');
policy->roles = construct_array(&role, 1, OIDOID, sizeof(Oid), true, TYPALIGN_INT);
/*
* policy->qual = (Expr *) makeConst(BOOLOID, -1, InvalidOid,
@ -152,7 +152,7 @@ test_rls_hooks_restrictive(CmdType cmdtype, Relation relation)
policy->policy_name = pstrdup("extension policy");
policy->polcmd = '*';
policy->roles = construct_array(&role, 1, OIDOID, sizeof(Oid), true, 'i');
policy->roles = construct_array(&role, 1, OIDOID, sizeof(Oid), true, TYPALIGN_INT);
n = makeFuncCall(list_make2(makeString("pg_catalog"),
makeString("current_user")), NIL, 0);