mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Alignment cleanup so no more massive switch statements for alignment,
just two macros.
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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
|
* NOTES
|
||||||
* The old interface functions have been converted to macros
|
* The old interface functions have been converted to macros
|
||||||
@ -68,44 +68,8 @@ ComputeDataSize(TupleDesc tupleDesc,
|
|||||||
if (nulls[i] != ' ')
|
if (nulls[i] != ' ')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
switch (att[i]->attlen)
|
data_length = att_align(data_length, att[i]->attlen, att[i]->attalign);
|
||||||
{
|
data_length = att_addlength(data_length, att[i]->attlen, value[i]);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data_length;
|
return data_length;
|
||||||
@ -160,57 +124,34 @@ DataFill(char *data,
|
|||||||
*bitP |= bitmask;
|
*bitP |= bitmask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data = (char *)att_align((long)data, att[i]->attlen, att[i]->attalign);
|
||||||
switch (att[i]->attlen)
|
switch (att[i]->attlen)
|
||||||
{
|
{
|
||||||
case -1:
|
case -1:
|
||||||
*infomask |= HEAP_HASVARLENA;
|
*infomask |= HEAP_HASVARLENA;
|
||||||
if (att[i]->attalign == 'd')
|
|
||||||
data = (char *) DOUBLEALIGN(data);
|
|
||||||
else
|
|
||||||
data = (char *) INTALIGN(data);
|
|
||||||
data_length = VARSIZE(DatumGetPointer(value[i]));
|
data_length = VARSIZE(DatumGetPointer(value[i]));
|
||||||
memmove(data, DatumGetPointer(value[i]), data_length);
|
memmove(data, DatumGetPointer(value[i]), data_length);
|
||||||
data += data_length;
|
|
||||||
break;
|
break;
|
||||||
case sizeof(char):
|
case sizeof(char):
|
||||||
*data = att[i]->attbyval ?
|
*data = att[i]->attbyval ?
|
||||||
DatumGetChar(value[i]) : *((char *) value[i]);
|
DatumGetChar(value[i]) : *((char *) value[i]);
|
||||||
data += sizeof(char);
|
|
||||||
break;
|
break;
|
||||||
case sizeof(int16):
|
case sizeof(int16):
|
||||||
data = (char *) SHORTALIGN(data);
|
|
||||||
*(short *) data = (att[i]->attbyval ?
|
*(short *) data = (att[i]->attbyval ?
|
||||||
DatumGetInt16(value[i]) :
|
DatumGetInt16(value[i]) :
|
||||||
*((short *) value[i]));
|
*((short *) value[i]));
|
||||||
data += sizeof(short);
|
|
||||||
break;
|
break;
|
||||||
case sizeof(int32):
|
case sizeof(int32):
|
||||||
data = (char *) INTALIGN(data);
|
|
||||||
*(int32 *) data = (att[i]->attbyval ?
|
*(int32 *) data = (att[i]->attbyval ?
|
||||||
DatumGetInt32(value[i]) :
|
DatumGetInt32(value[i]) :
|
||||||
*((int32 *) value[i]));
|
*((int32 *) value[i]));
|
||||||
data += sizeof(int32);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (att[i]->attlen < sizeof(int32))
|
memmove(data, DatumGetPointer(value[i]),
|
||||||
elog(ERROR, "DataFill: attribute %d has len %d",
|
att[i]->attlen);
|
||||||
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;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
data = (char *)att_addlength((long)data, att[i]->attlen, value[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,53 +498,11 @@ nocachegetattr(HeapTuple tup,
|
|||||||
* Fix me when going to a machine with more than a four-byte
|
* Fix me when going to a machine with more than a four-byte
|
||||||
* word!
|
* word!
|
||||||
*/
|
*/
|
||||||
|
off = att_align(off, att[j]->attlen, att[j]->attalign);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
att[j]->attcacheoff = off;
|
att[j]->attcacheoff = off;
|
||||||
|
|
||||||
switch (att[j]->attlen)
|
off = att_addlength(off, att[j]->attlen, tp + off);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (Datum) fetchatt(&(att[attnum]), tp + att[attnum]->attcacheoff);
|
return (Datum) fetchatt(&(att[attnum]), tp + att[attnum]->attcacheoff);
|
||||||
@ -640,83 +539,19 @@ nocachegetattr(HeapTuple tup,
|
|||||||
off = att[i]->attcacheoff;
|
off = att[i]->attcacheoff;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch (att[i]->attlen)
|
off = att_align(off, att[i]->attlen, att[i]->attalign);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
if (usecache)
|
if (usecache)
|
||||||
att[i]->attcacheoff = off;
|
att[i]->attcacheoff = off;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (att[i]->attlen)
|
off = att_addlength(off, att[i]->attlen, tp + off);
|
||||||
{
|
|
||||||
case sizeof(char):
|
if (att[i]->attlen == -1 && !VARLENA_FIXED_SIZE(att[i]))
|
||||||
off++;
|
usecache = false;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (att[attnum]->attlen)
|
off = att_align(off, att[attnum]->attlen, att[attnum]->attalign);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (Datum) fetchatt(&(att[attnum]), tp + off);
|
return (Datum) fetchatt(&(att[attnum]), tp + off);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -300,30 +300,7 @@ nocache_index_getattr(IndexTuple tup,
|
|||||||
* word!
|
* word!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
switch (att[j]->attlen)
|
off = att_align(off, att[j]->attlen, att[j]->attalign);
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
att[j]->attcacheoff = off;
|
att[j]->attcacheoff = off;
|
||||||
|
|
||||||
@ -365,31 +342,8 @@ nocache_index_getattr(IndexTuple tup,
|
|||||||
off = att[i]->attcacheoff;
|
off = att[i]->attcacheoff;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch (att[i]->attlen)
|
off = att_align(off, att[i]->attlen, att[i]->attalign);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
if (usecache)
|
if (usecache)
|
||||||
att[i]->attcacheoff = off;
|
att[i]->attcacheoff = off;
|
||||||
}
|
}
|
||||||
@ -418,30 +372,7 @@ nocache_index_getattr(IndexTuple tup,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (att[attnum]->attlen)
|
off = att_align(off, att[attnum]->attlen, att[attnum]->attalign);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (Datum) fetchatt(&att[attnum], tp + off);
|
return (Datum) fetchatt(&att[attnum], tp + off);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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
|
* INTERFACE ROUTINES
|
||||||
* index_open - open an index relation by relationId
|
* index_open - open an index relation by relationId
|
||||||
@ -384,9 +384,7 @@ GetIndexValue(HeapTuple tuple,
|
|||||||
*attNull = FALSE;
|
*attNull = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
returnVal = heap_getattr(tuple, attrNums[attOff], hTupDesc, attNull);
|
||||||
returnVal = heap_getattr(tuple, attrNums[attOff],
|
|
||||||
hTupDesc, attNull);
|
|
||||||
}
|
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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
|
* NOTES
|
||||||
* This file contains only the public interface routines.
|
* This file contains only the public interface routines.
|
||||||
@ -367,7 +367,7 @@ btinsert(Relation rel, Datum *datum, char *nulls, ItemPointer ht_ctid, Relation
|
|||||||
btitem = _bt_formitem(itup);
|
btitem = _bt_formitem(itup);
|
||||||
|
|
||||||
res = _bt_doinsert(rel, btitem,
|
res = _bt_doinsert(rel, btitem,
|
||||||
IndexIsUnique(RelationGetRelid(rel)), heapRel);
|
IndexIsUnique(RelationGetRelid(rel)), heapRel);
|
||||||
|
|
||||||
pfree(btitem);
|
pfree(btitem);
|
||||||
pfree(itup);
|
pfree(itup);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -297,8 +297,7 @@ _bt_formitem(IndexTuple itup)
|
|||||||
|
|
||||||
/* make a copy of the index tuple with room for the sequence number */
|
/* make a copy of the index tuple with room for the sequence number */
|
||||||
tuplen = IndexTupleSize(itup);
|
tuplen = IndexTupleSize(itup);
|
||||||
nbytes_btitem = tuplen +
|
nbytes_btitem = tuplen + (sizeof(BTItemData) - sizeof(IndexTupleData));
|
||||||
(sizeof(BTItemData) - sizeof(IndexTupleData));
|
|
||||||
|
|
||||||
btitem = (BTItem) palloc(nbytes_btitem);
|
btitem = (BTItem) palloc(nbytes_btitem);
|
||||||
memmove((char *) &(btitem->bti_itup), (char *) itup, tuplen);
|
memmove((char *) &(btitem->bti_itup), (char *) itup, tuplen);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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
|
* INTERFACE ROUTINES
|
||||||
@ -64,8 +64,7 @@
|
|||||||
#define NTUPLES_PER_PAGE(natts) (BLCKSZ/((natts)*AVG_TUPLE_SIZE))
|
#define NTUPLES_PER_PAGE(natts) (BLCKSZ/((natts)*AVG_TUPLE_SIZE))
|
||||||
|
|
||||||
/* non-export function prototypes */
|
/* non-export function prototypes */
|
||||||
static Oid
|
static Oid RelationNameGetObjectId(char *relationName, Relation pg_class);
|
||||||
RelationNameGetObjectId(char *relationName, Relation pg_class);
|
|
||||||
static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName);
|
static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName);
|
||||||
static TupleDesc BuildFuncTupleDesc(FuncIndexInfo *funcInfo);
|
static TupleDesc BuildFuncTupleDesc(FuncIndexInfo *funcInfo);
|
||||||
static TupleDesc ConstructTupleDescriptor(Oid heapoid, Relation heapRelation,
|
static TupleDesc ConstructTupleDescriptor(Oid heapoid, Relation heapRelation,
|
||||||
@ -73,12 +72,11 @@ static TupleDesc ConstructTupleDescriptor(Oid heapoid, Relation heapRelation,
|
|||||||
int numatts, AttrNumber *attNums);
|
int numatts, AttrNumber *attNums);
|
||||||
|
|
||||||
static void ConstructIndexReldesc(Relation indexRelation, Oid amoid);
|
static void ConstructIndexReldesc(Relation indexRelation, Oid amoid);
|
||||||
static Oid UpdateRelationRelation(Relation indexRelation);
|
static Oid UpdateRelationRelation(Relation indexRelation);
|
||||||
static void InitializeAttributeOids(Relation indexRelation,
|
static void InitializeAttributeOids(Relation indexRelation,
|
||||||
int numatts,
|
int numatts,
|
||||||
Oid indexoid);
|
Oid indexoid);
|
||||||
static void
|
static void AppendAttributeTuples(Relation indexRelation, int numatts);
|
||||||
AppendAttributeTuples(Relation indexRelation, int numatts);
|
|
||||||
static void UpdateIndexRelation(Oid indexoid, Oid heapoid,
|
static void UpdateIndexRelation(Oid indexoid, Oid heapoid,
|
||||||
FuncIndexInfo *funcInfo, int natts,
|
FuncIndexInfo *funcInfo, int natts,
|
||||||
AttrNumber *attNums, Oid *classOids, Node *predicate,
|
AttrNumber *attNums, Oid *classOids, Node *predicate,
|
||||||
@ -552,11 +550,9 @@ UpdateRelationRelation(Relation indexRelation)
|
|||||||
sizeof(*indexRelation->rd_rel),
|
sizeof(*indexRelation->rd_rel),
|
||||||
(char *) indexRelation->rd_rel);
|
(char *) indexRelation->rd_rel);
|
||||||
|
|
||||||
/* ----------------
|
/*
|
||||||
* the new tuple must have the same oid as the relcache entry for the
|
* The new tuple must have the same oid as the heap_create() we just
|
||||||
* index. sure would be embarassing to do this sort of thing in polite
|
* did.
|
||||||
* company.
|
|
||||||
* ----------------
|
|
||||||
*/
|
*/
|
||||||
tuple->t_oid = RelationGetRelid(indexRelation);
|
tuple->t_oid = RelationGetRelid(indexRelation);
|
||||||
heap_insert(pg_class, tuple);
|
heap_insert(pg_class, tuple);
|
||||||
@ -1078,7 +1074,7 @@ index_create(char *heapRelationName,
|
|||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
* add index to catalogs
|
* add index to catalogs
|
||||||
* (append RELATION tuple)
|
* (INSERT pg_class tuple)
|
||||||
* ----------------
|
* ----------------
|
||||||
*/
|
*/
|
||||||
indexoid = UpdateRelationRelation(indexRelation);
|
indexoid = UpdateRelationRelation(indexRelation);
|
||||||
@ -1264,8 +1260,7 @@ FormIndexDatum(int numberOfAttributes,
|
|||||||
char *nullv,
|
char *nullv,
|
||||||
FuncIndexInfoPtr fInfo)
|
FuncIndexInfoPtr fInfo)
|
||||||
{
|
{
|
||||||
AttrNumber i;
|
AttrNumber attOff;
|
||||||
int offset;
|
|
||||||
bool isNull;
|
bool isNull;
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
@ -1275,18 +1270,16 @@ FormIndexDatum(int numberOfAttributes,
|
|||||||
* ----------------
|
* ----------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (i = 1; i <= numberOfAttributes; i++)
|
for (attOff = 0; attOff < numberOfAttributes; attOff++)
|
||||||
{
|
{
|
||||||
offset = AttrNumberGetAttrOffset(i);
|
datum[attOff] = PointerGetDatum(GetIndexValue(heapTuple,
|
||||||
|
|
||||||
datum[offset] = PointerGetDatum(GetIndexValue(heapTuple,
|
|
||||||
heapDescriptor,
|
heapDescriptor,
|
||||||
offset,
|
attOff,
|
||||||
attributeNumber,
|
attributeNumber,
|
||||||
fInfo,
|
fInfo,
|
||||||
&isNull));
|
&isNull));
|
||||||
|
|
||||||
nullv[offset] = (isNull) ? 'n' : ' ';
|
nullv[attOff] = (isNull) ? 'n' : ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -129,25 +129,29 @@ CatalogIndexInsert(Relation *idescs,
|
|||||||
Assert(index_tup);
|
Assert(index_tup);
|
||||||
index_form = (Form_pg_index) GETSTRUCT(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)
|
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;
|
natts = 1;
|
||||||
FIgetProcOid(&finfo) = index_form->indproc;
|
FIgetProcOid(&finfo) = index_form->indproc;
|
||||||
*(FIgetname(&finfo)) = '\0';
|
*(FIgetname(&finfo)) = '\0';
|
||||||
finfoP = &finfo;
|
finfoP = &finfo;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
natts = RelationGetDescr(idescs[i])->natts;
|
||||||
finfoP = (FuncIndexInfo *) NULL;
|
finfoP = (FuncIndexInfo *) NULL;
|
||||||
|
}
|
||||||
|
|
||||||
FormIndexDatum(natts,
|
FormIndexDatum(natts,
|
||||||
(AttrNumber *) index_form->indkey,
|
(AttrNumber *) index_form->indkey,
|
||||||
heapTuple,
|
heapTuple,
|
||||||
@ -160,6 +164,7 @@ CatalogIndexInsert(Relation *idescs,
|
|||||||
&heapTuple->t_ctid, heapRelation);
|
&heapTuple->t_ctid, heapRelation);
|
||||||
if (indexRes)
|
if (indexRes)
|
||||||
pfree(indexRes);
|
pfree(indexRes);
|
||||||
|
|
||||||
pfree(index_tup);
|
pfree(index_tup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -661,38 +661,9 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
|||||||
}
|
}
|
||||||
else if (nulls[i] != 'n')
|
else if (nulls[i] != 'n')
|
||||||
{
|
{
|
||||||
switch (attr[i]->attlen)
|
ptr = att_align(ptr, attr[i]->attlen, attr[i]->attalign);
|
||||||
{
|
values[i] = (Datum) ptr;
|
||||||
case -1:
|
ptr = att_addlength(ptr, attr[i]->attlen, ptr);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -62,4 +62,53 @@
|
|||||||
(char *) (T) \
|
(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
|
#endif
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* 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
|
* NOTES
|
||||||
* some of the information in this file will be moved to
|
* some of the information in this file will be moved to
|
||||||
@ -37,8 +37,7 @@ tending
|
|||||||
GCC (at least v2.5.8 and up) has an __alignof__ keyword.
|
GCC (at least v2.5.8 and up) has an __alignof__ keyword.
|
||||||
However, we cannot use it here since on some architectures it reports
|
However, we cannot use it here since on some architectures it reports
|
||||||
just a _recommended_ alignment instead of the actual alignment used in
|
just a _recommended_ alignment instead of the actual alignment used in
|
||||||
padding structures (or at least, this is how I understand gcc's
|
padding structures (or at least, this is how I understand gcc).
|
||||||
s...)
|
|
||||||
So define a macro that gives us the _actual_ alignment inside a struct.
|
So define a macro that gives us the _actual_ alignment inside a struct.
|
||||||
{{note: assumes that alignment size is always a power of 2.}}
|
{{note: assumes that alignment size is always a power of 2.}}
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user