Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Introduce macros for typalign and typstorage constants.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 4 Mar 2020 15:34:25 +0000 (10:34 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 4 Mar 2020 15:34:25 +0000 (10:34 -0500)
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

76 files changed:
contrib/hstore/hstore_gin.c
contrib/hstore/hstore_gist.c
contrib/hstore/hstore_io.c
contrib/hstore/hstore_op.c
contrib/pageinspect/btreefuncs.c
contrib/pageinspect/ginfuncs.c
contrib/pageinspect/hashfuncs.c
contrib/pageinspect/heapfuncs.c
contrib/pg_trgm/trgm_op.c
contrib/pgcrypto/pgp-pgsql.c
src/backend/access/common/heaptuple.c
src/backend/access/common/indextuple.c
src/backend/access/common/reloptions.c
src/backend/access/common/tupdesc.c
src/backend/access/heap/heapam_handler.c
src/backend/access/heap/heaptoast.c
src/backend/access/table/toast_helper.c
src/backend/bootstrap/bootstrap.c
src/backend/catalog/heap.c
src/backend/catalog/objectaddress.c
src/backend/catalog/pg_constraint.c
src/backend/catalog/pg_proc.c
src/backend/catalog/pg_subscription.c
src/backend/catalog/pg_type.c
src/backend/catalog/toasting.c
src/backend/commands/analyze.c
src/backend/commands/event_trigger.c
src/backend/commands/extension.c
src/backend/commands/functioncmds.c
src/backend/commands/policy.c
src/backend/commands/prepare.c
src/backend/commands/statscmds.c
src/backend/commands/subscriptioncmds.c
src/backend/commands/tablecmds.c
src/backend/commands/typecmds.c
src/backend/executor/nodeTidscan.c
src/backend/jit/llvm/llvmjit_deform.c
src/backend/libpq/hba.c
src/backend/parser/parse_type.c
src/backend/parser/parse_utilcmd.c
src/backend/replication/logical/logicalfuncs.c
src/backend/tsearch/dict.c
src/backend/utils/adt/arrayutils.c
src/backend/utils/adt/enum.c
src/backend/utils/adt/float.c
src/backend/utils/adt/format_type.c
src/backend/utils/adt/json.c
src/backend/utils/adt/jsonb.c
src/backend/utils/adt/jsonb_gin.c
src/backend/utils/adt/jsonb_op.c
src/backend/utils/adt/jsonfuncs.c
src/backend/utils/adt/lockfuncs.c
src/backend/utils/adt/name.c
src/backend/utils/adt/orderedsetaggs.c
src/backend/utils/adt/pg_upgrade_support.c
src/backend/utils/adt/rangetypes.c
src/backend/utils/adt/regexp.c
src/backend/utils/adt/ruleutils.c
src/backend/utils/adt/timestamp.c
src/backend/utils/adt/tsvector_op.c
src/backend/utils/adt/varlena.c
src/backend/utils/adt/xml.c
src/backend/utils/cache/evtcache.c
src/backend/utils/cache/lsyscache.c
src/backend/utils/fmgr/funcapi.c
src/backend/utils/misc/guc.c
src/bin/pg_dump/pg_dump.c
src/include/access/toast_helper.h
src/include/access/tupmacs.h
src/include/catalog/pg_attribute.h
src/include/catalog/pg_type.h
src/include/utils/lsyscache.h
src/pl/plpgsql/src/pl_comp.c
src/pl/plpgsql/src/pl_exec.c
src/pl/plpython/plpy_typeio.c
src/test/modules/test_rls_hooks/test_rls_hooks.c

index 4c3a422643dcee040cc96513ac7fdd9150e9a14d..908530261aeab787ed449aac732312ffc88e88b7 100644 (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);
index e860f1e4d357b0aa052492b5572931ae0171d1f5..d198c4b7d7788f44070efebccabfc51bedc89b49 100644 (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;
index f3174f2995110fabb38acfedf41b93e4b0d009e0..60bdbea46be18ca9ba6b9ba2dfb12bb12a947cd1 100644 (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;
index fb1bb0681cca55dd794fc48b249b1bc3547fe035..dd79d01cac308c5883366886450315d14581c4b8 100644 (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);
index 2ddedef7141b5ca33c93670fddcd607d2464bde0..dffb3e199ba2d893617c2cd9a983ee669eb143aa 100644 (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
index 9b1d41c510ee2229fe44fecbe87e34d6d417e4fb..7e2cafab74de8fc7892c2a40a1bb3e7bdd8f6aa9 100644 (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);
 
index effc80fbd3fbe3fa31c4c1b9139d10373b640786..984ac33186040da6de0a4cbea9493e1e1c0d58b3 100644 (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);
 
index 20b4d32429e20ca66b96316aec8dc2213b899db7..11a910184bf3a7fbab5ef1b50773ce7573c8a604 100644 (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);
 
index 0670095c20655787593c393492511d77650eb4b8..fb38135f7a3995f35212eca210688e06fbb11bf5 100644 (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]));
index 8be895df80f03074a637e151eb79cf11d1fcf9e5..62a2f351e43b93527e6670da94de8dab7de8abf4 100644 (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)
index b7c864cfacffa47a5499dfb2496ef352ba496a2e..f89769f37937448858ae44d5982536b29c5fb38b 100644 (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.
 
 /* 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);
    }
index bfc8b154a7a93087746017b570365cd831a88a9c..634016b9b7c04cb37dff5c8378beae108b4d7e27 100644 (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]);
 
index 5325dd3f611a0e3e05857cb976e49451101f160f..c3d45c7a248ee6f995132c381b6d9c40ce3b4436 100644 (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++)
index 28835512f0089243dca2d9ed9946c60293263c87..1e743d7d86e85b66fdef232eeba50f7cd7df77af 100644 (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;
 
index 3fa4b766db885ce1edb956404a81dbb306977758..ca52846b973ae0d5ce8d538e79b91d61f382ee78 100644 (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;
        }
    }
index a6631f93d34eea8328ef9de508de401233afcafe..584f101dd987ba568080d12c0342228483144426 100644 (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;
index a32486588082b811f4c597ef52dcf68c76081c06..739b6ae9900ec3a5863cec728ffe31b9c6dd401f 100644 (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)
index bfc629c7539fc10d9216201c618689cf1844ec71..657b18ecc8949eabe6922dd63baca925ae8b3504 100644 (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}
 };
 
index e31478bf9177c01b9f626be4934f6d000e7d566a..9d9e9159796587a92b938a8c68442a3b027bf97f 100644 (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 */
index 93b90436a2ba91cbb961d26d8e430db2dc2c7269..d0b5de49ebd13d3f0ddb2df8060b8fe2e33796f2 100644 (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);
 
index 3d2b1cc9119c990199f542cba758dea14c5ab6ac..90932be8310177788a865ce4ed4b5e4f2c295011 100644 (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;
index 5194dcaac083d051420bc0f76ecaac68d8e01098..423fd79d945fa791a911073f7972a237fad45c26 100644 (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]);
index f77a83bd2ea71f2e45206a7a4222f1134eb931f6..cb1573111545d331f7a546e9f725314cd5958c2d 100644 (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)
index 8d7572da513aa5962db52138ade1781fc0218367..56e0bcf39eebfe79b04dfe1195793b5e8d2e689a 100644 (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")));
index 33344476cac12925f2909ec1e5759150af6259ea..3239185b425a100d47bcf1559cd01652c23a188f 100644 (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
index c4420ddd7f2fc29c7b31e2069d1fd3dd752a9758..924ef37c8163827c1debc11fcd2f88f2c9776110 100644 (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
index a366869369b3cd32cf291eea4aaf332a7ac7c5a4..91800d1fac18fbe7a19e4d477f8a33180abe1970 100644 (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));
 }
 
 /*
index a0db7db411b21c87c0d8e75df3fe83033b981055..00cf4ef268035d8085b6229f8599e8de98e99b5a 100644 (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);
    }
index 540044b2d68d5ff37140d38748428959e86b9291..6d824a5ebfb64c1198c2f3905612891de0e49aa9 100644 (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
    {
index 6e990a38182dc7f111f791b9d364cc42f5527314..4b4e4694930e2823e191ff651b5635b43c958624 100644 (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. */
index f917fc9c7a770f775a07743dac566fa6de7151ec..284a5bfbec750b2c8e8239b287fd4c0f7c17d8ce 100644 (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);
 }
index fb608cf5cdd09f36e2c34151427a0370aa729eed..988cdba6f5357f3aa7c5290897172c5aa0c57684 100644 (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);
 
index 119a9ce76ffe6e37997b699f89fb62db3716d374..f3ec012ddad01239eaafce3602396877e6002d4c 100644 (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);
 
index 02a7c04fdb7791b4e92df852e49fae8f15b8ea40..7a13b971649fb01aab2537f0ee1be33cc8732378 100644 (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,
index 52097363fd6034d48eae5af4c885b2341ee9b8b6..99528bf1d58e5b793717524455b3773919ff12d7 100644 (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 */
index f0d4883e687e57d9905063880301811e6cc8e918..b53a6bbe1d6c604ef34670dbc0c86d82f578e792 100644 (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)
            {
index d7a7b328e8be60e903b26c9f79e9d16f54986c1a..8a3064e6819bfe7736d9a8b896b6d11a79dc5149 100644 (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
        {
index d2a63e9e5681250408b2dd148b28ca4b068de609..da5189a4fa0ae66354c5f2b3e7ac0a0019888bed 100644 (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;
 }
index 2c237cd15d962f33b8357efd6502d91d3aed2c60..2709f6f9c7953b0e3511942ebfe89d81de772644 100644 (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);
index 973eab6ae2c848814b7dd69ab72e7d2f93a90ce7..af77f1890f9dd220b43fe0cc30fe008afe975c46 100644 (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++)
index 2bba2b4f24d6716581edb6a715f781609a5ee4f0..a3a83a9d36762365a0108d7008a104b13f0d68dd 100644 (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)
index e1d9e90f7a7aa980e2cfda923c78d897d54d42f1..835b6721a9f8931feda78753bbf50d82b454b678 100644 (file)
@@ -73,7 +73,7 @@ ts_lexize(PG_FUNCTION_ARGS)
                        TEXTOID,
                        -1,
                        false,
-                       'i');
+                       TYPALIGN_INT);
 
    ptr = res;
    while (ptr->lexeme)
index d972be17f935ffb82f428a59cdc9ee3eb9eeb7e1..bc4360aaec0c7069f639d9ae27ed48e5938a3c0e 100644 (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));
index 3ea0d5d31d7f5aabf7916e5be0c39fd678b33a46..5ead794e349233725063b407e68b8e615b3d4d5d 100644 (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);
 
index 34af0eb22b5c5c415452428c1c46158ed880729c..2101d586744d5ae01a3b4981ad7fc9d9c1739e43 100644 (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);
    }
index 92ee77ac5c6d37a06b4f3f5efc9da795d2f80c21..df0bdeb610bb8cdf800df752e6fd58d03f380f45 100644 (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);
index 567eab1e01e235e26ccbf7d896303b8d4d8478ce..f78420e22dc7dacbe4b003a982e1b859efff88e2 100644 (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)
index fea4335951519a5975417687eaa05154cfe22d5e..b961d2947235e10c2470d79fecf720c6ba24912d 100644 (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)
index 63122edf2e4c49c10e2312dce667b5833210fb18..aee3d9d6733ee7061d787cc77b09006e1ce5142c 100644 (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);
index 443ea24dc618c1e3720b403498d705f8dd7408ed..dc17e17f9b46b86c821e659c6cb55277a6210ec7 100644 (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++)
    {
index 6e33dfb2a2b5ef980f7be54c9a2ff0946bb62667..f92861d8d2967c451f2593612387003ba154569e 100644 (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)
index 7e47ebeb6f6725935a7587baaa75c81aa77f5b37..ecb1bf92ff7d1dc9d9bb2a0bd0ae8ad9b54b9c88 100644 (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));
 }
 
 
index 6749e75c89049740b98c43af78b2abcb32010e15..64877f67e0103445ae57be43514ab8eb4f504584 100644 (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);
 }
index d169045a1adb524566333adc4ca65a8b2ecbe791..f9b5d7024b5be541cff8fee6fa52ffc808f7817d 100644 (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);
 }
 
index 0d9e55cdcf4b0c22e7bc73f336e08607d5a63a50..18f2ee8226cc2077e365822d332b5ab0d002a0f8 100644 (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++)
        {
index b95132b714869d260b611d6f284ba4d1eee9163f..490bc2ae8136dbb4d1c502edad7e102a21d2aa72 100644 (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);
    }
index 6c76e89c9aefab438856193aeaa6fe2e2933948d..06f808652a4cb224f29b43f9b1b6f2c00bfadd69 100644 (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);
 }
 
 /*
index 158784474d8d1c72fcefeb259d73855f011bf7b6..5e63238f0302a02276f5c3785d0eeadf1fcf8227 100644 (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++)
index 0b6c9d5ea8ee7557241794ee356d404aa53be49a..4caffb580409ec245e76c201fcf9820daa9a9df2 100644 (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");
index cab6874e70218e9bcefe6965f75b086d4b22f9af..790355082d97ea0e67f9c04451335f222d00c2c0 100644 (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++)
index 18900e0f1ea56ebe001bef3a5d1579de2f5353b5..907b5ab7b02f2a4511ca1e3d1037878160a9d058 100644 (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);
index 3808c307f6fd8a3d71eb5e78eb3e9bc161aa62e7..c7ae1eded800b8ffabe039ba5983811420538ec6 100644 (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);
 
index b9c1a0a5adbc8c5c3e26da5c697057c0cacd9b1e..73d091d1f63c85f71c3362fb49685a0118956af3 100644 (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)
    {
index fb0599f7f13f096d0a97b984c19ab467b596518a..3da90cb72aea9a92fe810361f6117b133965c2e0 100644 (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;
 }
 
 /*
index b7eee3da1d65d2e66726fd836bee89572f5f5125..0201e4f8d34238d88322968f900ca07808e707dc 100644 (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);
    }
index 464f264d9a26be7cf98bdf5106e41e1ddc7d4911..dbecc00fef03edfe63e6b37d1a51af0c9d42eff2 100644 (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);
index ef1539044fde042c541991a806b60e3223e014db..caa25e3e758a403db7f0ad26f405be7abaa48073 100644 (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;
                }
index e59138df3e16e53aa5bf2e67c6cab5f6088dc829..0e92acc546e5c6334bdc6dfc2293ad861f611593 100644 (file)
  * 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
 {
index 0b205a0dc60ad056422df432fa10bc44470d0e5d..70157cf90ab113e85eab00cfefb55593fe9831c7 100644 (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.
  */
 #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) \
       ))) \
 )
index 591e0d65aed50b5240fd107a83534c5b6aed8754..a4cc80adad9c6bbc2d62931e2b1de6cb02a2fac5 100644 (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;
index e1a5ab3df30a0ade0dd751b938bda5286fbd5aa0..f972f941e05efd4985aa3dc949b2314e31a7a02c 100644 (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 || \
index 370f62a13340ffc75b76928f1fa2b2f563e2b399..f132d3945817bbc46bd050a7ad0b3744ab777769 100644 (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 */
index 4f6b36b145a58b9eb0109947941a18c4b489721f..c8e43e684f51f63c7039890324f49298ffcabfd9 100644 (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
index a867c2c43b83fc93fc166b48c60140b897afc596..d3ad4fa54dd9b6bbf3ef201de4b476f7cbe826eb 100644 (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
index e734b0d130349dc7927a6dd03f896d8a0c8bfe98..7c844c2b8a10c5d17b1f40171eb07d38c664b70e 100644 (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;
    }
 
    /*
index d1b7075bcc699a960c04e2d5516b6212ac575f27..0bfa878a2531dd7be6a3cf96c4e6bb7b76e00192 100644 (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);