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 "access/tableam.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "parser/parsetree.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/snapmgr.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

static ItemPointer currtid_for_view (Relation viewrel, ItemPointer tid)
 
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)
 
Datum hashtid (PG_FUNCTION_ARGS)
 
Datum hashtidextended (PG_FUNCTION_ARGS)
 
static ItemPointer currtid_internal (Relation rel, ItemPointer tid)
 
Datum currtid_byrelname (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ DatumGetItemPointer

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

Definition at line 40 of file tid.c.

◆ DELIM

#define DELIM   ','

Definition at line 47 of file tid.c.

Referenced by tidin().

◆ ItemPointerGetDatum

#define ItemPointerGetDatum (   X)    PointerGetDatum(X)

Definition at line 41 of file tid.c.

◆ LDELIM

#define LDELIM   '('

Definition at line 45 of file tid.c.

Referenced by tidin().

◆ NTIDARGS

#define NTIDARGS   2

Definition at line 48 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 43 of file tid.c.

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

◆ RDELIM

#define RDELIM   ')'

Definition at line 46 of file tid.c.

Referenced by tidin().

Function Documentation

◆ bttidcmp()

Datum bttidcmp ( PG_FUNCTION_ARGS  )

Definition at line 220 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_INT32.

221 {
224 
225  PG_RETURN_INT32(ItemPointerCompare(arg1, arg2));
226 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354

◆ currtid_byrelname()

Datum currtid_byrelname ( PG_FUNCTION_ARGS  )

Definition at line 398 of file tid.c.

References AccessShareLock, currtid_internal(), makeRangeVarFromNameList(), PG_GETARG_ITEMPOINTER, PG_GETARG_TEXT_PP, PG_RETURN_ITEMPOINTER, relname, table_close(), table_openrv(), and textToQualifiedNameList().

399 {
402  ItemPointer result;
403  RangeVar *relrv;
404  Relation rel;
405 
407  rel = table_openrv(relrv, AccessShareLock);
408 
409  /* grab the latest tuple version associated to this CTID */
410  result = currtid_internal(rel, tid);
411 
413 
414  PG_RETURN_ITEMPOINTER(result);
415 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define AccessShareLock
Definition: lockdefs.h:36
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3061
static ItemPointer currtid_internal(Relation rel, ItemPointer tid)
Definition: tid.c:286
NameData relname
Definition: pg_class.h:38
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:43
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3658
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: table.c:102
Definition: c.h:617

◆ currtid_for_view()

static ItemPointer currtid_for_view ( Relation  viewrel,
ItemPointer  tid 
)
static

Definition at line 326 of file tid.c.

References AccessShareLock, RewriteRule::actions, CMD_SELECT, currtid_internal(), elog, ERROR, RewriteRule::event, TargetEntry::expr, get_tle_by_resno(), i, IS_SPECIAL_VARNO, IsA, linitial, list_length(), NameStr, TupleDescData::natts, RuleLock::numLocks, RelationData::rd_rules, RelationGetDescr, rt_fetch, Query::rtable, RuleLock::rules, SelfItemPointerAttributeNumber, table_close(), table_open(), Query::targetList, TupleDescAttr, Var::varattno, and Var::varno.

Referenced by currtid_internal().

327 {
328  TupleDesc att = RelationGetDescr(viewrel);
329  RuleLock *rulelock;
330  RewriteRule *rewrite;
331  int i,
332  natts = att->natts,
333  tididx = -1;
334 
335  for (i = 0; i < natts; i++)
336  {
337  Form_pg_attribute attr = TupleDescAttr(att, i);
338 
339  if (strcmp(NameStr(attr->attname), "ctid") == 0)
340  {
341  if (attr->atttypid != TIDOID)
342  elog(ERROR, "ctid isn't of type TID");
343  tididx = i;
344  break;
345  }
346  }
347  if (tididx < 0)
348  elog(ERROR, "currtid cannot handle views with no CTID");
349  rulelock = viewrel->rd_rules;
350  if (!rulelock)
351  elog(ERROR, "the view has no rules");
352  for (i = 0; i < rulelock->numLocks; i++)
353  {
354  rewrite = rulelock->rules[i];
355  if (rewrite->event == CMD_SELECT)
356  {
357  Query *query;
358  TargetEntry *tle;
359 
360  if (list_length(rewrite->actions) != 1)
361  elog(ERROR, "only one select rule is allowed in views");
362  query = (Query *) linitial(rewrite->actions);
363  tle = get_tle_by_resno(query->targetList, tididx + 1);
364  if (tle && tle->expr && IsA(tle->expr, Var))
365  {
366  Var *var = (Var *) tle->expr;
367  RangeTblEntry *rte;
368 
369  if (!IS_SPECIAL_VARNO(var->varno) &&
371  {
372  rte = rt_fetch(var->varno, query->rtable);
373  if (rte)
374  {
375  ItemPointer result;
376  Relation rel;
377 
378  rel = table_open(rte->relid, AccessShareLock);
379  result = currtid_internal(rel, tid);
381  return result;
382  }
383  }
384  }
385  break;
386  }
387  }
388  elog(ERROR, "currtid cannot handle this view");
389  return NULL;
390 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:578
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
int numLocks
Definition: prs2lock.h:42
#define RelationGetDescr(relation)
Definition: rel.h:483
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define AccessShareLock
Definition: lockdefs.h:36
AttrNumber varattno
Definition: primnodes.h:186
static ItemPointer currtid_internal(Relation rel, ItemPointer tid)
Definition: tid.c:286
Definition: primnodes.h:181
List * targetList
Definition: parsenodes.h:140
#define IS_SPECIAL_VARNO(varno)
Definition: primnodes.h:175
#define linitial(l)
Definition: pg_list.h:174
List * rtable
Definition: parsenodes.h:137
#define ERROR
Definition: elog.h:43
CmdType event
Definition: prs2lock.h:27
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
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:184
Expr * expr
Definition: primnodes.h:1422
RuleLock * rd_rules
Definition: rel.h:114
static int list_length(const List *l)
Definition: pg_list.h:149
#define elog(elevel,...)
Definition: elog.h:228
int i
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
#define NameStr(name)
Definition: c.h:677
#define SelfItemPointerAttributeNumber
Definition: sysattr.h:21
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ currtid_internal()

static ItemPointer currtid_internal ( Relation  rel,
ItemPointer  tid 
)
static

Definition at line 286 of file tid.c.

References ACL_SELECT, aclcheck_error(), ACLCHECK_OK, currtid_for_view(), elog, ERROR, get_namespace_name(), get_relkind_objtype(), GetLatestSnapshot(), GetUserId(), ItemPointerCopy, palloc(), pg_class_aclcheck(), RelationData::rd_rel, RegisterSnapshot(), RelationGetNamespace, RelationGetRelationName, RelationGetRelid, table_beginscan_tid(), table_endscan(), table_tuple_get_latest_tid(), and UnregisterSnapshot().

Referenced by currtid_byrelname(), and currtid_for_view().

287 {
288  ItemPointer result;
289  AclResult aclresult;
290  Snapshot snapshot;
291  TableScanDesc scan;
292 
293  result = (ItemPointer) palloc(sizeof(ItemPointerData));
294 
295  aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
296  ACL_SELECT);
297  if (aclresult != ACLCHECK_OK)
298  aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind),
300 
301  if (rel->rd_rel->relkind == RELKIND_VIEW)
302  return currtid_for_view(rel, tid);
303 
304  if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
305  elog(ERROR, "cannot look at latest visible tid for relation \"%s.%s\"",
308 
309  ItemPointerCopy(tid, result);
310 
311  snapshot = RegisterSnapshot(GetLatestSnapshot());
312  scan = table_beginscan_tid(rel, snapshot);
313  table_tuple_get_latest_tid(scan, result);
314  table_endscan(scan);
315  UnregisterSnapshot(snapshot);
316 
317  return result;
318 }
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:810
Oid GetUserId(void)
Definition: miscinit.c:476
Form_pg_class rd_rel
Definition: rel.h:110
ItemPointerData * ItemPointer
Definition: itemptr.h:49
static ItemPointer currtid_for_view(Relation viewrel, ItemPointer tid)
Definition: tid.c:326
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3294
#define ERROR
Definition: elog.h:43
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3196
void table_tuple_get_latest_tid(TableScanDesc scan, ItemPointer tid)
Definition: tableam.c:246
#define RelationGetRelationName(relation)
Definition: rel.h:491
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:852
AclResult
Definition: acl.h:177
#define ACL_SELECT
Definition: parsenodes.h:75
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:325
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4563
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:863
static TableScanDesc table_beginscan_tid(Relation rel, Snapshot snapshot)
Definition: tableam.h:839
void * palloc(Size size)
Definition: mcxt.c:950
#define elog(elevel,...)
Definition: elog.h:228
ObjectType get_relkind_objtype(char relkind)
#define RelationGetRelid(relation)
Definition: rel.h:457
#define ItemPointerCopy(fromPointer, toPointer)
Definition: itemptr.h:161
#define RelationGetNamespace(relation)
Definition: rel.h:498

◆ hashtid()

Datum hashtid ( PG_FUNCTION_ARGS  )

Definition at line 247 of file tid.c.

References hash_any(), sort-test::key, and PG_GETARG_ITEMPOINTER.

248 {
250 
251  /*
252  * While you'll probably have a lot of trouble with a compiler that
253  * insists on appending pad space to struct ItemPointerData, we can at
254  * least make this code work, by not using sizeof(ItemPointerData).
255  * Instead rely on knowing the sizes of the component fields.
256  */
257  return hash_any((unsigned char *) key,
258  sizeof(BlockIdData) + sizeof(OffsetNumber));
259 }
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
uint16 OffsetNumber
Definition: off.h:24
static Datum hash_any(const unsigned char *k, int keylen)
Definition: hashfn.h:31

◆ hashtidextended()

Datum hashtidextended ( PG_FUNCTION_ARGS  )

Definition at line 262 of file tid.c.

References hash_any_extended(), sort-test::key, PG_GETARG_INT64, and PG_GETARG_ITEMPOINTER.

263 {
265  uint64 seed = PG_GETARG_INT64(1);
266 
267  /* As above */
268  return hash_any_extended((unsigned char *) key,
269  sizeof(BlockIdData) + sizeof(OffsetNumber),
270  seed);
271 }
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
Definition: hashfn.h:37
uint16 OffsetNumber
Definition: off.h:24
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283

◆ tideq()

Datum tideq ( PG_FUNCTION_ARGS  )

Definition at line 166 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

167 {
170 
171  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) == 0);
172 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ tidge()

Datum tidge ( PG_FUNCTION_ARGS  )

Definition at line 211 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

212 {
215 
216  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) >= 0);
217 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ tidgt()

Datum tidgt ( PG_FUNCTION_ARGS  )

Definition at line 202 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

203 {
206 
207  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) > 0);
208 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ tidin()

Datum tidin ( PG_FUNCTION_ARGS  )

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

58 {
59  char *str = PG_GETARG_CSTRING(0);
60  char *p,
61  *coord[NTIDARGS];
62  int i;
63  ItemPointer result;
64  BlockNumber blockNumber;
65  OffsetNumber offsetNumber;
66  char *badp;
67  int hold_offset;
68 
69  for (i = 0, p = str; *p && i < NTIDARGS && *p != RDELIM; p++)
70  if (*p == DELIM || (*p == LDELIM && !i))
71  coord[i++] = p + 1;
72 
73  if (i < NTIDARGS)
74  ereport(ERROR,
75  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
76  errmsg("invalid input syntax for type %s: \"%s\"",
77  "tid", str)));
78 
79  errno = 0;
80  blockNumber = strtoul(coord[0], &badp, 10);
81  if (errno || *badp != DELIM)
82  ereport(ERROR,
83  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
84  errmsg("invalid input syntax for type %s: \"%s\"",
85  "tid", str)));
86 
87  hold_offset = strtol(coord[1], &badp, 10);
88  if (errno || *badp != RDELIM ||
89  hold_offset > USHRT_MAX || hold_offset < 0)
90  ereport(ERROR,
91  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
92  errmsg("invalid input syntax for type %s: \"%s\"",
93  "tid", str)));
94 
95  offsetNumber = hold_offset;
96 
97  result = (ItemPointer) palloc(sizeof(ItemPointerData));
98 
99  ItemPointerSet(result, blockNumber, offsetNumber);
100 
101  PG_RETURN_ITEMPOINTER(result);
102 }
#define LDELIM
Definition: tid.c:45
#define RDELIM
Definition: tid.c:46
int errcode(int sqlerrcode)
Definition: elog.c:691
#define NTIDARGS
Definition: tid.c:48
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:43
#define DELIM
Definition: tid.c:47
#define ereport(elevel,...)
Definition: elog.h:155
void * palloc(Size size)
Definition: mcxt.c:950
int errmsg(const char *fmt,...)
Definition: elog.c:902
int i
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127

