Commit 7540eda8 authored by Vadim B. Mikheev's avatar Vadim B. Mikheev

Someone forgot about aligning in fastgetiattr()...

parent 9392a191
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.13 1997/03/26 02:24:38 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.14 1997/06/12 15:41:52 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -135,6 +135,7 @@ fastgetiattr(IndexTuple tup, ...@@ -135,6 +135,7 @@ fastgetiattr(IndexTuple tup,
register char *bp = NULL; /* ptr to att in tuple */ register char *bp = NULL; /* ptr to att in tuple */
int slow; /* do we have to walk nulls? */ int slow; /* do we have to walk nulls? */
register int data_off; /* tuple data offset */ register int data_off; /* tuple data offset */
AttributeTupleForm *att = tupleDesc->attrs;
/* ---------------- /* ----------------
* sanity checks * sanity checks
...@@ -162,14 +163,14 @@ fastgetiattr(IndexTuple tup, ...@@ -162,14 +163,14 @@ fastgetiattr(IndexTuple tup,
/* first attribute is always at position zero */ /* first attribute is always at position zero */
if (attnum == 1) { if (attnum == 1) {
return(fetchatt(&(tupleDesc->attrs[0]), (char *) tup + data_off)); return(fetchatt(&(att[0]), (char *) tup + data_off));
} }
attnum--; attnum--;
if (tupleDesc->attrs[attnum]->attcacheoff > 0) { if (att[attnum]->attcacheoff > 0) {
return(fetchatt(&(tupleDesc->attrs[attnum]), return(fetchatt(&(att[attnum]),
(char *) tup + data_off + (char *) tup + data_off +
tupleDesc->attrs[attnum]->attcacheoff)); att[attnum]->attcacheoff));
} }
tp = (char *) tup + data_off; tp = (char *) tup + data_off;
...@@ -226,14 +227,14 @@ fastgetiattr(IndexTuple tup, ...@@ -226,14 +227,14 @@ fastgetiattr(IndexTuple tup,
/* now check for any non-fixed length attrs before our attribute */ /* now check for any non-fixed length attrs before our attribute */
if (!slow) { if (!slow) {
if (tupleDesc->attrs[attnum]->attcacheoff > 0) { if (att[attnum]->attcacheoff > 0) {
return(fetchatt(&(tupleDesc->attrs[attnum]), return(fetchatt(&(att[attnum]),
tp + tupleDesc->attrs[attnum]->attcacheoff)); tp + att[attnum]->attcacheoff));
}else if (!IndexTupleAllFixed(tup)) { }else if (!IndexTupleAllFixed(tup)) {
register int j = 0; register int j = 0;
for (j = 0; j < attnum && !slow; j++) for (j = 0; j < attnum && !slow; j++)
if (tupleDesc->attrs[j]->attlen < 1) slow = 1; if (att[j]->attlen < 1) slow = 1;
} }
} }
...@@ -251,12 +252,12 @@ fastgetiattr(IndexTuple tup, ...@@ -251,12 +252,12 @@ fastgetiattr(IndexTuple tup,
* need to set cache for some atts * need to set cache for some atts
*/ */
tupleDesc->attrs[0]->attcacheoff = 0; att[0]->attcacheoff = 0;
while (tupleDesc->attrs[j]->attcacheoff > 0) j++; while (att[j]->attcacheoff > 0) j++;
off = tupleDesc->attrs[j-1]->attcacheoff + off = att[j-1]->attcacheoff +
tupleDesc->attrs[j-1]->attlen; att[j-1]->attlen;
for (; j < attnum + 1; j++) { for (; j < attnum + 1; j++) {
/* /*
...@@ -264,10 +265,10 @@ fastgetiattr(IndexTuple tup, ...@@ -264,10 +265,10 @@ fastgetiattr(IndexTuple tup,
* word! * word!
*/ */
switch(tupleDesc->attrs[j]->attlen) switch(att[j]->attlen)
{ {
case -1: case -1:
off = (tupleDesc->attrs[j]->attalign=='d')? off = (att[j]->attalign=='d')?
DOUBLEALIGN(off):INTALIGN(off); DOUBLEALIGN(off):INTALIGN(off);
break; break;
case sizeof(char): case sizeof(char):
...@@ -279,22 +280,22 @@ fastgetiattr(IndexTuple tup, ...@@ -279,22 +280,22 @@ fastgetiattr(IndexTuple tup,
off = INTALIGN(off); off = INTALIGN(off);
break; break;
default: default:
if (tupleDesc->attrs[j]->attlen > sizeof(int32)) if (att[j]->attlen > sizeof(int32))
off = (tupleDesc->attrs[j]->attalign=='d')? off = (att[j]->attalign=='d')?
DOUBLEALIGN(off) : LONGALIGN(off); DOUBLEALIGN(off) : LONGALIGN(off);
else else
elog(WARN, "fastgetiattr: attribute %d has len %d", elog(WARN, "fastgetiattr: attribute %d has len %d",
j, tupleDesc->attrs[j]->attlen); j, att[j]->attlen);
break; break;
} }
tupleDesc->attrs[j]->attcacheoff = off; att[j]->attcacheoff = off;
off += tupleDesc->attrs[j]->attlen; off += att[j]->attlen;
} }
return(fetchatt( &(tupleDesc->attrs[attnum]), return(fetchatt( &(att[attnum]),
tp + tupleDesc->attrs[attnum]->attcacheoff)); tp + att[attnum]->attcacheoff));
}else { }else {
register bool usecache = true; register bool usecache = true;
register int off = 0; register int off = 0;
...@@ -312,16 +313,16 @@ fastgetiattr(IndexTuple tup, ...@@ -312,16 +313,16 @@ fastgetiattr(IndexTuple tup,
} }
} }
if (usecache && tupleDesc->attrs[i]->attcacheoff > 0) { if (usecache && att[i]->attcacheoff > 0) {
off = tupleDesc->attrs[i]->attcacheoff; off = att[i]->attcacheoff;
if (tupleDesc->attrs[i]->attlen == -1) if (att[i]->attlen == -1)
usecache = false; usecache = false;
else else
continue; continue;
} }
if (usecache) tupleDesc->attrs[i]->attcacheoff = off; if (usecache) att[i]->attcacheoff = off;
switch(tupleDesc->attrs[i]->attlen) switch(att[i]->attlen)
{ {
case sizeof(char): case sizeof(char):
off++; off++;
...@@ -334,24 +335,52 @@ fastgetiattr(IndexTuple tup, ...@@ -334,24 +335,52 @@ fastgetiattr(IndexTuple tup,
break; break;
case -1: case -1:
usecache = false; usecache = false;
off = (tupleDesc->attrs[i]->attalign=='d')? off = (att[i]->attalign=='d')?
DOUBLEALIGN(off):INTALIGN(off); DOUBLEALIGN(off):INTALIGN(off);
off += VARSIZE(tp + off); off += VARSIZE(tp + off);
break; break;
default: default:
if (tupleDesc->attrs[i]->attlen > sizeof(int32)) if (att[i]->attlen > sizeof(int32))
off = (tupleDesc->attrs[i]->attalign=='d') ? off = (att[i]->attalign=='d') ?
DOUBLEALIGN(off) + tupleDesc->attrs[i]->attlen : DOUBLEALIGN(off) + att[i]->attlen :
LONGALIGN(off) + tupleDesc->attrs[i]->attlen; LONGALIGN(off) + att[i]->attlen;
else else
elog(WARN, "fastgetiattr2: attribute %d has len %d", elog(WARN, "fastgetiattr2: attribute %d has len %d",
i, tupleDesc->attrs[i]->attlen); i, att[i]->attlen);
break; break;
} }
} }
/*
* I don't know why this code was missed here!
* I've got it from heaptuple.c:fastgetattr().
* - vadim 06/12/97
*/
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(WARN, "fastgetattr3: attribute %d has len %d",
attnum, att[attnum]->attlen);
if (att[attnum]->attalign == 'd')
off = DOUBLEALIGN(off);
else
off = LONGALIGN(off);
break;
}
return(fetchatt(&tupleDesc->attrs[attnum], tp + off)); return(fetchatt(&att[attnum], tp + off));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment