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 "libpq/pqformat.h"
#include "miscadmin.h"
#include "parser/parsetree.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/hashutils.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

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

◆ DELIM

#define DELIM   ','

Definition at line 46 of file tid.c.

Referenced by tidin().

◆ ItemPointerGetDatum

#define ItemPointerGetDatum (   X)    PointerGetDatum(X)

Definition at line 40 of file tid.c.

◆ LDELIM

#define LDELIM   '('

Definition at line 44 of file tid.c.

Referenced by tidin().

◆ NTIDARGS

#define NTIDARGS   2

Definition at line 47 of file tid.c.

Referenced by tidin().

◆ PG_GETARG_ITEMPOINTER

◆ PG_RETURN_ITEMPOINTER

#define PG_RETURN_ITEMPOINTER (   x)    return ItemPointerGetDatum(x)

Definition at line 42 of file tid.c.

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

◆ RDELIM

#define RDELIM   ')'

Definition at line 45 of file tid.c.

Referenced by tidin().

Function Documentation

◆ bttidcmp()

Datum bttidcmp ( PG_FUNCTION_ARGS  )

Definition at line 217 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_INT32.

218 {
221 
222  PG_RETURN_INT32(ItemPointerCompare(arg1, arg2));
223 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:41
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344

◆ currtid_byrelname()

Datum currtid_byrelname ( PG_FUNCTION_ARGS  )

Definition at line 395 of file tid.c.

References AccessShareLock, ACL_SELECT, aclcheck_error(), ACLCHECK_OK, currtid_for_view(), get_relkind_objtype(), GetLatestSnapshot(), GetUserId(), ItemPointerCopy, makeRangeVarFromNameList(), palloc(), pg_class_aclcheck(), PG_GETARG_ITEMPOINTER, PG_GETARG_TEXT_PP, PG_RETURN_ITEMPOINTER, RelationData::rd_rel, RegisterSnapshot(), RelationGetRelationName, RelationGetRelid, relname, table_beginscan(), table_close(), table_endscan(), table_openrv(), table_tuple_get_latest_tid(), textToQualifiedNameList(), and UnregisterSnapshot().

396 {
399  ItemPointer result;
400  RangeVar *relrv;
401  Relation rel;
402  AclResult aclresult;
403  Snapshot snapshot;
404  TableScanDesc scan;
405 
407  rel = table_openrv(relrv, AccessShareLock);
408 
409  aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
410  ACL_SELECT);
411  if (aclresult != ACLCHECK_OK)
412  aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind),
414 
415  if (rel->rd_rel->relkind == RELKIND_VIEW)
416  return currtid_for_view(rel, tid);
417 
418  result = (ItemPointer) palloc(sizeof(ItemPointerData));
419  ItemPointerCopy(tid, result);
420 
421  snapshot = RegisterSnapshot(GetLatestSnapshot());
422  scan = table_beginscan(rel, snapshot, 0, NULL);
423  table_tuple_get_latest_tid(scan, result);
424  table_endscan(scan);
425  UnregisterSnapshot(snapshot);
426 
428 
429  PG_RETURN_ITEMPOINTER(result);
430 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:865
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:41
Oid GetUserId(void)
Definition: miscinit.c:380
#define AccessShareLock
Definition: lockdefs.h:36
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3054
Form_pg_class rd_rel
Definition: rel.h:83
NameData relname
Definition: pg_class.h:35
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
ItemPointerData * ItemPointer
Definition: itemptr.h:49
static Datum currtid_for_view(Relation viewrel, ItemPointer tid)
Definition: tid.c:291
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3353
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:42
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
Definition: tableam.h:736
void table_tuple_get_latest_tid(TableScanDesc scan, ItemPointer tid)
Definition: tableam.c:228
#define RelationGetRelationName(relation)
Definition: rel.h:450
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3611
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:907
AclResult
Definition: acl.h:177
#define ACL_SELECT
Definition: parsenodes.h:75
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: table.c:68
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:381
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4631
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:831
void * palloc(Size size)
Definition: mcxt.c:924
ObjectType get_relkind_objtype(char relkind)
Definition: c.h:549
#define RelationGetRelid(relation)
Definition: rel.h:416
#define ItemPointerCopy(fromPointer, toPointer)
Definition: itemptr.h:161

◆ currtid_byreloid()

Datum currtid_byreloid ( PG_FUNCTION_ARGS  )

Definition at line 353 of file tid.c.

References AccessShareLock, ACL_SELECT, aclcheck_error(), ACLCHECK_OK, Current_last_tid, currtid_for_view(), get_relkind_objtype(), GetLatestSnapshot(), GetUserId(), ItemPointerCopy, palloc(), pg_class_aclcheck(), PG_GETARG_ITEMPOINTER, PG_GETARG_OID, PG_RETURN_ITEMPOINTER, RelationData::rd_rel, RegisterSnapshot(), RelationGetRelationName, RelationGetRelid, table_beginscan(), table_close(), table_endscan(), table_open(), table_tuple_get_latest_tid(), and UnregisterSnapshot().

