36 void *result,
Size allocated_size);
50 Datum newValue,
bool isnull);
79 if (type_id != RECORDOID)
90 if (typentry->
typtype == TYPTYPE_DOMAIN)
98 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
99 errmsg(
"type %s is not composite",
132 + tupdesc->
natts * (
sizeof(
Datum) +
sizeof(
bool)));
173 if (type_id == RECORDOID)
230 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
231 errmsg(
"type %s is not composite",
263 + tupdesc->
natts * (
sizeof(
Datum) +
sizeof(
bool)));
355 + tupdesc->
natts * (
sizeof(
Datum) +
sizeof(
bool)));
443 bool expand_external)
467 if (expand_external && tuple)
478 expand_external =
false;
484 oldflags = erh->
flags;
531 erh->
flags = newflags;
554 if (oldValue < oldfstartptr || oldValue >= oldfendptr)
725 erh->
flags &= ~ER_FLAG_HAVE_EXTERNAL;
765 void *result,
Size allocated_size)
793 memset(tuphdr, 0, allocated_size);
809 (
char *) tuphdr + erh->
hoff,
971 nfields = tupdesc->
natts;
981 nfields * (
sizeof(
Datum) +
sizeof(
bool)));
983 dnulls = (
bool *) (
chunk + nfields *
sizeof(
Datum));
1002 memset(dvalues, 0, nfields *
sizeof(
Datum));
1003 memset(dnulls,
true, nfields *
sizeof(
bool));
1028 for (fno = 0; fno < tupdesc->
natts; fno++)
1031 if (
namestrcmp(&attr->attname, fieldname) == 0 &&
1032 !attr->attisdropped)
1034 finfo->
fnumber = attr->attnum;
1035 finfo->
ftypeid = attr->atttypid;
1036 finfo->
ftypmod = attr->atttypmod;
1044 if (sysattr != NULL)
1046 finfo->
fnumber = sysattr->attnum;
1047 finfo->
ftypeid = sysattr->atttypid;
1048 finfo->
ftypmod = sysattr->atttypmod;
1082 *isnull = erh->
dnulls[fnumber - 1];
1083 return erh->
dvalues[fnumber - 1];
1113 Datum newValue,
bool isnull,
1114 bool expand_external,
1115 bool check_constraints)
1143 elog(
ERROR,
"cannot assign to field %d of expanded record", fnumber);
1155 if (expand_external)
1157 if (attr->
attlen == -1 &&
1166 expand_external =
false;
1175 if (expand_external)
1187 if (attr->
attlen == -1 &&
1199 erh->
flags &= ~ER_FLAG_FVALUE_VALID;
1204 if (!attr->
attbyval && !dnulls[fnumber - 1])
1210 dvalues[fnumber - 1] = newValue;
1211 dnulls[fnumber - 1] = isnull;
1227 if (oldValue < erh->fstartptr || oldValue >= erh->
fendptr)
1250 const Datum *newValues,
const bool *isnulls,
1251 bool expand_external)
1271 erh->
flags &= ~ER_FLAG_FVALUE_VALID;
1280 for (fnumber = 0; fnumber < erh->
nfields; fnumber++)
1290 newValue = newValues[fnumber];
1291 isnull = isnulls[fnumber];
1302 if (attr->
attlen == -1 &&
1305 if (expand_external)
1313 newValue =
datumCopy(newValue,
false, -1);
1339 if (oldValue < erh->fstartptr || oldValue >= erh->
fendptr)
1345 dvalues[fnumber] = newValue;
1346 dnulls[fnumber] = isnull;
1384 "expanded record short-term context",
1423 + tupdesc->
natts * (
sizeof(
Datum) +
sizeof(bool)));
1495 Datum newValue,
bool isnull)
1515 dummy_erh->
nfields *
sizeof(
bool));
1522 memset(dummy_erh->
dnulls,
true, dummy_erh->
nfields *
sizeof(
bool));
1530 elog(
ERROR,
"cannot assign to field %d of expanded record", fnumber);
1533 dummy_erh->
dvalues[fnumber - 1] = newValue;
1534 dummy_erh->
dnulls[fnumber - 1] = isnull;
1605 dummy_erh->
fvalue = tuple;
#define Assert(condition)
Datum datumCopy(Datum value, bool typByVal, int typLen)
struct varlena * detoast_external_attr(struct varlena *attr)
void domain_check(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
ExpandedObjectHeader * DatumGetEOHP(Datum d)
void EOH_init_header(ExpandedObjectHeader *eohptr, const ExpandedObjectMethods *methods, MemoryContext obj_context)
static Datum EOHPGetRWDatum(const struct ExpandedObjectHeader *eohptr)
static const ExpandedObjectMethods ER_methods
static pg_noinline void check_domain_for_new_tuple(ExpandedRecordHeader *erh, HeapTuple tuple)
static void build_dummy_expanded_header(ExpandedRecordHeader *main_erh)
static void ER_flatten_into(ExpandedObjectHeader *eohptr, void *result, Size allocated_size)
ExpandedRecordHeader * make_expanded_record_from_exprecord(ExpandedRecordHeader *olderh, MemoryContext parentcontext)
ExpandedRecordHeader * make_expanded_record_from_tupdesc(TupleDesc tupdesc, MemoryContext parentcontext)
void expanded_record_set_field_internal(ExpandedRecordHeader *erh, int fnumber, Datum newValue, bool isnull, bool expand_external, bool check_constraints)
bool expanded_record_lookup_field(ExpandedRecordHeader *erh, const char *fieldname, ExpandedRecordFieldInfo *finfo)
static MemoryContext get_short_term_cxt(ExpandedRecordHeader *erh)
Datum expanded_record_fetch_field(ExpandedRecordHeader *erh, int fnumber, bool *isnull)
static Size ER_get_flat_size(ExpandedObjectHeader *eohptr)
static pg_noinline void check_domain_for_new_field(ExpandedRecordHeader *erh, int fnumber, Datum newValue, bool isnull)
static void ER_mc_callback(void *arg)
Datum make_expanded_record_from_datum(Datum recorddatum, MemoryContext parentcontext)
ExpandedRecordHeader * make_expanded_record_from_typeid(Oid type_id, int32 typmod, MemoryContext parentcontext)
ExpandedRecordHeader * DatumGetExpandedRecord(Datum d)
TupleDesc expanded_record_fetch_tupdesc(ExpandedRecordHeader *erh)
void expanded_record_set_tuple(ExpandedRecordHeader *erh, HeapTuple tuple, bool copy, bool expand_external)
HeapTuple expanded_record_get_tuple(ExpandedRecordHeader *erh)
void deconstruct_expanded_record(ExpandedRecordHeader *erh)
void expanded_record_set_fields(ExpandedRecordHeader *erh, const Datum *newValues, const bool *isnulls, bool expand_external)
#define ER_FLAG_HAVE_EXTERNAL
#define ExpandedRecordIsEmpty(erh)
static Datum ExpandedRecordGetRODatum(const ExpandedRecordHeader *erh)
#define ER_FLAG_DVALUES_VALID
#define ER_FLAG_TUPDESC_ALLOCED
#define ER_FLAG_DVALUES_ALLOCED
#define ER_FLAG_IS_DOMAIN
static TupleDesc expanded_record_get_tupdesc(ExpandedRecordHeader *erh)
#define ER_FLAGS_NON_DATA
#define ER_FLAG_FVALUE_VALID
#define ER_FLAG_FVALUE_ALLOCED
#define DatumGetHeapTupleHeader(X)
const FormData_pg_attribute * SystemAttributeByName(const char *attname)
HeapTuple toast_flatten_tuple(HeapTuple tup, TupleDesc tupleDesc)
Size heap_compute_data_size(TupleDesc tupleDesc, const Datum *values, const bool *isnull)
HeapTuple heap_copytuple(HeapTuple tuple)
Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
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)
void heap_freetuple(HeapTuple htup)
HeapTupleHeaderData * HeapTupleHeader
#define HeapTupleHeaderSetTypMod(tup, typmod)
#define HeapTupleHeaderGetTypMod(tup)
#define HeapTupleHasExternal(tuple)
#define HeapTupleHeaderGetTypeId(tup)
#define HeapTupleHeaderGetDatumLength(tup)
#define HeapTupleHeaderSetNatts(tup, natts)
#define HeapTupleHeaderSetDatumLength(tup, len)
#define HeapTupleHeaderHasExternal(tup)
#define HeapTupleHeaderSetTypeId(tup, typeid)
if(TABLE==NULL||TABLE_index==NULL)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
void * MemoryContextAlloc(MemoryContext context, Size size)
void MemoryContextReset(MemoryContext context)
void * MemoryContextAllocZero(MemoryContext context, Size size)
void MemoryContextRegisterResetCallback(MemoryContext context, MemoryContextCallback *cb)
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define ALLOCSET_SMALL_SIZES
int namestrcmp(Name name, const char *str)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
FormData_pg_attribute * Form_pg_attribute
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
MemoryContext eoh_context
MemoryContext er_short_term_cxt
MemoryContextCallback er_mcb
struct ExpandedRecordHeader * er_dummy_header
MemoryContextCallbackFunction func
uint64 tupDesc_identifier
void FreeTupleDesc(TupleDesc tupdesc)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
#define ReleaseTupleDesc(tupdesc)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
uint64 assign_record_type_identifier(Oid type_id, int32 typmod)
void assign_record_type_typmod(TupleDesc tupDesc)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
#define TYPECACHE_TUPDESC
#define TYPECACHE_DOMAIN_BASE_INFO
#define VARATT_IS_EXTERNAL_EXPANDED_RW(PTR)
#define VARATT_IS_EXTERNAL(PTR)