PostgreSQL Source Code  git master
tid.c File Reference
#include "postgres.h"
#include <math.h>
#include <limits.h>
#include "access/heapam.h"
#include "access/sysattr.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "parser/parsetree.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/tqual.h"
#include "utils/varlena.h"
Include dependency graph for tid.c:

Go to the source code of this file.

Macros

#define DatumGetItemPointer(X)   ((ItemPointer) DatumGetPointer(X))
 
#define ItemPointerGetDatum(X)   PointerGetDatum(X)
 
#define PG_GETARG_ITEMPOINTER(n)   DatumGetItemPointer(PG_GETARG_DATUM(n))
 
#define PG_RETURN_ITEMPOINTER(x)   return ItemPointerGetDatum(x)
 
#define LDELIM   '('
 
#define RDELIM   ')'
 
#define DELIM   ','
 
#define NTIDARGS   2
 

Functions

Datum tidin (PG_FUNCTION_ARGS)
 
Datum tidout (PG_FUNCTION_ARGS)
 
Datum tidrecv (PG_FUNCTION_ARGS)
 
Datum tidsend (PG_FUNCTION_ARGS)
 
Datum tideq (PG_FUNCTION_ARGS)
 
Datum tidne (PG_FUNCTION_ARGS)
 
Datum tidlt (PG_FUNCTION_ARGS)
 
Datum tidle (PG_FUNCTION_ARGS)
 
Datum tidgt (PG_FUNCTION_ARGS)
 
Datum tidge (PG_FUNCTION_ARGS)
 
Datum bttidcmp (PG_FUNCTION_ARGS)
 
Datum tidlarger (PG_FUNCTION_ARGS)
 
Datum tidsmaller (PG_FUNCTION_ARGS)
 
void setLastTid (const ItemPointer tid)
 
static Datum currtid_for_view (Relation viewrel, ItemPointer tid)
 
Datum currtid_byreloid (PG_FUNCTION_ARGS)
 
Datum currtid_byrelname (PG_FUNCTION_ARGS)
 

Variables

static ItemPointerData Current_last_tid = {{0, 0}, 0}
 

Macro Definition Documentation

◆ DatumGetItemPointer

#define DatumGetItemPointer (   X)    ((ItemPointer) DatumGetPointer(X))

Definition at line 38 of file tid.c.

◆ DELIM

#define DELIM   ','

Definition at line 45 of file tid.c.

Referenced by tidin().

◆ ItemPointerGetDatum

#define ItemPointerGetDatum (   X)    PointerGetDatum(X)

Definition at line 39 of file tid.c.

◆ LDELIM

#define LDELIM   '('

Definition at line 43 of file tid.c.

Referenced by tidin().

◆ NTIDARGS

#define NTIDARGS   2

Definition at line 46 of file tid.c.

Referenced by tidin().

◆ PG_GETARG_ITEMPOINTER

#define PG_GETARG_ITEMPOINTER (   n)    DatumGetItemPointer(PG_GETARG_DATUM(n))

◆ PG_RETURN_ITEMPOINTER

#define PG_RETURN_ITEMPOINTER (   x)    return ItemPointerGetDatum(x)

Definition at line 41 of file tid.c.

Referenced by currtid_byrelname(), currtid_byreloid(), tidin(), tidlarger(), tidrecv(), and tidsmaller().

◆ RDELIM

#define RDELIM   ')'

Definition at line 44 of file tid.c.

Referenced by tidin().

Function Documentation

◆ bttidcmp()

Datum bttidcmp ( PG_FUNCTION_ARGS  )

Definition at line 216 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_INT32.