Referenced by currtid_for_view().

354 {
355  Oid reloid = PG_GETARG_OID(0);
357  ItemPointer result;
358  Relation rel;
359  AclResult aclresult;
360  Snapshot snapshot;
361  TableScanDesc scan;
362 
363  result = (ItemPointer) palloc(sizeof(ItemPointerData));
364  if (!reloid)
365  {
366  *result = Current_last_tid;
367  PG_RETURN_ITEMPOINTER(result);
368  }
369 
370  rel = table_open(reloid, AccessShareLock);
371 
372  aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
373  ACL_SELECT);
374  if (aclresult != ACLCHECK_OK)
375  aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind),
377 
378  if (rel->rd_rel->relkind == RELKIND_VIEW)
379  return currtid_for_view(rel, tid);
380 
381  ItemPointerCopy(tid, result);
382 
383  snapshot = RegisterSnapshot(GetLatestSnapshot());
384  scan = table_beginscan(rel, snapshot, 0, NULL);
385  table_tuple_get_latest_tid(scan, result);
386  table_endscan(scan);
387  UnregisterSnapshot(snapshot);
388 
390 
391  PG_RETURN_ITEMPOINTER(result);
392 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:865
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:41
Oid GetUserId(void)
Definition: miscinit.c:380
#define AccessShareLock
Definition: lockdefs.h:36
Form_pg_class rd_rel
Definition: rel.h:83
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:291
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3353
static ItemPointerData Current_last_tid
Definition: tid.c:277
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:42
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
Definition: tableam.h:736
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
void table_tuple_get_latest_tid(TableScanDesc scan, ItemPointer tid)
Definition: tableam.c:228
#define RelationGetRelationName(relation)
Definition: rel.h:450
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:907
AclResult
Definition: acl.h:177
#define ACL_SELECT
Definition: parsenodes.h:75
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:381
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4631
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:831
void * palloc(Size size)
Definition: mcxt.c:924
ObjectType get_relkind_objtype(char relkind)
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define RelationGetRelid(relation)
Definition: rel.h:416
#define ItemPointerCopy(fromPointer, toPointer)
Definition: itemptr.h:161

◆ currtid_for_view()

static Datum currtid_for_view ( Relation  viewrel,
ItemPointer  tid 
)
static

Definition at line 291 of file tid.c.

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

Referenced by currtid_byrelname(), and currtid_byreloid().

292 {
293  TupleDesc att = RelationGetDescr(viewrel);
294  RuleLock *rulelock;
295  RewriteRule *rewrite;
296  int i,
297  natts = att->natts,
298  tididx = -1;
299 
300  for (i = 0; i < natts; i++)
301  {
302  Form_pg_attribute attr = TupleDescAttr(att, i);
303 
304  if (strcmp(NameStr(attr->attname), "ctid") == 0)
305  {
306  if (attr->atttypid != TIDOID)
307  elog(ERROR, "ctid isn't of type TID");
308  tididx = i;
309  break;
310  }
311  }
312  if (tididx < 0)
313  elog(ERROR, "currtid cannot handle views with no CTID");
314  rulelock = viewrel->rd_rules;
315  if (!rulelock)
316  elog(ERROR, "the view has no rules");
317  for (i = 0; i < rulelock->numLocks; i++)
318  {
319  rewrite = rulelock->rules[i];
320  if (rewrite->event == CMD_SELECT)
321  {
322  Query *query;
323  TargetEntry *tle;
324 
325  if (list_length(rewrite->actions) != 1)
326  elog(ERROR, "only one select rule is allowed in views");
327  query = (Query *) linitial(rewrite->actions);
328  tle = get_tle_by_resno(query->targetList, tididx + 1);
329  if (tle && tle->expr && IsA(tle->expr, Var))
330  {
331  Var *var = (Var *) tle->expr;
332  RangeTblEntry *rte;
333 
334  if (!IS_SPECIAL_VARNO(var->varno) &&
336  {
337  rte = rt_fetch(var->varno, query->rtable);
338  if (rte)
339  {
340  table_close(viewrel, AccessShareLock);
342  }
343  }
344  }
345  break;
346  }
347  }
348  elog(ERROR, "currtid cannot handle this view");
349  return (Datum) 0;
350 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:575
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
int numLocks
Definition: prs2lock.h:42
#define RelationGetDescr(relation)
Definition: rel.h:442
#define PointerGetDatum(X)
Definition: postgres.h:556
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define AccessShareLock
Definition: lockdefs.h:36
AttrNumber varattno
Definition: primnodes.h:172
Definition: primnodes.h:167
List * targetList
Definition: parsenodes.h:140
#define IS_SPECIAL_VARNO(varno)
Definition: primnodes.h:161
#define linitial(l)
Definition: pg_list.h:195
List * rtable
Definition: parsenodes.h:137
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
Datum currtid_byreloid(PG_FUNCTION_ARGS)
Definition: tid.c:353
CmdType event
Definition: prs2lock.h:27
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
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:170
uintptr_t Datum
Definition: postgres.h:367
Expr * expr
Definition: primnodes.h:1393
RuleLock * rd_rules
Definition: rel.h:87
static int list_length(const List *l)
Definition: pg_list.h:169
#define elog(elevel,...)
Definition: elog.h:226
int i
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
#define NameStr(name)
Definition: c.h:609
#define SelfItemPointerAttributeNumber
Definition: sysattr.h:21
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:618

◆ hashtid()

Datum hashtid ( PG_FUNCTION_ARGS  )

Definition at line 244 of file tid.c.

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

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

◆ hashtidextended()

Datum hashtidextended ( PG_FUNCTION_ARGS  )

Definition at line 259 of file tid.c.

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

260 {
262  uint64 seed = PG_GETARG_INT64(1);
263 
264  /* As above */
265  return hash_any_extended((unsigned char *) key,
266  sizeof(BlockIdData) + sizeof(OffsetNumber),
267  seed);
268 }
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:41
Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
Definition: hashfn.c:374
uint16 OffsetNumber
Definition: off.h:24
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ setLastTid()

void setLastTid ( const ItemPointer  tid)

Definition at line 280 of file tid.c.

Referenced by ExecInsert().

281 {
282  Current_last_tid = *tid;
283 }
static ItemPointerData Current_last_tid
Definition: tid.c:277

◆ tideq()

Datum tideq ( PG_FUNCTION_ARGS  )

Definition at line 163 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

164 {
167 
168  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) == 0);
169 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:41
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ tidge()

Datum tidge ( PG_FUNCTION_ARGS  )

Definition at line 208 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

209 {
212 
213  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) >= 0);
214 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:41
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ tidgt()

