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 223 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_INT32.

224 {
227 
228  PG_RETURN_INT32(ItemPointerCompare(arg1, arg2));
229 }
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:298
Datum currtid_byrelname ( PG_FUNCTION_ARGS  )

Definition at line 369 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_P, PG_RETURN_ITEMPOINTER, RelationData::rd_rel, RegisterSnapshot(), RelationGetRelationName, RelationGetRelid, RELKIND_VIEW, textToQualifiedNameList(), and UnregisterSnapshot().

370 {
371  text *relname = PG_GETARG_TEXT_P(0);
373  ItemPointer result;
374  RangeVar *relrv;
375  Relation rel;
376  AclResult aclresult;
377  Snapshot snapshot;
378 
380  rel = heap_openrv(relrv, AccessShareLock);
381 
382  aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
383  ACL_SELECT);
384  if (aclresult != ACLCHECK_OK)
385  aclcheck_error(aclresult, ACL_KIND_CLASS,
387 
388  if (rel->rd_rel->relkind == RELKIND_VIEW)
389  return currtid_for_view(rel, tid);
390 
391  result = (ItemPointer) palloc(sizeof(ItemPointerData));
392  ItemPointerCopy(tid, result);
393 
394  snapshot = RegisterSnapshot(GetLatestSnapshot());
395  heap_get_latest_tid(rel, snapshot, result);
396  UnregisterSnapshot(snapshot);
397 
399 
400  PG_RETURN_ITEMPOINTER(result);
401 }
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:858
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
Oid GetUserId(void)
Definition: miscinit.c:282
#define AccessShareLock
Definition: lockdefs.h:36
void heap_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid)
Definition: heapam.c:2154
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:2857
#define heap_close(r, l)
Definition: heapam.h:97
Form_pg_class rd_rel
Definition: rel.h:113
ItemPointerData * ItemPointer
Definition: itemptr.h:48
static Datum currtid_for_view(Relation viewrel, ItemPointer tid)
Definition: tid.c:270
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:41
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3378
#define RelationGetRelationName(relation)
Definition: rel.h:433
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3071
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:900
AclResult
Definition: acl.h:170
#define ACL_SELECT
Definition: parsenodes.h:66
Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1315
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:375
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4397
void * palloc(Size size)
Definition: mcxt.c:891
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:269
#define RELKIND_VIEW
Definition: pg_class.h:164
Definition: c.h:435
#define RelationGetRelid(relation)
Definition: rel.h:413
#define ItemPointerCopy(fromPointer, toPointer)
Definition: itemptr.h:120
Datum currtid_byreloid ( PG_FUNCTION_ARGS  )

Definition at line 330 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().

331 {
332  Oid reloid = PG_GETARG_OID(0);
334  ItemPointer result;
335  Relation rel;
336  AclResult aclresult;
337  Snapshot snapshot;
338 
339  result = (ItemPointer) palloc(sizeof(ItemPointerData));
340  if (!reloid)
341  {
342  *result = Current_last_tid;
343  PG_RETURN_ITEMPOINTER(result);
344  }
345 
346  rel = heap_open(reloid, AccessShareLock);
347 
348  aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
349  ACL_SELECT);
350  if (aclresult != ACLCHECK_OK)
351  aclcheck_error(aclresult, ACL_KIND_CLASS,
353 
354  if (rel->rd_rel->relkind == RELKIND_VIEW)
355  return currtid_for_view(rel, tid);
356 
357  ItemPointerCopy(tid, result);
358 
359  snapshot = RegisterSnapshot(GetLatestSnapshot());
360  heap_get_latest_tid(rel, snapshot, result);
361  UnregisterSnapshot(snapshot);
362 
364 
365  PG_RETURN_ITEMPOINTER(result);
366 }
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:858
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
Oid GetUserId(void)
Definition: miscinit.c:282
#define AccessShareLock
Definition: lockdefs.h:36
void heap_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid)
Definition: heapam.c:2154
#define heap_close(r, l)
Definition: heapam.h:97
Form_pg_class rd_rel
Definition: rel.h:113
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:270
static ItemPointerData Current_last_tid
Definition: tid.c:256
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:41
#define PG_GETARG_OID(n)
Definition: fmgr.h:231
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3378
#define RelationGetRelationName(relation)
Definition: rel.h:433
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:900
AclResult
Definition: acl.h:170
#define ACL_SELECT
Definition: parsenodes.h:66
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:375
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4397
void * palloc(Size size)
Definition: mcxt.c:891
#define RELKIND_VIEW
Definition: pg_class.h:164
#define RelationGetRelid(relation)
Definition: rel.h:413
#define ItemPointerCopy(fromPointer, toPointer)
Definition: itemptr.h:120
static Datum currtid_for_view ( Relation  viewrel,
ItemPointer  tid 
)
static