217 {
220 
221  PG_RETURN_INT32(ItemPointerCompare(arg1, arg2));
222 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314

◆ currtid_byrelname()

Datum currtid_byrelname ( PG_FUNCTION_ARGS  )

Definition at line 364 of file tid.c.

References AccessShareLock, ACL_KIND_CLASS, ACL_SELECT, aclcheck_error(), ACLCHECK_OK, currtid_for_view(), GetLatestSnapshot(), GetUserId(), heap_close, heap_get_latest_tid(), heap_openrv(), ItemPointerCopy, makeRangeVarFromNameList(), palloc(), pg_class_aclcheck(), PG_GETARG_ITEMPOINTER, PG_GETARG_TEXT_PP, PG_RETURN_ITEMPOINTER, RelationData::rd_rel, RegisterSnapshot(), RelationGetRelationName, RelationGetRelid, RELKIND_VIEW, textToQualifiedNameList(), and UnregisterSnapshot().

365 {
366  text *relname = PG_GETARG_TEXT_PP(0);
368  ItemPointer result;
369  RangeVar *relrv;
370  Relation rel;
371  AclResult aclresult;
372  Snapshot snapshot;
373 
375  rel = heap_openrv(relrv, AccessShareLock);
376 
377  aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
378  ACL_SELECT);
379  if (aclresult != ACLCHECK_OK)
380  aclcheck_error(aclresult, ACL_KIND_CLASS,
382 
383  if (rel->rd_rel->relkind == RELKIND_VIEW)
384  return currtid_for_view(rel, tid);
385 
386  result = (ItemPointer) palloc(sizeof(ItemPointerData));
387  ItemPointerCopy(tid, result);
388 
389  snapshot = RegisterSnapshot(GetLatestSnapshot());
390  heap_get_latest_tid(rel, snapshot, result);
391  UnregisterSnapshot(snapshot);
392 
394 
395  PG_RETURN_ITEMPOINTER(result);
396 }
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:863
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
Oid GetUserId(void)
Definition: miscinit.c:284
#define AccessShareLock
Definition: lockdefs.h:36
void heap_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid)
Definition: heapam.c:2184
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3023
#define heap_close(r, l)
Definition: heapam.h:97
Form_pg_class rd_rel
Definition: rel.h:114
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
ItemPointerData * ItemPointer
Definition: itemptr.h:49
static Datum currtid_for_view(Relation viewrel, ItemPointer tid)
Definition: tid.c:263
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:41
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3457
#define RelationGetRelationName(relation)
Definition: rel.h:445
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3205
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:905
AclResult
Definition: acl.h:178
#define ACL_SELECT
Definition: parsenodes.h:73
Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1318
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:379
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4480
void * palloc(Size size)
Definition: mcxt.c:848
#define RELKIND_VIEW
Definition: pg_class.h:164
Definition: c.h:487
#define RelationGetRelid(relation)
Definition: rel.h:425
#define ItemPointerCopy(fromPointer, toPointer)
Definition: itemptr.h:139

◆ currtid_byreloid()

Datum currtid_byreloid ( PG_FUNCTION_ARGS  )

Definition at line 325 of file tid.c.

References AccessShareLock, ACL_KIND_CLASS, ACL_SELECT, aclcheck_error(), ACLCHECK_OK, Current_last_tid, currtid_for_view(), GetLatestSnapshot(), GetUserId(), heap_close, heap_get_latest_tid(), heap_open(), ItemPointerCopy, palloc(), pg_class_aclcheck(), PG_GETARG_ITEMPOINTER, PG_GETARG_OID, PG_RETURN_ITEMPOINTER, RelationData::rd_rel, RegisterSnapshot(), RelationGetRelationName, RelationGetRelid, RELKIND_VIEW, and UnregisterSnapshot().

Referenced by currtid_for_view().

326 {
327  Oid reloid = PG_GETARG_OID(0);
329  ItemPointer result;
330  Relation rel;
331  AclResult aclresult;
332  Snapshot snapshot;
333 
334  result = (ItemPointer) palloc(sizeof(ItemPointerData));
335  if (!reloid)
336  {
337  *result = Current_last_tid;
338  PG_RETURN_ITEMPOINTER(result);
339  }
340 
341  rel = heap_open(reloid, AccessShareLock);
342 
343  aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
344  ACL_SELECT);
345  if (aclresult != ACLCHECK_OK)
346  aclcheck_error(aclresult, ACL_KIND_CLASS,
348 
349  if (rel->rd_rel->relkind == RELKIND_VIEW)
350  return currtid_for_view(rel, tid);
351 
352  ItemPointerCopy(tid, result);
353 
354  snapshot = RegisterSnapshot(GetLatestSnapshot());
355  heap_get_latest_tid(rel, snapshot, result);
356  UnregisterSnapshot(snapshot);
357 
359 
360  PG_RETURN_ITEMPOINTER(result);
361 }
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:863
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
Oid GetUserId(void)
Definition: miscinit.c:284
#define AccessShareLock
Definition: lockdefs.h:36
void heap_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid)
Definition: heapam.c:2184
#define heap_close(r, l)
Definition: heapam.h:97
Form_pg_class rd_rel
Definition: rel.h:114
unsigned int Oid
Definition: postgres_ext.h:31
ItemPointerData * ItemPointer
Definition: itemptr.h:49
static Datum currtid_for_view(Relation viewrel, ItemPointer tid)
Definition: tid.c:263
static ItemPointerData Current_last_tid
Definition: tid.c:249
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:41
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3457
#define RelationGetRelationName(relation)
Definition: rel.h:445
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:905
AclResult
Definition: acl.h:178
#define ACL_SELECT
Definition: parsenodes.h:73
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:379
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4480
void * palloc(Size size)
Definition: mcxt.c:848
#define RELKIND_VIEW
Definition: pg_class.h:164
#define RelationGetRelid(relation)
Definition: rel.h:425
#define ItemPointerCopy(fromPointer, toPointer)
Definition: itemptr.h:139

