30#include "catalog/pg_am_d.h"
49 return *((
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;
326 if (rel->
rd_rel->relkind != RELKIND_SEQUENCE &&
327 rel->
rd_rel->relam != HEAP_TABLE_AM_OID)
329 errmsg(
"only heap AM is supported")));
334 errmsg(
"number of attributes in tuple header is greater than number of attributes in tuple descriptor")));
336 for (
i = 0;
i < nattrs;
i++)
340 bytea *attr_data = NULL;
374 errmsg(
"first byte of varlena attribute is incorrect for attribute %d",
i)));
384 if (tupdata_len < off +
len)
387 errmsg(
"unexpected end of tuple data")));
389 if (attr->
attlen == -1 && do_detoast)
395 memcpy(
VARDATA(attr_data), tupdata + off,
len);
408 if (tupdata_len != off)
411 errmsg(
"end of tuple reached without looking at all its data")));
434 bool do_detoast =
false;
435 bits8 *t_bits = NULL;
450 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
451 errmsg(
"must be superuser to use raw page functions")));
469 errmsg(
"t_bits string must not be NULL")));
471 bits_str_len = strlen(t_bits_str);
472 if (bits_len != bits_str_len)
475 errmsg(
"unexpected length of t_bits string: %zu, expected %zu",
476 bits_str_len, bits_len)));
486 errmsg(
"t_bits string is expected to be NULL, but instead it is %zu bytes long",
487 strlen(t_bits_str))));
493 t_infomask, t_infomask2, t_bits,
513#define HEAP_TUPLE_INFOMASK_COLS 2
527 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
528 errmsg(
"must be superuser to use raw page functions")));
532 elog(
ERROR,
"return type must be a row type");
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
ArrayType * construct_empty_array(Oid elmtype)
ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
static Datum values[MAXATTR]
static Item PageGetItem(const PageData *page, const ItemIdData *itemId)
#define SizeOfPageHeaderData
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static OffsetNumber PageGetMaxOffsetNumber(const PageData *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)
#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
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 bits8 * text_to_bits(char *str, int len)
static char * bits_to_text(bits8 *bits, int len)
Datum heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
static Oid HeapTupleHeaderGetOidOld(const HeapTupleHeaderData *tup)
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
static int BITMAPLEN(int NATTS)
#define HEAP_XMAX_LOCK_ONLY
static CommandId HeapTupleHeaderGetRawCommandId(const HeapTupleHeaderData *tup)
static TransactionId HeapTupleHeaderGetRawXmax(const HeapTupleHeaderData *tup)
#define HEAP_XMAX_IS_MULTI
#define HEAP_XMAX_COMMITTED
#define HEAP_XMIN_INVALID
#define HEAP_XMAX_EXCL_LOCK
#define HEAP_XMAX_INVALID
static TransactionId HeapTupleHeaderGetRawXmin(const HeapTupleHeaderData *tup)
#define HEAP_XMAX_KEYSHR_LOCK
#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
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
#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)
#define RelationGetDescr(relation)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
MemoryContext multi_call_memory_ctx
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
#define att_nominal_alignby(cur_offset, attalignby)
static bool att_isnull(int ATT, const bits8 *BITS)
#define att_addlength_pointer(cur_offset, attlen, attptr)
#define att_pointer_alignby(cur_offset, attalignby, 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)