1/*-------------------------------------------------------------------------
4 * Functions for the built-in type tuple id
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/utils/adt/tid.c
14 * input routine largely stolen from boxin().
16 *-------------------------------------------------------------------------
33#include "utils/fmgrprotos.h"
47/* ----------------------------------------------------------------
49 * ----------------------------------------------------------------
55 Node *escontext = fcinfo->context;
71 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
72 errmsg(
"invalid input syntax for type %s: \"%s\"",
76 cvt = strtoul(coord[0], &badp, 10);
77 if (errno || *badp !=
DELIM)
79 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
80 errmsg(
"invalid input syntax for type %s: \"%s\"",
85 * Cope with possibility that unsigned long is wider than BlockNumber, in
86 * which case strtoul will not raise an error for some values that are out
87 * of the range of BlockNumber. (See similar code in uint32in_subr().)
90 if (cvt != (
unsigned long) blockNumber &&
91 cvt != (
unsigned long) ((
int32) blockNumber))
93 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
94 errmsg(
"invalid input syntax for type %s: \"%s\"",
98 cvt = strtoul(coord[1], &badp, 10);
99 if (errno || *badp !=
RDELIM ||
102 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
103 errmsg(
"invalid input syntax for type %s: \"%s\"",
114/* ----------------------------------------------------------------
116 * ----------------------------------------------------------------
129 /* Perhaps someday we should output this as a record. */
136 * tidrecv - converts external binary format to tid
157 * tidsend - converts tid to binary format
171/*****************************************************************************
173 *****************************************************************************/
262 * While you'll probably have a lot of trouble with a compiler that
263 * insists on appending pad space to struct ItemPointerData, we can at
264 * least make this code work, by not using sizeof(ItemPointerData).
265 * Instead rely on knowing the sizes of the component fields.
285 * Functions to get latest tid of a specified tuple.
287 * Maybe these implementations should be moved to another place
291 * Utility wrapper for current CTID functions.
292 * Returns the latest version of a tuple pointing at "tid" for
311 if (rel->
rd_rel->relkind == RELKIND_VIEW)
314 if (!RELKIND_HAS_STORAGE(rel->
rd_rel->relkind))
316 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
317 errmsg(
"cannot look at latest visible tid for relation \"%s.%s\"",
333 * Handle CTIDs of views.
334 * CTID should be defined in the view and it must
335 * correspond to the CTID of a base relation.
347 for (
i = 0;
i < natts;
i++)
351 if (strcmp(
NameStr(attr->attname),
"ctid") == 0)
353 if (attr->atttypid != TIDOID)
355 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
356 errmsg(
"ctid isn't of type TID"));
363 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
364 errmsg(
"currtid cannot handle views with no CTID"));
368 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
369 errmsg(
"the view has no rules"));
372 rewrite = rulelock->
rules[
i];
380 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
381 errmsg(
"only one select rule is allowed in views"));
408 elog(
ERROR,
"currtid cannot handle this view");
414 * Get the latest tuple version of the tuple pointing at a CTID, for a
415 * given relation name.
429 /* grab the latest tuple version associated to this CTID */
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_INT64(n)
#define PG_RETURN_INT32(x)
#define PG_RETURN_BOOL(x)
static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
static Datum hash_any(const unsigned char *k, int keylen)
if(TABLE==NULL||TABLE_index==NULL)
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
static void ItemPointerSet(ItemPointerData *pointer, BlockNumber blockNumber, OffsetNumber offNum)
#define PG_RETURN_ITEMPOINTER(x)
static OffsetNumber ItemPointerGetOffsetNumberNoCheck(const ItemPointerData *pointer)
#define PG_GETARG_ITEMPOINTER(n)
static BlockNumber ItemPointerGetBlockNumberNoCheck(const ItemPointerData *pointer)
ItemPointerData * ItemPointer
static void ItemPointerCopy(const ItemPointerData *fromPointer, ItemPointerData *toPointer)
char * get_namespace_name(Oid nspid)
char * pstrdup(const char *in)
RangeVar * makeRangeVarFromNameList(const List *names)
#define IsA(nodeptr, _type_)
ObjectType get_relkind_objtype(char relkind)
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
#define rt_fetch(rangetable_index, rangetable)
FormData_pg_attribute * Form_pg_attribute
static int list_length(const List *l)
#define IS_SPECIAL_VARNO(varno)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RelationGetNamespace(relation)
Snapshot GetLatestSnapshot(void)
void UnregisterSnapshot(Snapshot snapshot)
Snapshot RegisterSnapshot(Snapshot snapshot)
struct StringInfoData * StringInfo
#define SelfItemPointerAttributeNumber
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
void table_tuple_get_latest_tid(TableScanDesc scan, ItemPointer tid)
static void table_endscan(TableScanDesc scan)
static TableScanDesc table_beginscan_tid(Relation rel, Snapshot snapshot)
Datum tidge(PG_FUNCTION_ARGS)
Datum bttidcmp(PG_FUNCTION_ARGS)
Datum currtid_byrelname(PG_FUNCTION_ARGS)
static ItemPointer currtid_internal(Relation rel, ItemPointer tid)
Datum hashtid(PG_FUNCTION_ARGS)
Datum tidlarger(PG_FUNCTION_ARGS)
Datum hashtidextended(PG_FUNCTION_ARGS)
Datum tideq(PG_FUNCTION_ARGS)
Datum tidgt(PG_FUNCTION_ARGS)
Datum tidin(PG_FUNCTION_ARGS)
Datum tidle(PG_FUNCTION_ARGS)
Datum tidsmaller(PG_FUNCTION_ARGS)
Datum tidne(PG_FUNCTION_ARGS)
static ItemPointer currtid_for_view(Relation viewrel, ItemPointer tid)
Datum tidrecv(PG_FUNCTION_ARGS)
Datum tidout(PG_FUNCTION_ARGS)
Datum tidsend(PG_FUNCTION_ARGS)
Datum tidlt(PG_FUNCTION_ARGS)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
List * textToQualifiedNameList(text *textval)