diff options
Diffstat (limited to 'src/backend/access/common')
-rw-r--r-- | src/backend/access/common/heaptuple.c | 43 | ||||
-rw-r--r-- | src/backend/access/common/indextuple.c | 36 | ||||
-rw-r--r-- | src/backend/access/common/printtup.c | 10 |
3 files changed, 47 insertions, 42 deletions
diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c index 19e02dee67e..4aa66879feb 100644 --- a/src/backend/access/common/heaptuple.c +++ b/src/backend/access/common/heaptuple.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.78 2002/07/20 05:16:56 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.79 2002/08/24 15:00:45 tgl Exp $ * * NOTES * The old interface functions have been converted to macros @@ -48,7 +48,7 @@ ComputeDataSize(TupleDesc tupleDesc, if (nulls[i] != ' ') continue; - data_length = att_align(data_length, att[i]->attlen, att[i]->attalign); + data_length = att_align(data_length, att[i]->attalign); data_length = att_addlength(data_length, att[i]->attlen, value[i]); } @@ -69,7 +69,7 @@ DataFill(char *data, { bits8 *bitP = 0; int bitmask = 0; - uint32 data_length; + Size data_length; int i; int numberOfAttributes = tupleDesc->natts; Form_pg_attribute *att = tupleDesc->attrs; @@ -105,12 +105,13 @@ DataFill(char *data, } /* XXX we are aligning the pointer itself, not the offset */ - data = (char *) att_align((long) data, att[i]->attlen, att[i]->attalign); + data = (char *) att_align((long) data, att[i]->attalign); if (att[i]->attbyval) { /* pass-by-value */ store_att_byval(data, value[i], att[i]->attlen); + data_length = att[i]->attlen; } else if (att[i]->attlen == -1) { @@ -123,15 +124,22 @@ DataFill(char *data, data_length = VARATT_SIZE(DatumGetPointer(value[i])); memcpy(data, DatumGetPointer(value[i]), data_length); } + else if (att[i]->attlen == -2) + { + /* cstring */ + *infomask |= HEAP_HASVARLENA; + data_length = strlen(DatumGetCString(value[i])) + 1; + memcpy(data, DatumGetPointer(value[i]), data_length); + } else { /* fixed-length pass-by-reference */ - Assert(att[i]->attlen >= 0); - memcpy(data, DatumGetPointer(value[i]), - (size_t) (att[i]->attlen)); + Assert(att[i]->attlen > 0); + data_length = att[i]->attlen; + memcpy(data, DatumGetPointer(value[i]), data_length); } - data = (char *) att_addlength((long) data, att[i]->attlen, value[i]); + data += data_length; } } @@ -235,7 +243,8 @@ nocachegetattr(HeapTuple tuple, if (att[attnum]->attcacheoff != -1) { return fetchatt(att[attnum], - (char *) tup + tup->t_hoff + att[attnum]->attcacheoff); + (char *) tup + tup->t_hoff + + att[attnum]->attcacheoff); } #endif } @@ -243,9 +252,7 @@ nocachegetattr(HeapTuple tuple, { /* * there's a null somewhere in the tuple - */ - - /* + * * check to see if desired att is null */ @@ -346,11 +353,7 @@ nocachegetattr(HeapTuple tuple, (HeapTupleNoNulls(tuple) || !att_isnull(j, bp)) && (HeapTupleAllFixed(tuple) || att[j]->attlen > 0)); j++) { - /* - * Fix me when going to a machine with more than a four-byte - * word! - */ - off = att_align(off, att[j]->attlen, att[j]->attalign); + off = att_align(off, att[j]->attalign); att[j]->attcacheoff = off; @@ -391,7 +394,7 @@ nocachegetattr(HeapTuple tuple, off = att[i]->attcacheoff; else { - off = att_align(off, att[i]->attlen, att[i]->attalign); + off = att_align(off, att[i]->attalign); if (usecache) att[i]->attcacheoff = off; @@ -399,11 +402,11 @@ nocachegetattr(HeapTuple tuple, off = att_addlength(off, att[i]->attlen, tp + off); - if (usecache && att[i]->attlen == -1) + if (usecache && att[i]->attlen <= 0) usecache = false; } - off = att_align(off, att[attnum]->attlen, att[attnum]->attalign); + off = att_align(off, att[attnum]->attalign); return fetchatt(att[attnum], tp + off); } diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c index d47c2e2d2f9..a0d2dc8ef7e 100644 --- a/src/backend/access/common/indextuple.c +++ b/src/backend/access/common/indextuple.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.57 2002/06/20 20:29:24 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.58 2002/08/24 15:00:45 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -64,7 +64,7 @@ index_formtuple(TupleDesc tupleDescriptor, untoasted_free[i] = false; /* Do nothing if value is NULL or not of varlena type */ - if (null[i] != ' ' || att->attlen >= 0) + if (null[i] != ' ' || att->attlen != -1) continue; /* @@ -243,9 +243,10 @@ nocache_index_getattr(IndexTuple tup, #endif } else - { /* there's a null somewhere in the tuple */ - + { /* + * there's a null somewhere in the tuple + * * check to see if desired att is null */ @@ -291,8 +292,9 @@ nocache_index_getattr(IndexTuple tup, tp = (char *) tup + data_off; - /* 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 (att[attnum]->attcacheoff != -1) @@ -305,11 +307,13 @@ nocache_index_getattr(IndexTuple tup, int j; for (j = 0; j < attnum; j++) + { if (att[j]->attlen <= 0) { slow = true; break; } + } } } @@ -337,12 +341,7 @@ nocache_index_getattr(IndexTuple tup, for (; j <= attnum; j++) { - /* - * Fix me when going to a machine with more than a four-byte - * word! - */ - - off = att_align(off, att[j]->attlen, att[j]->attalign); + off = att_align(off, att[j]->attalign); att[j]->attcacheoff = off; @@ -377,22 +376,19 @@ nocache_index_getattr(IndexTuple tup, off = att[i]->attcacheoff; else { - off = att_align(off, att[i]->attlen, att[i]->attalign); + off = att_align(off, att[i]->attalign); if (usecache) att[i]->attcacheoff = off; } - if (att[i]->attlen == -1) - { - off += VARSIZE(tp + off); + off = att_addlength(off, att[i]->attlen, tp + off); + + if (usecache && att[i]->attlen <= 0) usecache = false; - } - else - off += att[i]->attlen; } - off = att_align(off, att[attnum]->attlen, att[attnum]->attalign); + off = att_align(off, att[attnum]->attalign); return fetchatt(att[attnum], tp + off); } diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c index 6fbce87be7c..db4187dba44 100644 --- a/src/backend/access/common/printtup.c +++ b/src/backend/access/common/printtup.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.63 2002/08/22 00:01:41 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.64 2002/08/24 15:00:46 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -457,9 +457,15 @@ printtup_internal(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self) } else { - /* fixed size */ + /* fixed size or cstring */ attr = origattr; len = typeinfo->attrs[i]->attlen; + if (len <= 0) + { + /* it's a cstring */ + Assert(len == -2 && !typeinfo->attrs[i]->attbyval); + len = strlen(DatumGetCString(attr)) + 1; + } pq_sendint(&buf, len, sizeof(int32)); if (typeinfo->attrs[i]->attbyval) { |