Definition at line 270 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().

271 {
272  TupleDesc att = RelationGetDescr(viewrel);
273  RuleLock *rulelock;
274  RewriteRule *rewrite;
275  int i,
276  natts = att->natts,
277  tididx = -1;
278 
279  for (i = 0; i < natts; i++)
280  {
281  if (strcmp(NameStr(att->attrs[i]->attname), "ctid") == 0)
282  {
283  if (att->attrs[i]->atttypid != TIDOID)
284  elog(ERROR, "ctid isn't of type TID");
285  tididx = i;
286  break;
287  }
288  }
289  if (tididx < 0)
290  elog(ERROR, "currtid cannot handle views with no CTID");
291  rulelock = viewrel->rd_rules;
292  if (!rulelock)
293  elog(ERROR, "the view has no rules");
294  for (i = 0; i < rulelock->numLocks; i++)
295  {
296  rewrite = rulelock->rules[i];
297  if (rewrite->event == CMD_SELECT)
298  {
299  Query *query;
300  TargetEntry *tle;
301 
302  if (list_length(rewrite->actions) != 1)
303  elog(ERROR, "only one select rule is allowed in views");
304  query = (Query *) linitial(rewrite->actions);
305  tle = get_tle_by_resno(query->targetList, tididx + 1);
306  if (tle && tle->expr && IsA(tle->expr, Var))
307  {
308  Var *var = (Var *) tle->expr;
309  RangeTblEntry *rte;
310 
311  if (!IS_SPECIAL_VARNO(var->varno) &&
313  {
314  rte = rt_fetch(var->varno, query->rtable);
315  if (rte)
316  {
317  heap_close(viewrel, AccessShareLock);
319  }
320  }
321  }
322  break;
323  }
324  }
325  elog(ERROR, "currtid cannot handle this view");
326  return (Datum) 0;
327 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:559
int numLocks
Definition: prs2lock.h:42
#define RelationGetDescr(relation)
Definition: rel.h:425
#define PointerGetDatum(X)
Definition: postgres.h:564
Form_pg_attribute * attrs
Definition: tupdesc.h:74
#define AccessShareLock
Definition: lockdefs.h:36
AttrNumber varattno
Definition: primnodes.h:146
#define heap_close(r, l)
Definition: heapam.h:97
Definition: primnodes.h:141
int natts
Definition: tupdesc.h:73
List * targetList
Definition: parsenodes.h:131
#define TIDOID
Definition: pg_type.h:332
#define IS_SPECIAL_VARNO(varno)
Definition: primnodes.h:135
#define linitial(l)
Definition: pg_list.h:110
List * rtable
Definition: parsenodes.h:128
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
Datum currtid_byreloid(PG_FUNCTION_ARGS)
Definition: tid.c:330
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:144
uintptr_t Datum
Definition: postgres.h:374
Expr * expr
Definition: primnodes.h:1330
RuleLock * rd_rules
Definition: rel.h:117
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:495
#define SelfItemPointerAttributeNumber
Definition: sysattr.h:21
#define elog
Definition: elog.h:219
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
void setLastTid ( const ItemPointer  tid)

Definition at line 259 of file tid.c.

Referenced by ExecInsert().

260 {
261  Current_last_tid = *tid;
262 }
static ItemPointerData Current_last_tid
Definition: tid.c:256
Datum tideq ( PG_FUNCTION_ARGS  )

Definition at line 169 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

170 {
173 
174  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) == 0);
175 }
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:303
Datum tidge ( PG_FUNCTION_ARGS  )

