30 #include "catalog/pg_am_d.h"
46 #define HeapTupleHeaderGetOidOld(tup) \
48 ((tup)->t_infomask & HEAP_HASOID_OLD) ? \
49 *((Oid *) ((char *)(tup) + (tup)->t_hoff - sizeof(Oid))) \
70 str[
i] = (bits[(
i / 8)] & (1 << (
i % 8))) ?
'1' :
'0';
98 if ((
str[off] ==
'0') || (
str[off] ==
'1'))
99 byte =
byte | ((
str[off] -
'0') << off % 8);
103 errmsg(
"invalid character \"%.*s\" in t_bits string",
107 bits[off / 8] = byte;
139 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
140 errmsg(
"must be superuser to use raw page functions")));
151 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
152 errmsg(
"input page too small (%d bytes)", raw_page_size)));
161 elog(
ERROR,
"return type must be a row type");
163 inter_call_data->
tupd = tupdesc;
189 memset(nulls, 0,
sizeof(nulls));
212 lp_offset + lp_len <= raw_page_size)
215 bytea *tuple_data_bytea;
232 tuple_data_len = lp_len - tuphdr->
t_hoff;
235 memcpy(
VARDATA(tuple_data_bytea), (
char *) tuphdr + tuphdr->
t_hoff,
246 tuphdr->
t_hoff <= lp_len &&
279 for (
i = 4;
i <= 13;
i++)
287 inter_call_data->
offset++;
321 nattrs = tupdesc->
natts;
323 if (rel->
rd_rel->relam != HEAP_TABLE_AM_OID)
325 errmsg(
"only heap AM is supported")));
330 errmsg(
"number of attributes in tuple header is greater than number of attributes in tuple descriptor")));
332 for (
i = 0;
i < nattrs;
i++)
336 bytea *attr_data = NULL;
355 if (attr->attlen == -1)
370 errmsg(
"first byte of varlena attribute is incorrect for attribute %d",
i)));
380 if (tupdata_len < off +
len)
383 errmsg(
"unexpected end of tuple data")));
385 if (attr->attlen == -1 && do_detoast)
391 memcpy(
VARDATA(attr_data), tupdata + off,
len);
404 if (tupdata_len != off)
407 errmsg(
"end of tuple reached without looking at all its data")));
430 bool do_detoast =
false;
431 bits8 *t_bits = NULL;
446 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
447 errmsg(
"must be superuser to use raw page functions")));
465 errmsg(
"t_bits string must not be NULL")));
467 bits_str_len = strlen(t_bits_str);
468 if (bits_len != bits_str_len)
471 errmsg(
"unexpected length of t_bits string: %zu, expected %zu",
472 bits_str_len, bits_len)));
482 errmsg(
"t_bits string is expected to be NULL, but instead it is %zu bytes long",
483 strlen(t_bits_str))));
489 t_infomask, t_infomask2, t_bits,
509 #define HEAP_TUPLE_INFOMASK_COLS 2
523 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
524 errmsg(
"must be superuser to use raw page functions")));
528 elog(
ERROR,
"return type must be a row type");
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
ArrayType * construct_empty_array(Oid elmtype)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
static Datum values[MAXATTR]
static Item PageGetItem(Page page, ItemId itemId)
#define SizeOfPageHeaderData
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static OffsetNumber PageGetMaxOffsetNumber(Page page)
#define CStringGetTextDatum(s)
#define Assert(condition)
#define MemSet(start, val, len)
static void PGresult * res
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
struct varlena * pg_detoast_datum_copy(struct varlena *datum)
#define PG_GETARG_TEXT_PP(n)
#define PG_GETARG_BOOL(n)
#define PG_RETURN_DATUM(x)
#define PG_GETARG_BYTEA_P(n)
#define PG_GETARG_INT16(n)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
#define SRF_RETURN_DONE(_funcctx)
static bits8 * text_to_bits(char *str, int len)
#define HEAP_TUPLE_INFOMASK_COLS
PG_FUNCTION_INFO_V1(heap_page_items)
Datum heap_page_items(PG_FUNCTION_ARGS)
struct heap_page_items_state heap_page_items_state
#define HeapTupleHeaderGetOidOld(tup)
static Datum tuple_data_split_internal(Oid relid, char *tupdata, uint16 tupdata_len, uint16 t_infomask, uint16 t_infomask2, bits8 *t_bits, bool do_detoast)
static char * bits_to_text(bits8 *bits, int len)
Datum heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
Datum tuple_data_split(PG_FUNCTION_ARGS)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
HeapTupleHeaderData * HeapTupleHeader
#define HEAP_XMAX_SHR_LOCK
#define HEAP_XMIN_COMMITTED
#define HeapTupleHeaderGetNatts(tup)
#define SizeofHeapTupleHeader
#define HEAP_KEYS_UPDATED
#define HEAP_XMAX_LOCK_ONLY
#define HEAP_XMAX_IS_MULTI
#define HEAP_XMAX_COMMITTED
#define HEAP_XMIN_INVALID
#define HeapTupleHeaderGetRawXmin(tup)
#define HEAP_XMAX_EXCL_LOCK
#define HEAP_XMAX_INVALID
#define HeapTupleHeaderGetRawXmax(tup)
#define HEAP_XMAX_KEYSHR_LOCK
#define HeapTupleHeaderGetRawCommandId(tup)
#define ItemIdGetLength(itemId)
#define ItemIdGetOffset(itemId)
#define ItemIdGetFlags(itemId)
#define ItemIdHasStorage(itemId)
int pg_mblen(const char *mbstr)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
#define FirstOffsetNumber
FormData_pg_attribute * Form_pg_attribute
#define ERRCODE_DATA_CORRUPTED
static uint64 pg_popcount(const char *buf, int bytes)
static Datum PointerGetDatum(const void *X)
static Datum UInt16GetDatum(uint16 X)
static Datum UInt8GetDatum(uint8 X)
static Datum UInt32GetDatum(uint32 X)
MemoryContextSwitchTo(old_ctx)
#define RelationGetDescr(relation)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
MemoryContext multi_call_memory_ctx
#define TupleDescAttr(tupdesc, i)
#define att_align_pointer(cur_offset, attalign, attlen, attptr)
#define att_align_nominal(cur_offset, attalign)
static bool att_isnull(int ATT, const bits8 *BITS)
#define att_addlength_pointer(cur_offset, attlen, attptr)
#define VARATT_IS_EXTERNAL_ONDISK(PTR)
#define VARATT_IS_EXTERNAL_INDIRECT(PTR)
#define SET_VARSIZE(PTR, len)
#define VARATT_IS_EXTERNAL(PTR)
char * text_to_cstring(const text *t)