PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

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

Definition at line 38 of file tid.c.

#define DELIM   ','

Definition at line 45 of file tid.c.

Referenced by tidin().

#define ItemPointerGetDatum (   X)    PointerGetDatum(X)

Definition at line 39 of file tid.c.

#define LDELIM   '('

Definition at line 43 of file tid.c.

Referenced by tidin().

#define NTIDARGS   2

Definition at line 46 of file tid.c.

Referenced by tidin().

#define PG_GETARG_ITEMPOINTER (   n)    DatumGetItemPointer(PG_GETARG_DATUM(n))
#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().

#define RDELIM   ')'

Definition at line 44 of file tid.c.

Referenced by tidin().

Function Documentation

Datum bttidcmp ( PG_FUNCTION_ARGS  )

Definition at line 218 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_INT32.

219 {
222 
223  PG_RETURN_INT32(ItemPointerCompare(arg1, arg2));
224 }
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
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, result, textToQualifiedNameList(), and UnregisterSnapshot().

365 {
366  text *relname = PG_GETARG_TEXT_PP(0);
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:858
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
Oid GetUserId(void)
Definition: miscinit.c:283
#define AccessShareLock
Definition: lockdefs.h:36
void heap_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid)
Definition: heapam.c:2167
return result
Definition: formatting.c:1618
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:2913
#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:48
static Datum currtid_for_view(Relation viewrel, ItemPointer tid)
Definition: tid.c:265
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:41
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3399
#define RelationGetRelationName(relation)
Definition: rel.h:437
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3182
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:900
AclResult
Definition: acl.h:170
#define ACL_SELECT
Definition: parsenodes.h:73
Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1312
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:375
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4422
void * palloc(Size size)
Definition: mcxt.c:849
#define RELKIND_VIEW
Definition: pg_class.h:164
Definition: c.h:439
#define RelationGetRelid(relation)
Definition: rel.h:417
#define ItemPointerCopy(fromPointer, toPointer)
Definition: itemptr.h:138
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, result, and UnregisterSnapshot().

Referenced by currtid_for_view().

326 {
327  Oid reloid = PG_GETARG_OID(0);
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:858
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
Oid GetUserId(void)
Definition: miscinit.c:283
#define AccessShareLock
Definition: lockdefs.h:36
void heap_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid)
Definition: heapam.c:2167
return result
Definition: formatting.c:1618
#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:48
static Datum currtid_for_view(Relation viewrel, ItemPointer tid)
Definition: tid.c:265
static ItemPointerData Current_last_tid
Definition: tid.c:251
#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:3399
#define RelationGetRelationName(relation)
Definition: rel.h:437
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:900
AclResult
Definition: acl.h:170
#define ACL_SELECT
Definition: parsenodes.h:73
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:375
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4422
void * palloc(Size size)
Definition: mcxt.c:849
#define RELKIND_VIEW
Definition: pg_class.h:164
#define RelationGetRelid(relation)
Definition: rel.h:417
#define ItemPointerCopy(fromPointer, toPointer)
Definition: itemptr.h:138
static Datum currtid_for_view ( Relation  viewrel,
ItemPointer  tid 
)
static

Definition at line 265 of file tid.c.

References AccessShareLock, RewriteRule::actions, tupleDesc::attrs, 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, Var::varattno, and Var::varno.

Referenced by currtid_byrelname(), and currtid_byreloid().

266 {
267  TupleDesc att = RelationGetDescr(viewrel);
268  RuleLock *rulelock;
269  RewriteRule *rewrite;
270  int i,
271  natts = att->natts,
272  tididx = -1;
273 
274  for (i = 0; i < natts; i++)
275  {
276  if (strcmp(NameStr(att->attrs[i]->attname), "ctid") == 0)
277  {
278  if (att->attrs[i]->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:560
int numLocks
Definition: prs2lock.h:42
#define RelationGetDescr(relation)
Definition: rel.h:429
#define PointerGetDatum(X)
Definition: postgres.h:562
Form_pg_attribute * attrs
Definition: tupdesc.h:74
#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:73
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
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:1367
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:499
#define SelfItemPointerAttributeNumber
Definition: sysattr.h:21
#define elog
Definition: elog.h:219
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
void setLastTid ( const ItemPointer  tid)

Definition at line 254 of file tid.c.

Referenced by ExecInsert().

255 {
256  Current_last_tid = *tid;
257 }
static ItemPointerData Current_last_tid
Definition: tid.c:251
Datum tideq ( PG_FUNCTION_ARGS  )

Definition at line 164 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

165 {
168 
169  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) == 0);
170 }
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
Datum tidge ( PG_FUNCTION_ARGS  )

Definition at line 209 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

210 {
213 
214  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) >= 0);
215 }
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
Datum tidgt ( PG_FUNCTION_ARGS  )

Definition at line 200 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

201 {
204 
205  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) > 0);
206 }
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
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 result.

Referenced by make_tuple_from_result_row().

54 {
55  char *str = PG_GETARG_CSTRING(0);
56  char *p,
57  *coord[NTIDARGS];
58  int i;
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
return result
Definition: formatting.c:1618
uint32 BlockNumber
Definition: block.h:31
uint16 OffsetNumber
Definition: off.h:24
ItemPointerData * ItemPointer
Definition: itemptr.h:48
#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:849
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:104
Datum tidlarger ( PG_FUNCTION_ARGS  )

Definition at line 227 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_ITEMPOINTER.

228 {
231 
232  PG_RETURN_ITEMPOINTER(ItemPointerCompare(arg1, arg2) >= 0 ? arg1 : arg2);
233 }
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
Datum tidle ( PG_FUNCTION_ARGS  )

Definition at line 191 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

192 {
195 
196  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) <= 0);
197 }
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
Datum tidlt ( PG_FUNCTION_ARGS  )

Definition at line 182 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

183 {
186 
187  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) < 0);
188 }
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
Datum tidne ( PG_FUNCTION_ARGS  )

Definition at line 173 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

174 {
177 
178  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) != 0);
179 }
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
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:85
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
char * pstrdup(const char *in)
Definition: mcxt.c:1077
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:66
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
#define ItemPointerGetBlockNumberNoCheck(pointer)
Definition: itemptr.h:66
Datum tidrecv ( PG_FUNCTION_ARGS  )

Definition at line 125 of file tid.c.

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

126 {
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:46
return result
Definition: formatting.c:1618
#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:48
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:41
static char * buf
Definition: pg_test_fsync.c:66
void * palloc(Size size)
Definition: mcxt.c:849
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:448
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:104
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(), and pq_sendint().

147 {
148  ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0);
150 
151  pq_begintypsend(&buf);
153  sizeof(BlockNumber));
155  sizeof(OffsetNumber));
157 }
#define ItemPointerGetOffsetNumberNoCheck(pointer)
Definition: itemptr.h:85
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:359
uint32 BlockNumber
Definition: block.h:31
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:329
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:379
uint16 OffsetNumber
Definition: off.h:24
static char * buf
Definition: pg_test_fsync.c:66
void pq_sendint(StringInfo buf, int i, int b)
Definition: pqformat.c:236
#define ItemPointerGetBlockNumberNoCheck(pointer)
Definition: itemptr.h:66
Datum tidsmaller ( PG_FUNCTION_ARGS  )

Definition at line 236 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_ITEMPOINTER.

237 {
240 
241  PG_RETURN_ITEMPOINTER(ItemPointerCompare(arg1, arg2) <= 0 ? arg1 : arg2);
242 }
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

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

Definition at line 251 of file tid.c.

Referenced by currtid_byreloid().