◆ currtid_for_view()

static Datum currtid_for_view ( Relation  viewrel,
ItemPointer  tid 
)
static

Definition at line 263 of file tid.c.

References AccessShareLock, RewriteRule::actions, CMD_SELECT, currtid_byreloid(), DirectFunctionCall2, elog, ERROR, RewriteRule::event, TargetEntry::expr, get_tle_by_resno(), heap_close, i, IS_SPECIAL_VARNO, IsA, linitial, list_length(), NameStr, tupleDesc::natts, RuleLock::numLocks, ObjectIdGetDatum, PointerGetDatum, RelationData::rd_rules, RelationGetDescr, rt_fetch, Query::rtable, RuleLock::rules, SelfItemPointerAttributeNumber, Query::targetList, TIDOID, TupleDescAttr, Var::varattno, and Var::varno.

Referenced by currtid_byrelname(), and currtid_byreloid().

264 {
265  TupleDesc att = RelationGetDescr(viewrel);
266  RuleLock *rulelock;
267  RewriteRule *rewrite;
268  int i,
269  natts = att->natts,
270  tididx = -1;
271 
272  for (i = 0; i < natts; i++)
273  {
274  Form_pg_attribute attr = TupleDescAttr(att, i);
275 
276  if (strcmp(NameStr(attr->attname), "ctid") == 0)
277  {
278  if (attr->atttypid != TIDOID)
279  elog(ERROR, "ctid isn't of type TID");
280  tididx = i;
281  break;
282  }
283  }
284  if (tididx < 0)
285  elog(ERROR, "currtid cannot handle views with no CTID");
286  rulelock = viewrel->rd_rules;
287  if (!rulelock)
288  elog(ERROR, "the view has no rules");
289  for (i = 0; i < rulelock->numLocks; i++)
290  {
291  rewrite = rulelock->rules[i];
292  if (rewrite->event == CMD_SELECT)
293  {
294  Query *query;
295  TargetEntry *tle;
296 
297  if (list_length(rewrite->actions) != 1)
298  elog(ERROR, "only one select rule is allowed in views");
299  query = (Query *) linitial(rewrite->actions);
300  tle = get_tle_by_resno(query->targetList, tididx + 1);
301  if (tle && tle->expr && IsA(tle->expr, Var))
302  {
303  Var *var = (Var *) tle->expr;
304  RangeTblEntry *rte;
305 
306  if (!IS_SPECIAL_VARNO(var->varno) &&
308  {
309  rte = rt_fetch(var->varno, query->rtable);
310  if (rte)
311  {
312  heap_close(viewrel, AccessShareLock);
314  }
315  }
316  }
317  break;
318  }
319  }
320  elog(ERROR, "currtid cannot handle this view");
321  return (Datum) 0;
322 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
int numLocks
Definition: prs2lock.h:42
#define RelationGetDescr(relation)
Definition: rel.h:437
#define PointerGetDatum(X)
Definition: postgres.h:562
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:90
#define AccessShareLock
Definition: lockdefs.h:36
AttrNumber varattno
Definition: primnodes.h:168
#define heap_close(r, l)
Definition: heapam.h:97
Definition: primnodes.h:163
int natts
Definition: tupdesc.h:79
List * targetList
Definition: parsenodes.h:138
#define TIDOID
Definition: pg_type.h:332
#define IS_SPECIAL_VARNO(varno)
Definition: primnodes.h:157
#define linitial(l)
Definition: pg_list.h:111
List * rtable
Definition: parsenodes.h:135
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
Datum currtid_byreloid(PG_FUNCTION_ARGS)
Definition: tid.c:325
CmdType event
Definition: prs2lock.h:27
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
RewriteRule ** rules
Definition: prs2lock.h:43
List * actions
Definition: prs2lock.h:29
#define rt_fetch(rangetable_index, rangetable)
Definition: parsetree.h:31
Index varno
Definition: primnodes.h:166
uintptr_t Datum
Definition: postgres.h:372
Expr * expr
Definition: primnodes.h:1375
RuleLock * rd_rules
Definition: rel.h:118
static int list_length(const List *l)
Definition: pg_list.h:89
int i
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
#define NameStr(name)
Definition: c.h:547
#define SelfItemPointerAttributeNumber
Definition: sysattr.h:21
#define elog
Definition: elog.h:219
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ setLastTid()

void setLastTid ( const ItemPointer  tid)

Definition at line 252 of file tid.c.

Referenced by ExecInsert().

253 {
254  Current_last_tid = *tid;
255 }
static ItemPointerData Current_last_tid
Definition: tid.c:249

◆ tideq()

Datum tideq ( PG_FUNCTION_ARGS  )

Definition at line 162 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

163 {
166 
167  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) == 0);
168 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ tidge()

Datum tidge ( PG_FUNCTION_ARGS  )

Definition at line 207 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

208 {
211 
212  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) >= 0);
213 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ tidgt()