◆ tidlarger()

Datum tidlarger ( PG_FUNCTION_ARGS  )

Definition at line 229 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_ITEMPOINTER.

230 {
233 
234  PG_RETURN_ITEMPOINTER(ItemPointerCompare(arg1, arg2) >= 0 ? arg1 : arg2);
235 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:43

◆ tidle()

Datum tidle ( PG_FUNCTION_ARGS  )

Definition at line 193 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

194 {
197 
198  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) <= 0);
199 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ tidlt()

Datum tidlt ( PG_FUNCTION_ARGS  )

Definition at line 184 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

185 {
188 
189  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) < 0);
190 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ tidne()

Datum tidne ( PG_FUNCTION_ARGS  )

Definition at line 175 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

176 {
179 
180  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) != 0);
181 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ tidout()

Datum tidout ( PG_FUNCTION_ARGS  )

Definition at line 109 of file tid.c.

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

Referenced by pgrowlocks().

110 {
111  ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0);
112  BlockNumber blockNumber;
113  OffsetNumber offsetNumber;
114  char buf[32];
115 
116  blockNumber = ItemPointerGetBlockNumberNoCheck(itemPtr);
117  offsetNumber = ItemPointerGetOffsetNumberNoCheck(itemPtr);
118 
119  /* Perhaps someday we should output this as a record. */
120  snprintf(buf, sizeof(buf), "(%u,%u)", blockNumber, offsetNumber);
121 
123 }
#define ItemPointerGetOffsetNumberNoCheck(pointer)
Definition: itemptr.h:108
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
char * pstrdup(const char *in)
Definition: mcxt.c:1187
uint32 BlockNumber
Definition: block.h:31
uint16 OffsetNumber
Definition: off.h:24
static char * buf
Definition: pg_test_fsync.c:68
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
#define ItemPointerGetBlockNumberNoCheck(pointer)
Definition: itemptr.h:89
#define snprintf
Definition: port.h:215