Datum tidgt ( PG_FUNCTION_ARGS  )

Definition at line 199 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

200 {
203 
204  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) > 0);
205 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:41
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ tidin()

Datum tidin ( PG_FUNCTION_ARGS  )

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

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

◆ tidlarger()

Datum tidlarger ( PG_FUNCTION_ARGS  )

Definition at line 226 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_ITEMPOINTER.

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

◆ tidle()

Datum tidle ( PG_FUNCTION_ARGS  )

Definition at line 190 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

191 {
194 
195  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) <= 0);
196 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:41
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ tidlt()

Datum tidlt ( PG_FUNCTION_ARGS  )

Definition at line 181 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

182 {
185 
186  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) < 0);
187 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:41
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ tidne()

Datum tidne ( PG_FUNCTION_ARGS  )

Definition at line 172 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

173 {
176 
177  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) != 0);
178 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:41
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ tidout()

Datum tidout ( PG_FUNCTION_ARGS  )

Definition at line 106 of file tid.c.

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

Referenced by pgrowlocks().

107 {
108  ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0);
109  BlockNumber blockNumber;
110  OffsetNumber offsetNumber;
111  char buf[32];
112 
113  blockNumber = ItemPointerGetBlockNumberNoCheck(itemPtr);
114  offsetNumber = ItemPointerGetOffsetNumberNoCheck(itemPtr);
115 
116  /* Perhaps someday we should output this as a record. */
117  snprintf(buf, sizeof(buf), "(%u,%u)", blockNumber, offsetNumber);
118 
120 }
#define ItemPointerGetOffsetNumberNoCheck(pointer)
Definition: itemptr.h:108
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:41
char * pstrdup(const char *in)
Definition: mcxt.c:1161
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:352
#define ItemPointerGetBlockNumberNoCheck(pointer)
Definition: itemptr.h:89
#define snprintf
Definition: port.h:192

◆ tidrecv()

Datum tidrecv ( PG_FUNCTION_ARGS  )

Definition at line 126 of file tid.c.

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

127 {
129  ItemPointer result;
130  BlockNumber blockNumber;
131  OffsetNumber offsetNumber;
132 
133  blockNumber = pq_getmsgint(buf, sizeof(blockNumber));
134  offsetNumber = pq_getmsgint(buf, sizeof(offsetNumber));
135 
136  result = (ItemPointer) palloc(sizeof(ItemPointerData));
137 
138  ItemPointerSet(result, blockNumber, offsetNumber);
139 
140  PG_RETURN_ITEMPOINTER(result);
141 }
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
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:42
static char * buf
Definition: pg_test_fsync.c:68
void * palloc(Size size)
Definition: mcxt.c:924
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 147 of file tid.c.

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

148 {
149  ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0);
151 
152  pq_begintypsend(&buf);
156 }
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:41
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:360
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 235 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_ITEMPOINTER.

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

Variable Documentation

◆ Current_last_tid

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

Definition at line 277 of file tid.c.

Referenced by currtid_byreloid().