Datum tidgt ( PG_FUNCTION_ARGS  )

Definition at line 198 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

199 {
202 
203  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) > 0);
204 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ tidin()

Datum tidin ( PG_FUNCTION_ARGS  )

Definition at line 53 of file tid.c.

References DELIM, ereport, errcode(), errmsg(), ERROR, i, ItemPointerSet, LDELIM, NTIDARGS, palloc(), PG_GETARG_CSTRING, PG_RETURN_ITEMPOINTER, RDELIM, and generate_unaccent_rules::str.

Referenced by make_tuple_from_result_row().

54 {
55  char *str = PG_GETARG_CSTRING(0);
56  char *p,
57  *coord[NTIDARGS];
58  int i;
59  ItemPointer result;
60  BlockNumber blockNumber;
61  OffsetNumber offsetNumber;
62  char *badp;
63  int hold_offset;
64 
65  for (i = 0, p = str; *p && i < NTIDARGS && *p != RDELIM; p++)
66  if (*p == DELIM || (*p == LDELIM && !i))
67  coord[i++] = p + 1;
68 
69  if (i < NTIDARGS)
70  ereport(ERROR,
71  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
72  errmsg("invalid input syntax for type %s: \"%s\"",
73  "tid", str)));
74 
75  errno = 0;
76  blockNumber = strtoul(coord[0], &badp, 10);
77  if (errno || *badp != DELIM)
78  ereport(ERROR,
79  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
80  errmsg("invalid input syntax for type %s: \"%s\"",
81  "tid", str)));
82 
83  hold_offset = strtol(coord[1], &badp, 10);
84  if (errno || *badp != RDELIM ||
85  hold_offset > USHRT_MAX || hold_offset < 0)
86  ereport(ERROR,
87  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
88  errmsg("invalid input syntax for type %s: \"%s\"",
89  "tid", str)));
90 
91  offsetNumber = hold_offset;
92 
93  result = (ItemPointer) palloc(sizeof(ItemPointerData));
94 
95  ItemPointerSet(result, blockNumber, offsetNumber);
96 
97  PG_RETURN_ITEMPOINTER(result);
98 }
#define LDELIM
Definition: tid.c:43
#define RDELIM
Definition: tid.c:44
int errcode(int sqlerrcode)
Definition: elog.c:575
#define NTIDARGS
Definition: tid.c:46
uint32 BlockNumber
Definition: block.h:31
uint16 OffsetNumber
Definition: off.h:24
ItemPointerData * ItemPointer
Definition: itemptr.h:49
#define ERROR
Definition: elog.h:43
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:41
#define ereport(elevel, rest)
Definition: elog.h:122
#define DELIM
Definition: tid.c:45
void * palloc(Size size)
Definition: mcxt.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:105

◆ tidlarger()

Datum tidlarger ( PG_FUNCTION_ARGS  )

Definition at line 225 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_ITEMPOINTER.