◆ tidrecv()

Datum tidrecv ( PG_FUNCTION_ARGS  )

Definition at line 129 of file tid.c.

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

130 {
132  ItemPointer result;
133  BlockNumber blockNumber;
134  OffsetNumber offsetNumber;
135 
136  blockNumber = pq_getmsgint(buf, sizeof(blockNumber));
137  offsetNumber = pq_getmsgint(buf, sizeof(offsetNumber));
138 
139  result = (ItemPointer) palloc(sizeof(ItemPointerData));
140 
141  ItemPointerSet(result, blockNumber, offsetNumber);
142 
143  PG_RETURN_ITEMPOINTER(result);
144 }
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
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:43
static char * buf
Definition: pg_test_fsync.c:68
void * palloc(Size size)
Definition: mcxt.c:950
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127

◆ tidsend()

Datum tidsend ( PG_FUNCTION_ARGS  )

Definition at line 150 of file tid.c.

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

151 {
152  ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0);
154 
155  pq_begintypsend(&buf);
159 }
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:137
#define ItemPointerGetOffsetNumberNoCheck(pointer)
Definition: itemptr.h:108
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
static char * buf
Definition: pg_test_fsync.c:68
#define ItemPointerGetBlockNumberNoCheck(pointer)
Definition: itemptr.h:89

◆ tidsmaller()

Datum tidsmaller ( PG_FUNCTION_ARGS  )

Definition at line 238 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_ITEMPOINTER.

239 {
242 
243  PG_RETURN_ITEMPOINTER(ItemPointerCompare(arg1, arg2) <= 0 ? arg1 : arg2);
244 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:43