Definition at line 214 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

215 {
218 
219  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) >= 0);
220 }
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:303
Datum tidgt ( PG_FUNCTION_ARGS  )

Definition at line 205 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

206 {
209 
210  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) > 0);
211 }
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:303
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, and RDELIM.

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: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:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:233
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:86
Datum tidlarger ( PG_FUNCTION_ARGS  )

Definition at line 232 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_ITEMPOINTER.

233 {
236 
237  PG_RETURN_ITEMPOINTER(ItemPointerCompare(arg1, arg2) >= 0 ? arg1 : arg2);
238 }
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 196 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

197 {
200 
201  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) <= 0);
202 }
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:303
Datum tidlt ( PG_FUNCTION_ARGS  )

Definition at line 187 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

188 {
191 
192  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) < 0);
193 }
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:303
Datum tidne ( PG_FUNCTION_ARGS  )

Definition at line 178 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

179 {
182 
183  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) != 0);
184 }
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:303
Datum tidout ( PG_FUNCTION_ARGS  )

Definition at line 105 of file tid.c.

References BlockIdGetBlockNumber, buf, ItemPointerData::ip_blkid, ItemPointerData::ip_posid, 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 = BlockIdGetBlockNumber(&(itemPtr->ip_blkid));
113  offsetNumber = itemPtr->ip_posid;
114 
115  /* Perhaps someday we should output this as a record. */
116  snprintf(buf, sizeof(buf), "(%u,%u)", blockNumber, offsetNumber);
117 
119 }
#define BlockIdGetBlockNumber(blockId)
Definition: block.h:115
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:40
char * pstrdup(const char *in)
Definition: mcxt.c:1165
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
BlockIdData ip_blkid
Definition: itemptr.h:38
static char * buf
Definition: pg_test_fsync.c:65
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:306
OffsetNumber ip_posid
Definition: itemptr.h:39
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:46
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:232
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:65
void * palloc(Size size)
Definition: mcxt.c:891
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:448
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:86
Datum tidsend ( PG_FUNCTION_ARGS  )

Definition at line 146 of file tid.c.

References BlockIdGetBlockNumber, buf, ItemPointerData::ip_blkid, ItemPointerData::ip_posid, PG_GETARG_ITEMPOINTER, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint().

147 {
148  ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0);
149  BlockId blockId;
150  BlockNumber blockNumber;
151  OffsetNumber offsetNumber;
153 
154  blockId = &(itemPtr->ip_blkid);
155  blockNumber = BlockIdGetBlockNumber(blockId);
156  offsetNumber = itemPtr->ip_posid;
157 
158  pq_begintypsend(&buf);
159  pq_sendint(&buf, blockNumber, sizeof(blockNumber));
160  pq_sendint(&buf, offsetNumber, sizeof(offsetNumber));
162 }
#define BlockIdGetBlockNumber(blockId)
Definition: block.h:115
#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:313
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:379
uint16 OffsetNumber
Definition: off.h:24
BlockIdData ip_blkid
Definition: itemptr.h:38
static char * buf
Definition: pg_test_fsync.c:65
void pq_sendint(StringInfo buf, int i, int b)
Definition: pqformat.c:236
OffsetNumber ip_posid
Definition: itemptr.h:39
Datum tidsmaller ( PG_FUNCTION_ARGS  )

Definition at line 241 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_ITEMPOINTER.

242 {
245 
246  PG_RETURN_ITEMPOINTER(ItemPointerCompare(arg1, arg2) <= 0 ? arg1 : arg2);
247 }
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 256 of file tid.c.

Referenced by currtid_byreloid().