226 {
229 
230  PG_RETURN_ITEMPOINTER(ItemPointerCompare(arg1, arg2) >= 0 ? arg1 : arg2);
231 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:41

◆ tidle()

Datum tidle ( PG_FUNCTION_ARGS  )

Definition at line 189 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

190 {
193 
194  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) <= 0);
195 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ tidlt()

Datum tidlt ( PG_FUNCTION_ARGS  )

Definition at line 180 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

181 {
184 
185  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) < 0);
186 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ tidne()

Datum tidne ( PG_FUNCTION_ARGS  )

Definition at line 171 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

172 {
175 
176  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) != 0);
177 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ tidout()

Datum tidout ( PG_FUNCTION_ARGS  )

Definition at line 105 of file tid.c.

References buf, ItemPointerGetBlockNumberNoCheck, ItemPointerGetOffsetNumberNoCheck, PG_GETARG_ITEMPOINTER, PG_RETURN_CSTRING, pstrdup(), and snprintf().

Referenced by pgrowlocks().

106 {
107  ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0);
108  BlockNumber blockNumber;
109  OffsetNumber offsetNumber;
110  char buf[32];
111 
112  blockNumber = ItemPointerGetBlockNumberNoCheck(itemPtr);
113  offsetNumber = ItemPointerGetOffsetNumberNoCheck(itemPtr);
114 
115  /* Perhaps someday we should output this as a record. */
116  snprintf(buf, sizeof(buf), "(%u,%u)", blockNumber, offsetNumber);
117 
119 }
#define ItemPointerGetOffsetNumberNoCheck(pointer)
Definition: itemptr.h:86
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
char * pstrdup(const char *in)
Definition: mcxt.c:1076
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
uint32 BlockNumber
Definition: block.h:31
uint16 OffsetNumber
Definition: off.h:24
static char * buf
Definition: pg_test_fsync.c:67
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
#define ItemPointerGetBlockNumberNoCheck(pointer)
Definition: itemptr.h:67

◆ tidrecv()

Datum tidrecv ( PG_FUNCTION_ARGS  )

Definition at line 125 of file tid.c.

References buf, ItemPointerSet, palloc(), PG_GETARG_POINTER, PG_RETURN_ITEMPOINTER, and pq_getmsgint().

126 {
128  ItemPointer result;
129  BlockNumber blockNumber;
130  OffsetNumber offsetNumber;
131 
132  blockNumber = pq_getmsgint(buf, sizeof(blockNumber));
133  offsetNumber = pq_getmsgint(buf, sizeof(offsetNumber));
134 
135  result = (ItemPointer) palloc(sizeof(ItemPointerData));
136 
137  ItemPointerSet(result, blockNumber, offsetNumber);
138 
139  PG_RETURN_ITEMPOINTER(result);
140 }
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
uint32 BlockNumber
Definition: block.h:31
uint16 OffsetNumber
Definition: off.h:24
ItemPointerData * ItemPointer
Definition: itemptr.h:49
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:41
static char * buf
Definition: pg_test_fsync.c:67
void * palloc(Size size)
Definition: mcxt.c:848
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:105

◆ tidsend()

Datum tidsend ( PG_FUNCTION_ARGS  )

Definition at line 146 of file tid.c.

References buf, ItemPointerGetBlockNumberNoCheck, ItemPointerGetOffsetNumberNoCheck, PG_GETARG_ITEMPOINTER, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendint16(), and pq_sendint32().

147 {
148  ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0);
150 
151  pq_begintypsend(&buf);
155 }
#define ItemPointerGetOffsetNumberNoCheck(pointer)
Definition: itemptr.h:86
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
static void pq_sendint32(StringInfo buf, int32 i)
Definition: pqformat.h:148
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:330
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:67
static void pq_sendint16(StringInfo buf, int16 i)
Definition: pqformat.h:140
#define ItemPointerGetBlockNumberNoCheck(pointer)
Definition: itemptr.h:67

◆ tidsmaller()

Datum tidsmaller ( PG_FUNCTION_ARGS  )

Definition at line 234 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_ITEMPOINTER.

235 {
238 
239  PG_RETURN_ITEMPOINTER(ItemPointerCompare(arg1, arg2) <= 0 ? arg1 : arg2);
240 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:41

Variable Documentation

◆ Current_last_tid

ItemPointerData Current_last_tid = {{0, 0}, 0}
static

Definition at line 249 of file tid.c.

Referenced by currtid_byreloid().