80 #define ATT_IS_PACKABLE(att) \
81 ((att)->attlen == -1 && (att)->attstorage != TYPSTORAGE_PLAIN)
83 #define VARLENA_ATT_IS_PACKABLE(att) \
84 ((att)->attstorage != TYPSTORAGE_PLAIN)
113 if (entry1->
len != entry2->
len)
114 return entry1->
len > entry2->
len ? 1 : -1;
152 Assert(attnum <= tupleDesc->natts);
157 if (att->atthasmissing)
184 Assert(att->attlen > 0 || att->attlen == -1);
186 key.len = att->attlen;
219 Size data_length = 0;
221 int numberOfAttributes = tupleDesc->
natts;
223 for (
i = 0;
i < numberOfAttributes;
i++)
243 else if (atti->attlen == -1 &&
315 data_length = att->attlen;
317 else if (att->attlen == -1)
343 memcpy(
data,
val, data_length);
350 memcpy(
data,
val, data_length);
366 memcpy(
data,
val, data_length);
369 else if (att->attlen == -2)
373 Assert(att->attalign == TYPALIGN_CHAR);
382 data_length = att->attlen;
408 int numberOfAttributes = tupleDesc->
natts;
410 #ifdef USE_ASSERT_CHECKING
428 for (
i = 0;
i < numberOfAttributes;
i++)
438 isnull ? isnull[
i] :
true);
461 Assert(!tupleDesc || attnum <= tupleDesc->natts);
548 int finalbit =
attnum & 0x07;
551 if ((~bp[
byte]) & ((1 << finalbit) - 1))
558 for (
i = 0;
i < byte;
i++)
569 tp = (
char *) td + td->
t_hoff;
580 if (att->attcacheoff >= 0)
581 return fetchatt(att, tp + att->attcacheoff);
605 int natts = tupleDesc->
natts;
626 for (;
j < natts;
j++)
630 if (att->attlen <= 0)
635 att->attcacheoff = off;
646 bool usecache =
true;
671 if (usecache && att->attcacheoff >= 0)
672 off = att->attcacheoff;
673 else if (att->attlen == -1)
683 att->attcacheoff = off;
697 att->attcacheoff = off;
705 if (usecache && att->attlen <= 0)
840 int natts = tupleDesc->
natts;
847 bits8 *nullBits = NULL;
852 Assert((targetHeapTuple && !targetMinimalTuple)
853 || (!targetHeapTuple && targetMinimalTuple));
855 Assert(sourceNatts < natts);
857 sourceNullLen = (hasNulls ?
BITMAPLEN(sourceNatts) : 0);
859 targetDataLen = sourceDataLen;
875 for (firstmissingnum = sourceNatts;
876 firstmissingnum < natts;
879 if (attrmiss[firstmissingnum].am_present)
889 for (
attnum = firstmissingnum;
893 if (attrmiss[
attnum].am_present)
927 len += targetNullLen;
940 len += targetDataLen;
943 (*targetHeapTuple)->t_data
946 (*targetHeapTuple)->t_len =
len;
947 (*targetHeapTuple)->t_tableOid = sourceTuple->
t_tableOid;
948 (*targetHeapTuple)->t_self = sourceTuple->
t_self;
951 targetTHeader->
t_hoff = hoff;
958 if (targetNullLen > 0)
959 nullBits = (
bits8 *) ((
char *) (*targetHeapTuple)->t_data
961 targetData = (
char *) (*targetHeapTuple)->t_data + hoff;
968 len += targetDataLen;
971 (*targetMinimalTuple)->t_len =
len;
973 (*targetMinimalTuple)->t_infomask = sourceTHeader->
t_infomask;
976 if (targetNullLen > 0)
977 nullBits = (
bits8 *) ((
char *) *targetMinimalTuple
979 targetData = (
char *) *targetMinimalTuple + hoff;
980 infoMask = &((*targetMinimalTuple)->t_infomask);
983 if (targetNullLen > 0)
985 if (sourceNullLen > 0)
989 ((
char *) sourceTHeader)
992 nullBits += sourceNullLen - 1;
998 memset(nullBits, 0xff, sourceNullLen);
1000 nullBits += sourceNullLen - 1;
1002 if (sourceNatts & 0x07)
1005 bitMask = 0xff << (sourceNatts & 0x07);
1007 *nullBits = ~bitMask;
1011 bitMask = (1 << ((sourceNatts - 1) & 0x07));
1015 ((
char *) sourceTuple->
t_data) + sourceTHeader->
t_hoff,
1018 targetData += sourceDataLen;
1026 if (attrmiss && attrmiss[
attnum].am_present)
1029 nullBits ? &nullBits : NULL,
1033 attrmiss[
attnum].am_value,
1057 expand_tuple(NULL, &minimalTuple, sourceTuple, tupleDesc);
1058 return minimalTuple;
1069 expand_tuple(&heapTuple, NULL, sourceTuple, tupleDesc);
1099 memcpy((
char *) td, (
char *) tuple->
t_data, tuple->
t_len);
1125 bool hasnull =
false;
1126 int numberOfAttributes = tupleDescriptor->
natts;
1131 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1132 errmsg(
"number of columns (%d) exceeds limit (%d)",
1138 for (
i = 0;
i < numberOfAttributes;
i++)
1192 (hasnull ? td->
t_bits : NULL));
1211 const Datum *replValues,
1212 const bool *replIsnull,
1213 const bool *doReplace)
1215 int numberOfAttributes = tupleDesc->
natts;
1233 isnull = (
bool *)
palloc(numberOfAttributes *
sizeof(
bool));
1237 for (attoff = 0; attoff < numberOfAttributes; attoff++)
1239 if (doReplace[attoff])
1241 values[attoff] = replValues[attoff];
1242 isnull[attoff] = replIsnull[attoff];
1280 const int *replCols,
1281 const Datum *replValues,
1282 const bool *replIsnull)
1284 int numberOfAttributes = tupleDesc->
natts;
1295 isnull = (
bool *)
palloc(numberOfAttributes *
sizeof(
bool));
1299 for (
i = 0;
i < nCols;
i++)
1303 if (attnum <= 0 || attnum > numberOfAttributes)
1306 isnull[
attnum - 1] = replIsnull[
i];
1350 int tdesc_natts = tupleDesc->
natts;
1365 natts =
Min(natts, tdesc_natts);
1367 tp = (
char *) tup + tup->
t_hoff;
1385 if (!slow && thisatt->attcacheoff >= 0)
1386 off = thisatt->attcacheoff;
1387 else if (thisatt->attlen == -1)
1397 thisatt->attcacheoff = off;
1411 thisatt->attcacheoff = off;
1418 if (thisatt->attlen <= 0)
1460 bool hasnull =
false;
1461 int numberOfAttributes = tupleDescriptor->
natts;
1466 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1467 errmsg(
"number of columns (%d) exceeds limit (%d)",
1473 for (
i = 0;
i < numberOfAttributes;
i++)
1511 (
char *) tuple + hoff,
1514 (hasnull ? tuple->
t_bits : NULL));
1540 memcpy(result, mtup, mtup->
t_len);
static Datum values[MAXATTR]
#define Assert(condition)
Datum datumCopy(Datum value, bool typByVal, int typLen)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
ExpandedObjectHeader * DatumGetEOHP(Datum d)
void EOH_flatten_into(ExpandedObjectHeader *eohptr, void *result, Size allocated_size)
Size EOH_get_flat_size(ExpandedObjectHeader *eohptr)
uint32 hash_bytes(const unsigned char *k, int keylen)
Datum toast_flatten_tuple_to_datum(HeapTupleHeader tup, uint32 tup_len, TupleDesc tupleDesc)
Size heap_compute_data_size(TupleDesc tupleDesc, const Datum *values, const bool *isnull)
static uint32 missing_hash(const void *key, Size keysize)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest)
HeapTuple heap_copytuple(HeapTuple tuple)
static void init_missing_cache()
size_t varsize_any(void *p)
MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup)
Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
#define VARLENA_ATT_IS_PACKABLE(att)
HeapTuple heap_modify_tuple_by_cols(HeapTuple tuple, TupleDesc tupleDesc, int nCols, const int *replCols, const Datum *replValues, const bool *replIsnull)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_free_minimal_tuple(MinimalTuple mtup)
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Datum nocachegetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Datum getmissingattr(TupleDesc tupleDesc, int attnum, bool *isnull)
HeapTuple heap_expand_tuple(HeapTuple sourceTuple, TupleDesc tupleDesc)
#define ATT_IS_PACKABLE(att)
void heap_fill_tuple(TupleDesc tupleDesc, const Datum *values, const bool *isnull, char *data, Size data_size, uint16 *infomask, bits8 *bit)
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
static int missing_match(const void *key1, const void *key2, Size keysize)
MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup)
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
static HTAB * missing_cache
static void expand_tuple(HeapTuple *targetHeapTuple, MinimalTuple *targetMinimalTuple, HeapTuple sourceTuple, TupleDesc tupleDesc)
HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup)
MinimalTuple minimal_expand_tuple(HeapTuple sourceTuple, TupleDesc tupleDesc)
static void fill_val(Form_pg_attribute att, bits8 **bit, int *bitmask, char **dataP, uint16 *infomask, Datum datum, bool isnull)
void heap_freetuple(HeapTuple htup)
HeapTupleData * HeapTuple
MinimalTupleData * MinimalTuple
HeapTupleHeaderData * HeapTupleHeader
#define HeapTupleIsValid(tuple)
#define MINIMAL_TUPLE_OFFSET
#define HeapTupleHeaderSetTypMod(tup, typmod)
#define HeapTupleHeaderGetNatts(tup)
#define SizeofMinimalTupleHeader
#define HeapTupleHasVarWidth(tuple)
#define HeapTupleHasExternal(tuple)
#define MaxTupleAttributeNumber
#define HeapTupleNoNulls(tuple)
#define HeapTupleHeaderGetRawXmin(tup)
#define HeapTupleHeaderSetNatts(tup, natts)
#define HeapTupleHeaderSetDatumLength(tup, len)
#define HeapTupleHeaderGetRawXmax(tup)
#define HeapTupleHeaderGetRawCommandId(tup)
#define HeapTupleHasNulls(tuple)
#define HeapTupleHeaderSetTypeId(tup, typeid)
if(TABLE==NULL||TABLE_index==NULL)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
void pfree(void *pointer)
MemoryContext TopMemoryContext
void * palloc0(Size size)
FormData_pg_attribute * Form_pg_attribute
static Datum PointerGetDatum(const void *X)
static char * DatumGetCString(Datum X)
static Datum TransactionIdGetDatum(TransactionId X)
static Datum CommandIdGetDatum(CommandId X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
MemoryContextSwitchTo(old_ctx)
bits8 t_bits[FLEXIBLE_ARRAY_MEMBER]
struct AttrMissing * missing
#define MinTransactionIdAttributeNumber
#define MaxCommandIdAttributeNumber
#define MaxTransactionIdAttributeNumber
#define TableOidAttributeNumber
#define SelfItemPointerAttributeNumber
#define MinCommandIdAttributeNumber
#define TupleDescAttr(tupdesc, i)
#define att_align_pointer(cur_offset, attalign, attlen, attptr)
#define att_align_nominal(cur_offset, attalign)
#define att_align_datum(cur_offset, attalign, attlen, attdatum)
static bool att_isnull(int ATT, const bits8 *BITS)
#define att_addlength_pointer(cur_offset, attlen, attptr)
#define att_addlength_datum(cur_offset, attlen, attdatum)
static void store_att_byval(void *T, Datum newdatum, int attlen)
#define VARSIZE_SHORT(PTR)
#define SET_VARSIZE_SHORT(PTR, len)
#define VARATT_CAN_MAKE_SHORT(PTR)
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
#define VARATT_IS_SHORT(PTR)
#define VARSIZE_EXTERNAL(PTR)
#define VARATT_CONVERTED_SHORT_SIZE(PTR)
#define VARATT_IS_EXTERNAL(PTR)
Datum bit(PG_FUNCTION_ARGS)