just two macros.
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.43 1998/09/04 18:21:10 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.44 1998/09/07 05:35:27 momjian Exp $
*
* NOTES
* The old interface functions have been converted to macros
if (nulls[i] != ' ')
continue;
- switch (att[i]->attlen)
- {
- case -1:
-
- /*
- * This is the size of the disk representation and so must
- * include the additional sizeof long.
- */
- if (att[i]->attalign == 'd')
- {
- data_length = DOUBLEALIGN(data_length)
- + VARSIZE(DatumGetPointer(value[i]));
- }
- else
- {
- data_length = INTALIGN(data_length)
- + VARSIZE(DatumGetPointer(value[i]));
- }
- break;
- case sizeof(char):
- data_length++;
- break;
- case sizeof(short):
- data_length = SHORTALIGN(data_length + sizeof(short));
- break;
- case sizeof(int32):
- data_length = INTALIGN(data_length + sizeof(int32));
- break;
- default:
- if (att[i]->attlen < sizeof(int32))
- elog(ERROR, "ComputeDataSize: attribute %d has len %d",
- i, att[i]->attlen);
- if (att[i]->attalign == 'd')
- data_length = DOUBLEALIGN(data_length) + att[i]->attlen;
- else
- data_length = LONGALIGN(data_length) + att[i]->attlen;
- break;
- }
+ data_length = att_align(data_length, att[i]->attlen, att[i]->attalign);
+ data_length = att_addlength(data_length, att[i]->attlen, value[i]);
}
return data_length;
*bitP |= bitmask;
}
+ data = (char *)att_align((long)data, att[i]->attlen, att[i]->attalign);
switch (att[i]->attlen)
{
case -1:
*infomask |= HEAP_HASVARLENA;
- if (att[i]->attalign == 'd')
- data = (char *) DOUBLEALIGN(data);
- else
- data = (char *) INTALIGN(data);
data_length = VARSIZE(DatumGetPointer(value[i]));
memmove(data, DatumGetPointer(value[i]), data_length);
- data += data_length;
break;
case sizeof(char):
*data = att[i]->attbyval ?
DatumGetChar(value[i]) : *((char *) value[i]);
- data += sizeof(char);
break;
case sizeof(int16):
- data = (char *) SHORTALIGN(data);
*(short *) data = (att[i]->attbyval ?
DatumGetInt16(value[i]) :
*((short *) value[i]));
- data += sizeof(short);
break;
case sizeof(int32):
- data = (char *) INTALIGN(data);
*(int32 *) data = (att[i]->attbyval ?
DatumGetInt32(value[i]) :
*((int32 *) value[i]));
- data += sizeof(int32);
break;
default:
- if (att[i]->attlen < sizeof(int32))
- elog(ERROR, "DataFill: attribute %d has len %d",
- i, att[i]->attlen);
- if (att[i]->attalign == 'd')
- {
- data = (char *) DOUBLEALIGN(data);
- memmove(data, DatumGetPointer(value[i]),
- att[i]->attlen);
- data += att[i]->attlen;
- }
- else
- {
- data = (char *) LONGALIGN(data);
- memmove(data, DatumGetPointer(value[i]),
- att[i]->attlen);
- data += att[i]->attlen;
- }
+ memmove(data, DatumGetPointer(value[i]),
+ att[i]->attlen);
break;
}
+ data = (char *)att_addlength((long)data, att[i]->attlen, value[i]);
}
}
* Fix me when going to a machine with more than a four-byte
* word!
*/
-
- switch (att[j]->attlen)
- {
- case -1:
- off = (att[j]->attalign == 'd') ?
- DOUBLEALIGN(off) : INTALIGN(off);
- break;
- case sizeof(char):
- break;
- case sizeof(short):
- off = SHORTALIGN(off);
- break;
- case sizeof(int32):
- off = INTALIGN(off);
- break;
- default:
- if (att[j]->attlen > sizeof(int32))
- off = (att[j]->attalign == 'd') ?
- DOUBLEALIGN(off) : LONGALIGN(off);
- else
- elog(ERROR, "nocache_index_getattr: attribute %d has len %d",
- j, att[j]->attlen);
- break;
- }
+ off = att_align(off, att[j]->attlen, att[j]->attalign);
att[j]->attcacheoff = off;
- switch (att[j]->attlen)
- {
- case sizeof(char):
- off++;
- break;
- case sizeof(short):
- off += sizeof(short);
- break;
- case sizeof(int32):
- off += sizeof(int32);
- break;
- case -1:
- Assert(!VARLENA_FIXED_SIZE(att[j]) ||
- att[j]->atttypmod == VARSIZE(tp + off));
- off += VARSIZE(tp + off);
- break;
- default:
- off += att[j]->attlen;
- break;
- }
+ off = att_addlength(off, att[j]->attlen, tp + off);
}
return (Datum) fetchatt(&(att[attnum]), tp + att[attnum]->attcacheoff);
off = att[i]->attcacheoff;
else
{
- switch (att[i]->attlen)
- {
- case -1:
- off = (att[i]->attalign == 'd') ?
- DOUBLEALIGN(off) : INTALIGN(off);
- break;
- case sizeof(char):
- break;
- case sizeof(short):
- off = SHORTALIGN(off);
- break;
- case sizeof(int32):
- off = INTALIGN(off);
- break;
- default:
- if (att[i]->attlen < sizeof(int32))
- elog(ERROR,
- "nocachegetattr2: attribute %d has len %d",
- i, att[i]->attlen);
- if (att[i]->attalign == 'd')
- off = DOUBLEALIGN(off);
- else
- off = LONGALIGN(off);
- break;
- }
+ off = att_align(off, att[i]->attlen, att[i]->attalign);
+
if (usecache)
att[i]->attcacheoff = off;
}
- switch (att[i]->attlen)
- {
- case sizeof(char):
- off++;
- break;
- case sizeof(short):
- off += sizeof(short);
- break;
- case sizeof(int32):
- off += sizeof(int32);
- break;
- case -1:
- Assert(!VARLENA_FIXED_SIZE(att[i]) ||
- att[i]->atttypmod == VARSIZE(tp + off));
- off += VARSIZE(tp + off);
- if (!VARLENA_FIXED_SIZE(att[i]))
- usecache = false;
- break;
- default:
- off += att[i]->attlen;
- break;
- }
- }
+ off = att_addlength(off, att[i]->attlen, tp + off);
- switch (att[attnum]->attlen)
- {
- case -1:
- off = (att[attnum]->attalign == 'd') ?
- DOUBLEALIGN(off) : INTALIGN(off);
- break;
- case sizeof(char):
- break;
- case sizeof(short):
- off = SHORTALIGN(off);
- break;
- case sizeof(int32):
- off = INTALIGN(off);
- break;
- default:
- if (att[attnum]->attlen < sizeof(int32))
- elog(ERROR, "nocachegetattr3: attribute %d has len %d",
- attnum, att[attnum]->attlen);
- if (att[attnum]->attalign == 'd')
- off = DOUBLEALIGN(off);
- else
- off = LONGALIGN(off);
- break;
+ if (att[i]->attlen == -1 && !VARLENA_FIXED_SIZE(att[i]))
+ usecache = false;
}
+ off = att_align(off, att[attnum]->attlen, att[attnum]->attalign);
+
return (Datum) fetchatt(&(att[attnum]), tp + off);
}
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.31 1998/09/01 03:20:42 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.32 1998/09/07 05:35:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
* word!
*/
- switch (att[j]->attlen)
- {
- case -1:
- off = (att[j]->attalign == 'd') ?
- DOUBLEALIGN(off) : INTALIGN(off);
- break;
- case sizeof(char):
- break;
- case sizeof(short):
- off = SHORTALIGN(off);
- break;
- case sizeof(int32):
- off = INTALIGN(off);
- break;
- default:
- if (att[j]->attlen > sizeof(int32))
- off = (att[j]->attalign == 'd') ?
- DOUBLEALIGN(off) : LONGALIGN(off);
- else
- elog(ERROR, "nocache_index_getattr: attribute %d has len %d",
- j, att[j]->attlen);
- break;
-
- }
+ off = att_align(off, att[j]->attlen, att[j]->attalign);
att[j]->attcacheoff = off;
off = att[i]->attcacheoff;
else
{
- switch (att[i]->attlen)
- {
- case -1:
- off = (att[i]->attalign == 'd') ?
- DOUBLEALIGN(off) : INTALIGN(off);
- break;
- case sizeof(char):
- break;
- case sizeof(short):
- off = SHORTALIGN(off);
- break;
- case sizeof(int32):
- off = INTALIGN(off);
- break;
- default:
- if (att[i]->attlen < sizeof(int32))
- elog(ERROR,
- "nocachegetiattr2: attribute %d has len %d",
- i, att[i]->attlen);
- if (att[i]->attalign == 'd')
- off = DOUBLEALIGN(off);
- else
- off = LONGALIGN(off);
- break;
- }
+ off = att_align(off, att[i]->attlen, att[i]->attalign);
+
if (usecache)
att[i]->attcacheoff = off;
}
}
}
- switch (att[attnum]->attlen)
- {
- case -1:
- off = (att[attnum]->attalign == 'd') ?
- DOUBLEALIGN(off) : INTALIGN(off);
- break;
- case sizeof(char):
- break;
- case sizeof(short):
- off = SHORTALIGN(off);
- break;
- case sizeof(int32):
- off = INTALIGN(off);
- break;
- default:
- if (att[attnum]->attlen < sizeof(int32))
- elog(ERROR, "nocache_index_getattr: attribute %d has len %d",
- attnum, att[attnum]->attlen);
- if (att[attnum]->attalign == 'd')
- off = DOUBLEALIGN(off);
- else
- off = LONGALIGN(off);
- break;
- }
+ off = att_align(off, att[attnum]->attlen, att[attnum]->attalign);
return (Datum) fetchatt(&att[attnum], tp + off);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.26 1998/09/02 23:05:21 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.27 1998/09/07 05:35:30 momjian Exp $
*
* INTERFACE ROUTINES
* index_open - open an index relation by relationId
*attNull = FALSE;
}
else
- {
- returnVal = heap_getattr(tuple, attrNums[attOff],
- hTupDesc, attNull);
- }
+ returnVal = heap_getattr(tuple, attrNums[attOff], hTupDesc, attNull);
+
return returnVal;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.32 1998/09/01 04:27:03 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.33 1998/09/07 05:35:33 momjian Exp $
*
* NOTES
* This file contains only the public interface routines.
btitem = _bt_formitem(itup);
res = _bt_doinsert(rel, btitem,
- IndexIsUnique(RelationGetRelid(rel)), heapRel);
+ IndexIsUnique(RelationGetRelid(rel)), heapRel);
pfree(btitem);
pfree(itup);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.22 1998/09/01 03:21:23 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.23 1998/09/07 05:35:34 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/* make a copy of the index tuple with room for the sequence number */
tuplen = IndexTupleSize(itup);
- nbytes_btitem = tuplen +
- (sizeof(BTItemData) - sizeof(IndexTupleData));
+ nbytes_btitem = tuplen + (sizeof(BTItemData) - sizeof(IndexTupleData));
btitem = (BTItem) palloc(nbytes_btitem);
memmove((char *) &(btitem->bti_itup), (char *) itup, tuplen);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.60 1998/09/01 04:27:31 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.61 1998/09/07 05:35:37 momjian Exp $
*
*
* INTERFACE ROUTINES
#define NTUPLES_PER_PAGE(natts) (BLCKSZ/((natts)*AVG_TUPLE_SIZE))
/* non-export function prototypes */
-static Oid
- RelationNameGetObjectId(char *relationName, Relation pg_class);
+static Oid RelationNameGetObjectId(char *relationName, Relation pg_class);
static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName);
static TupleDesc BuildFuncTupleDesc(FuncIndexInfo *funcInfo);
static TupleDesc ConstructTupleDescriptor(Oid heapoid, Relation heapRelation,
int numatts, AttrNumber *attNums);
static void ConstructIndexReldesc(Relation indexRelation, Oid amoid);
-static Oid UpdateRelationRelation(Relation indexRelation);
+static Oid UpdateRelationRelation(Relation indexRelation);
static void InitializeAttributeOids(Relation indexRelation,
int numatts,
Oid indexoid);
-static void
- AppendAttributeTuples(Relation indexRelation, int numatts);
+static void AppendAttributeTuples(Relation indexRelation, int numatts);
static void UpdateIndexRelation(Oid indexoid, Oid heapoid,
FuncIndexInfo *funcInfo, int natts,
AttrNumber *attNums, Oid *classOids, Node *predicate,
sizeof(*indexRelation->rd_rel),
(char *) indexRelation->rd_rel);
- /* ----------------
- * the new tuple must have the same oid as the relcache entry for the
- * index. sure would be embarassing to do this sort of thing in polite
- * company.
- * ----------------
+ /*
+ * The new tuple must have the same oid as the heap_create() we just
+ * did.
*/
tuple->t_oid = RelationGetRelid(indexRelation);
heap_insert(pg_class, tuple);
/* ----------------
* add index to catalogs
- * (append RELATION tuple)
+ * (INSERT pg_class tuple)
* ----------------
*/
indexoid = UpdateRelationRelation(indexRelation);
char *nullv,
FuncIndexInfoPtr fInfo)
{
- AttrNumber i;
- int offset;
+ AttrNumber attOff;
bool isNull;
/* ----------------
* ----------------
*/
- for (i = 1; i <= numberOfAttributes; i++)
+ for (attOff = 0; attOff < numberOfAttributes; attOff++)
{
- offset = AttrNumberGetAttrOffset(i);
-
- datum[offset] = PointerGetDatum(GetIndexValue(heapTuple,
+ datum[attOff] = PointerGetDatum(GetIndexValue(heapTuple,
heapDescriptor,
- offset,
+ attOff,
attributeNumber,
fInfo,
&isNull));
- nullv[offset] = (isNull) ? 'n' : ' ';
+ nullv[attOff] = (isNull) ? 'n' : ' ';
}
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.30 1998/09/02 23:05:23 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.31 1998/09/07 05:35:39 momjian Exp $
*
*-------------------------------------------------------------------------
*/
Assert(index_tup);
index_form = (Form_pg_index) GETSTRUCT(index_tup);
- /*
- * Compute the number of attributes we are indexing upon.
- */
- for (attnumP = index_form->indkey, natts = 0;
- *attnumP != InvalidAttrNumber;
- attnumP++, natts++)
- ;
-
if (index_form->indproc != InvalidOid)
{
- FIgetnArgs(&finfo) = natts;
+ int fatts;
+
+ /*
+ * Compute the number of attributes we are indexing upon.
+ */
+ for (attnumP = index_form->indkey, fatts = 0;
+ *attnumP != InvalidAttrNumber && fatts < INDEX_MAX_KEYS;
+ attnumP++, fatts++)
+ ;
+ FIgetnArgs(&finfo) = fatts;
natts = 1;
FIgetProcOid(&finfo) = index_form->indproc;
*(FIgetname(&finfo)) = '\0';
finfoP = &finfo;
}
else
+ {
+ natts = RelationGetDescr(idescs[i])->natts;
finfoP = (FuncIndexInfo *) NULL;
-
+ }
+
FormIndexDatum(natts,
(AttrNumber *) index_form->indkey,
heapTuple,
&heapTuple->t_ctid, heapRelation);
if (indexRes)
pfree(indexRes);
+
pfree(index_tup);
}
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.59 1998/09/01 04:27:47 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.60 1998/09/07 05:35:42 momjian Exp $
*
*-------------------------------------------------------------------------
*/
}
else if (nulls[i] != 'n')
{
- switch (attr[i]->attlen)
- {
- case -1:
- if (attr[i]->attalign == 'd')
- ptr = (char *) DOUBLEALIGN(ptr);
- else
- ptr = (char *) INTALIGN(ptr);
- values[i] = (Datum) ptr;
- ptr += *(uint32 *) ptr;
- break;
- case sizeof(char):
- values[i] = (Datum) ptr;
- ptr += attr[i]->attlen;
- break;
- case sizeof(short):
- ptr = (char *) SHORTALIGN(ptr);
- values[i] = (Datum) ptr;
- ptr += attr[i]->attlen;
- break;
- case sizeof(int32):
- ptr = (char *) INTALIGN(ptr);
- values[i] = (Datum) ptr;
- ptr += attr[i]->attlen;
- break;
- default:
- if (attr[i]->attalign == 'd')
- ptr = (char *) DOUBLEALIGN(ptr);
- else
- ptr = (char *) LONGALIGN(ptr);
- values[i] = (Datum) ptr;
- ptr += attr[i]->attlen;
- }
+ ptr = att_align(ptr, attr[i]->attlen, attr[i]->attalign);
+ values[i] = (Datum) ptr;
+ ptr = att_addlength(ptr, attr[i]->attlen, ptr);
}
}
}
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: tupmacs.h,v 1.5 1998/09/01 03:27:37 momjian Exp $
+ * $Id: tupmacs.h,v 1.6 1998/09/07 05:35:45 momjian Exp $
*
*-------------------------------------------------------------------------
*/
(char *) (T) \
)
+#define att_align(cur_offset, attlen, attalign) \
+( \
+ ((attlen) < sizeof(int32)) ? \
+ ( \
+ ((attlen) == -1) ? \
+ ( \
+ ((attalign) == 'd') ? DOUBLEALIGN(cur_offset) : \
+ INTALIGN(cur_offset) \
+ ) \
+ : \
+ ( \
+ ((attlen) == sizeof(char)) ? \
+ ( \
+ (cur_offset) \
+ ) \
+ : \
+ ( \
+ AssertMacro((attlen) == sizeof(short)), \
+ SHORTALIGN(cur_offset) \
+ ) \
+ ) \
+ ) \
+ : \
+ ( \
+ ((attlen) == sizeof(int32)) ? \
+ ( \
+ INTALIGN(cur_offset) \
+ ) \
+ : \
+ ( \
+ AssertMacro((attlen) > sizeof(int32)), \
+ ((attalign) == 'd') ? DOUBLEALIGN(cur_offset) : \
+ LONGALIGN(cur_offset) \
+ ) \
+ ) \
+)
+
+#define att_addlength(cur_offset, attlen, attval) \
+( \
+ ((attlen) != -1) ? \
+ ( \
+ (cur_offset) + (attlen) \
+ ) \
+ : \
+ ( \
+ (cur_offset) + VARSIZE(DatumGetPointer(attval)) \
+ ) \
+)
+
#endif
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: memutils.h,v 1.17 1998/09/01 04:39:20 momjian Exp $
+ * $Id: memutils.h,v 1.18 1998/09/07 05:35:48 momjian Exp $
*
* NOTES
* some of the information in this file will be moved to
GCC (at least v2.5.8 and up) has an __alignof__ keyword.
However, we cannot use it here since on some architectures it reports
just a _recommended_ alignment instead of the actual alignment used in
- padding structures (or at least, this is how I understand gcc's
-s...)
+ padding structures (or at least, this is how I understand gcc).
So define a macro that gives us the _actual_ alignment inside a struct.
{{note: assumes that alignment size is always a power of 2.}}
*/